UTILITIES

Utility classes

Overview:

  • Logfile

  • OutputFolderHandler

  • PopulationFactory

  • ToyPopulationFactory

  • HouseholdLinker

  • thread_pool

  • RandomManager

  • RandomGenerator

  • InverseCDF

  • DistanceMetrics

UTILITIES

class LogFile

Class to handle logging Singleton LogFile structure Usage: // Configure std::filesystem::path logfilepath(“log.log”) // path to log file LogFile::Instance()->configure(0, logfilepath); // Configure logger // ALTERNATIVELY LOG.configure(0, logfilepath);.

// Write to Logs LOG << LOG_LEVEL_ERROR << “Encountered Error” << std::endl; LOG << LOG_LEVEL_NORMAL << “Started Simulation” << std::endl;

// Cleanup LogFile::Close();

Public Functions

void configure(unsigned int level, std::filesystem::path path)

Close the currently open file, and delete the single LogFile instance.

void setLevel(unsigned int level)

Set the current logging level

const std::string prepare(unsigned int level)

Prepare the logger to recieve a log line by configuring the log level

bool isFileSet() const
Returns:

true if Set() has been called.

void lock()

Lock the logfile for multithreaded logging

void unlock()

Unlock the logfile for multithreaded logging

void enable_cout()

Configure the logger to output to both std::cout and the output file

void disable_cout()

Configure the logger to output to output file only and not std::cout

Public Static Functions

static LogFile *Instance()

Singleton Instance Return the Singleton LogFile Instance.

Returns:

LogFile*

static unsigned int Level()

Current Logging Level Return the current logging level.

Returns:

unsigned int

static void Close()

Close the currently open file, and delete the single LogFile instance.

class OutputFolderHandler

Output Folder Handling Class Class which handles opening a folder Creates folder if it doesn’t exist Can clear the folder after opening Public method which allows opening a file within this folder for writing.

Public Functions

OutputFolderHandler(const std::filesystem::path &directory_path, bool cleanOutputDirectory = true)

Construct a new Output File Handler object.

Parameters:
  • directory_path – Path to output directory

  • cleanOutputDirectory – Flag whether to clear contents of output directory

ofstreamPtr OpenOutputFile(const std::string &rFileName, std::ios_base::openmode mode = std::ios::out | std::ios::trunc) const

Make outputfile and return ofstream for the file Construct a new file inside of the OutputFolderHandler’s directory.

Parameters:
  • rFileName – New filename

  • mode – std::ios_base::openmode Mode with which to open file

Returns:

ofstreamPtr

class PopulationFactory

Public Functions

PopulationPtr makePopulation()
PopulationPtr makePopulation(size_t n_cells, size_t n_microcells, size_t n_people)

Create a Basic Population.

Create a Population with n_cells, n_microcells :class:Microcell in each cell, and n_people :class:People in each microcell.

Parameters:
  • n_cells

  • n_microcells

  • n_people

Returns:

PopulationPtr

void addCell(PopulationPtr population)
void addMicrocell(Cell *cell)
void addPerson(Cell *cell, size_t microcell_index)
void addCells(PopulationPtr population, size_t n)
void addMicrocells(Cell *cell, size_t n)
void addPeople(Cell *cell, size_t microcell_index, size_t n)
void addHousehold(Microcell *microcell)
void addHouseholds(Microcell *microcell, size_t n)
void addPlace(PopulationPtr population)
void addPlaces(PopulationPtr population, size_t n)
class ToyPopulationFactory

Public Functions

PopulationPtr makePopulation(size_t populationSize, size_t nCells, size_t nMicrocells, size_t nHouseholds, size_t nPlaces, std::optional<size_t> seed)
class HouseholdLinker

Public Functions

void linkHouseholds(PopulationPtr population, size_t n_households, int percInHousehold, std::optional<size_t> seed)

Link households Create n_households per microcell. Person has percInHousehold to be in a household. People who should be in a household are randomly assigned to a household in their microcell.

Parameters:
  • population

  • n_households

  • percInHousehold

Warning

doxygenclass: Cannot find class “epiabm::thread_pool” in doxygen xml output for project “cEpiabm” from directory: build/xml

class RandomManager

Public Functions

RandomManager(unsigned int seed)
~RandomManager()
RandomGenerator &g()
class RandomGenerator

Public Functions

inline RandomGenerator(unsigned int seed, size_t threadNum)
inline RandomGenerator(unsigned int seed, size_t threadNum, std::thread::id threadId)
~RandomGenerator() = default
inline std::mt19937_64 &generator()
template<typename T>
inline T randi(T max)

Generate Random Integer Random integer between 0 and max inclusive.

Template Parameters:

T – Integer Type

Parameters:

max

Returns:

T Generated Random Number

template<typename T>
inline T randi(T min, T max)

Generate Random Integer Type Random integer between min and max inclusive.

Template Parameters:

T – Integer Type

Parameters:
  • min

  • max

Returns:

T Generated Random Number

template<typename T>
inline T randf()

Generate Random Floating Point Type.

Template Parameters:

T – Float Type

Returns:

T Generated Float Type

class InverseCDF

Public Functions

InverseCDF()
InverseCDF(double mean)
void setNegLog(double startValue)
void assignExponent()
void assignExponent(double value)
unsigned short choose(double timestepsPerDay, RandomGenerator &generator)
std::array<double, InverseCDF::RES + 1> &getValues()
double &operator[](size_t i)
double mean()

Public Static Attributes

static const size_t RES = 20
class DistanceMetrics

Public Functions

DistanceMetrics()
~DistanceMetrics() = default

Public Static Functions

static double Dist(location loc1, location loc2)
static double DistEuclid(location loc1, location loc2)
static double DistCovidsim(location loc1, location loc2)