FFSM++ 1.1.0
French Forest Sector Model ++
Loading...
Searching...
No Matches
Init Class Reference

Init the environment, the objects and the agents of the model More...

#include <Init.h>

Inheritance diagram for Init:
Collaboration diagram for Init:

Public Member Functions

 Init (ThreadManager *MTHREAD_h)
 
 ~Init ()
 
void setInitLevel (int level_h)
 Wrapper to the correct setInitLevelX()
 
void setInitLevel0 ()
 Unused, reserver for future use.
 
void setInitLevel1 ()
 Setting up the space, the model objects and the agents (definitions only)
 
void setInitLevel2 ()
 Unused, reserver for future use.
 
void setInitLevel3 ()
 Linking object to agents and assigning space proprieties to objects and agents.
 
void setInitLevel4 ()
 Unused, reserver for future use.
 
void setInitLevel5 ()
 Simulation start.
 
void setInitLevel6 ()
 End of simulation (e.g. print summary statistics)
 
int getInitState ()
 
- Public Member Functions inherited from BaseClass
 BaseClass ()
 
 ~BaseClass ()
 
void msgOut (const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
 Overloaded function to print the output log.
 
void msgOut (const int &msgCode_h, const int &msg_h, const bool &refreshGUI_h=true) const
 Overloaded function to print the output log.
 
void msgOut (const int &msgCode_h, const double &msg_h, const bool &refreshGUI_h=true) const
 Overloaded function to print the output log.
 
int s2i (const string &string_h) const
 string to integer conversion
 
double s2d (const string &string_h) const
 string to double conversion
 
double s2d (const string &string_h, const bool &replaceComma) const
 string to double conversion
 
bool s2b (const string &string_h) const
 string to bool conversion
 
string i2s (const int &int_h) const
 integer to string conversion
 
string d2s (const double &double_h) const
 double to string conversion
 
string b2s (const bool &bool_h) const
 bool to string conversion
 
vector< int > s2i (const vector< string > &string_h) const
 string to integer conversion (vector)
 
vector< double > s2d (const vector< string > &string_h, const bool &replaceComma=false) const
 string to double conversion (vector)
 
vector< bool > s2b (const vector< string > &string_h) const
 string to bool conversion (vector)
 
vector< string > i2s (const vector< int > &int_h) const
 integer to string conversion (vector)
 
vector< string > d2s (const vector< double > &double_h) const
 double to string conversion (vector)
 
vector< string > b2s (const vector< bool > &bool_h) const
 bool to string conversion (vector)
 
int getType (const string &type_h) const
 Return a type according to enum TYPE_* from a string (eg: "string" -> TYPE_STRING (2))
 
void refreshGUI () const
 Ping to periodically return the control to the GUI.
 
template<typename T >
string toString (const T &x) const
 
template<typename T >
stringTo (const std::string &s) const
 
int vSum (const vector< int > &vector_h) const
 
double vSum (const vector< double > &vector_h) const
 
int vSum (const vector< vector< int > > &vector_h) const
 
double vSum (const vector< vector< double > > &vector_h) const
 
void tokenize (const string &str, vector< string > &tokens, const string &delimiter=" ") const
 Tokenize a string using a delimiter (default is space)
 
void untokenize (string &str, vector< string > &tokens, const string &delimiter=" ") const
 
template<typename K , typename V >
findMap (const map< K, V > &mymap, const K &key, const int &error_level=MSG_CRITICAL_ERROR, const V &notFoundValue=numeric_limits< V >::min()) const
 Lookup a map for a value. Return the value starting from the key.
 
template<typename K , typename V >
void changeMapValue (map< K, V > &mymap, const K &key, const V &value, const int &error_level=MSG_CRITICAL_ERROR)
 Change the value stored in a map given the key and the new value.
 
template<typename K , typename V >
void incrMapValue (map< K, V > &mymap, const K &key, const V &value, const int &error_level=MSG_CRITICAL_ERROR)
 Increments a value stored in a map of the specified value, given the key.
 
template<typename K , typename V >
void incrOrAddMapValue (map< K, V > &mymap, const K &key, const V &value)
 Increments a value stored in a map of the specified value, given the key.
 
template<typename K , typename V >
void resetMapValues (map< K, V > &mymap, const V &value)
 Reset all values stored in a map to the specified one.
 
template<typename K , typename V >
map< K, V > vectorToMap (const vector< K > &keys, const V &value=0.0)
 Returns a map built using the given vector and the given (scalar) value as keys/values pairs.
 
template<typename T >
vector< T > positionsToContent (const vector< T > &vector_h, const vector< int > &positions)
 Return a vector of content from a vector and a vector of positions (int)
 
template<typename V >
void debugMap (const map< iisskey, V > &mymap)
 Debug a map.
 
template<typename K , typename V >
void debugMap (const map< K, V > &mymap, const K &key)
 
template<typename K >
int getMaxPos (const vector< K > &v)
 Returns the position of the maximum element in the vector (the last one in case of multiple equivalent maxima)
 
template<typename K >
int getMinPos (const vector< K > &v)
 Returns the position of the minimum element in the vector (the first one in case of multiple equivalent minima)
 
template<typename K >
getMax (const vector< K > &v)
 Returns the value of the maximum element in the vector (the last one in case of multiple equivalent maxima)
 
template<typename K >
getMin (const vector< K > &v)
 Returns the value of the minimum element in the vector (the first one in case of multiple equivalent minima)
 
template<typename K >
double getAvg (const vector< K > &v)
 Returns the average of the elements in the vector.
 
template<typename K >
double getSd (const vector< K > &v, bool sample=true)
 
template<typename K >
int getPos (const K &element, const vector< K > &v, const int &msgCode_h=MSG_CRITICAL_ERROR)
 
template<typename K >
bool inVector (const K &element, const vector< K > &v)
 
double normSample (const double &avg, const double &stdev, const double &minval=NULL, const double &maxval=NULL) const
 Sample from a normal distribution with bounds. Slower (double time, but still you see the diff only after milion of loops).
 
template<typename K >
normSample (normal_distribution< K > &d, std::mt19937 &gen, const K &minval=NULL, const K &maxval=NULL) const
 Sample from a normal distribution with bounds. Faster (half time) as the normal_distribution is made only once.
 
template<typename T >
std::string toString (const T &x) const
 

Private Attributes

int InitState
 One of the 7 possible init states (0..6)
 
struct tm * current
 
time_t now
 

Additional Inherited Members

- Protected Attributes inherited from BaseClass
ThreadManagerMTHREAD
 Pointer to the Thread manager.
 

Detailed Description

Init the environment, the objects and the agents of the model

The Init class is responsable to ask to the various objects to Init themself, in a 7-steps procedures.
The basic idea is to first init the environment: options, settings and space.
Then objects and agents are mould up, objects are assigned to agents and finally agents and objects are collocated in the space.

Author
Antonello Lobianco

Definition at line 45 of file Init.h.

Constructor & Destructor Documentation

◆ Init()

Init ( ThreadManager MTHREAD_h)

Definition at line 38 of file Init.cpp.

38 {
39 MTHREAD=MTHREAD_h;
40 InitState=0;
41}
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition BaseClass.h:467
int InitState
One of the 7 possible init states (0..6)
Definition Init.h:70

◆ ~Init()

~Init ( )

Definition at line 43 of file Init.cpp.

44{
45}

Member Function Documentation

◆ getInitState()

int getInitState ( )
inline

Definition at line 67 of file Init.h.

67{return InitState;};

◆ setInitLevel()

void setInitLevel ( int  level_h)

Wrapper to the correct setInitLevelX()

Definition at line 48 of file Init.cpp.

48 {
49
50 switch (level_h){
51 case 0:
52 this->setInitLevel0();
53 break;
54 case 1:
55 this->setInitLevel1();
56 break;
57 case 2:
58 this->setInitLevel2();
59 break;
60 case 3:
61 this->setInitLevel3();
62 break;
63 case 4:
64 this->setInitLevel4();
65 break;
66 case 5:
67 this->setInitLevel5();
68 break;
69 case 6:
70 this->setInitLevel6();
71 break;
72 default:
73 msgOut(MSG_ERROR,"unexpected Init level");
74 }
75}
@ MSG_ERROR
Print an ERROR message, but don't stop the model.
Definition BaseClass.h:61
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition BaseClass.cpp:50
void setInitLevel6()
End of simulation (e.g. print summary statistics)
Definition Init.cpp:181
void setInitLevel5()
Simulation start.
Definition Init.cpp:175
void setInitLevel0()
Unused, reserver for future use.
Definition Init.cpp:78
void setInitLevel3()
Linking object to agents and assigning space proprieties to objects and agents.
Definition Init.cpp:156
void setInitLevel1()
Setting up the space, the model objects and the agents (definitions only)
Definition Init.cpp:94
void setInitLevel4()
Unused, reserver for future use.
Definition Init.cpp:167
void setInitLevel2()
Unused, reserver for future use.
Definition Init.cpp:148

Referenced by MainProgram::run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setInitLevel0()

void setInitLevel0 ( )

Unused, reserver for future use.

Definition at line 78 of file Init.cpp.

78 {
79 //unused now
80 InitState=0;
81}

Referenced by setInitLevel().

Here is the caller graph for this function:

◆ setInitLevel1()

void setInitLevel1 ( )

Setting up the space, the model objects and the agents (definitions only)

Setting up the space
Level 1 :

Definition at line 94 of file Init.cpp.

94 {
95 //Loading data from file.
96 InitState=1;
97 msgOut(MSG_DEBUG,"Entering Init state "+i2s(InitState));
98 time(&now);
99 current = localtime(&now);
100 string timemessage = "Local time is "+i2s(current->tm_hour)+":"+i2s(current->tm_min)+":"+ i2s(current->tm_sec);
101 msgOut(MSG_INFO, timemessage);
102 string scenarioName = MTHREAD->getScenarioName();
103 MTHREAD->MD->setScenarioData(); // set the characteristics (including overriding tables of the scneario)
106 if(MTHREAD->MD->getBoolSetting("newRandomSeed")){
107 // See here for how to use the new C++11 random functions:
108 // http://www.johndcook.com/cpp_TR1_random.html
109 // usage example:
110 // std::normal_distribution<double> d(100000,3);
111 // double x = d(*MTHREAD->gen);
112 srand(time(NULL)+getpid());
113 //std::random_device randev;
114 //MTHREAD->gen = new std::mt19937(randev());
115 MTHREAD->gen = new std::mt19937(time(0)+getpid());
116
117 //TO.DO change scenarioname to scenarioname_random number
118 uniform_int_distribution<> ud(1, 1000000);
119 int randomscenario = ud(*MTHREAD->gen);
120
121 MTHREAD->setScenarioName(scenarioName+"_"+i2s(randomscenario));
122
123 } else {
124 MTHREAD->gen = new std::mt19937(NULL);
125 }
126 MTHREAD->SCD->setYear(MTHREAD->MD->getIntSetting("initialYear"));
128
136 MTHREAD->MD->applyOverrides(); // Cancel all reg1 level data and trasform them in reg2 level if not already existing. Acts on forDataMap, prodDataMap and reclRules vectors
142 MTHREAD->GIS->setSpace();
144 MTHREAD->TEST->fullTest(); // normally empty function
145}
@ MSG_DEBUG
Print a debug message, normally filtered out.
Definition BaseClass.h:58
@ MSG_INFO
Print an INFO message.
Definition BaseClass.h:59
string i2s(const int &int_h) const
integer to string conversion
void applyForestReclassification()
Apply the forest reclassification with the rules defined in reclRules sheet.
Definition Gis.cpp:439
void setSpace()
Set the initial space environment, including loading data from files.
Definition Gis.cpp:57
time_t now
Definition Init.h:72
struct tm * current
Definition Init.h:71
void cacheSettings()
Called after input reading, it fix frequently used data;.
void setDefaultForData()
void setScenarioData()
Set the infos about this scenario (long description and overriding tables)
bool getBoolSetting(const string &name_h, int position=0, int reg=WORLD) const
void createRegions()
void setDefaultSettings()
void setScenarioProdData()
void applyDebugMode()
Works only a specified subset of regions and products.
void setDefaultPathogenRules()
void setScenarioPathogenRules()
void setDefaultProdData()
void setScenarioProductResourceMatrixLink()
void setReclassificationRules()
void setScenarioSettings()
void setForestTypes()
int getIntSetting(const string &name_h, int position=0, int reg=WORLD) const
void setDefaultProductResourceMatrixLink()
void applyOverrides()
Cancel all reg1 level data and trasform them in reg2 level if not already existing.
void setScenarioForData()
void fullTest()
Tests that require a full sandbox object including MTHREAD. Normally empty.
Definition Sandbox.cpp:600
void setYear(const int &year_h)
Definition Scheduler.h:50
void setScenarioName(const string &scenarioName_h)
Scheduler * SCD
the scheduler object (simulation-loops scheduler)
Sandbox * TEST
Various debugging code for development.
string getScenarioName()
Gis * GIS
GIS information and methods.
ModelData * MD
the model data object
std::mt19937 * gen
used in the sampling from normal distribution

Referenced by setInitLevel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setInitLevel2()

void setInitLevel2 ( )

Unused, reserver for future use.

Definition at line 148 of file Init.cpp.

148 {
149 InitState=2;
150}

Referenced by setInitLevel().

Here is the caller graph for this function:

◆ setInitLevel3()

void setInitLevel3 ( )

Linking object to agents and assigning space proprieties to objects and agents.

Init 3 run the simulation/assign the values for the pre-optimisation year(s)

Definition at line 156 of file Init.cpp.

156 {
157 InitState=3;
158 MTHREAD->DO->initOutput(); // initialize the output files
159 if(MTHREAD->MD->getBoolSetting("usePixelData")){
161 } else {
163 }
164}
void runInitPeriod()
Definition ModelCore.cpp:50
void initOutput()
Definition Output.cpp:48
ModelCoreSpatial * SCORE
Core of the model (spatial version)
Output * DO
data output
ModelCore * CORE
Core of the model.

Referenced by setInitLevel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setInitLevel4()

void setInitLevel4 ( )

Unused, reserver for future use.

Definition at line 167 of file Init.cpp.

167 {
168 InitState=4;
169}

Referenced by setInitLevel().

Here is the caller graph for this function:

◆ setInitLevel5()

void setInitLevel5 ( )

Simulation start.

Init level 5 pass the controll to the Scheduler object for the running of the simulations.

Definition at line 175 of file Init.cpp.

175 {
176 InitState=5;
177 MTHREAD->SCD->run(); // !!!! go "bello" !!!! start the simulation !!!!!
178}
void run()
Definition Scheduler.cpp:41

Referenced by setInitLevel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setInitLevel6()

void setInitLevel6 ( )

End of simulation (e.g. print summary statistics)

Definition at line 181 of file Init.cpp.

181 {
182 InitState=6;
184 msgOut(MSG_INFO, "Model has ended scheduled simulation in a regular way.");
185 time(&now);
186 current = localtime(&now);
187 string timemessage = "Local time is "+i2s(current->tm_hour)+":"+i2s(current->tm_min)+":"+ i2s(current->tm_sec);
188 msgOut(MSG_INFO, timemessage);
189}
void printFinalOutput()
Definition Output.cpp:462

Referenced by setInitLevel().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ current

struct tm* current
private

Definition at line 71 of file Init.h.

Referenced by setInitLevel1(), and setInitLevel6().

◆ InitState

int InitState
private

One of the 7 possible init states (0..6)

Definition at line 70 of file Init.h.

Referenced by getInitState(), Init(), setInitLevel0(), setInitLevel1(), setInitLevel2(), setInitLevel3(), setInitLevel4(), setInitLevel5(), and setInitLevel6().

◆ now

time_t now
private

Definition at line 72 of file Init.h.

Referenced by setInitLevel1(), and setInitLevel6().


The documentation for this class was generated from the following files: