FFSM++  1.1.0
French Forest Sector Model ++
MainProgram Class Reference

Main program scheleton. It control the flow of the program. More...

#include <MainProgram.h>

Inheritance diagram for MainProgram:
Collaboration diagram for MainProgram:

Public Member Functions

 MainProgram (ThreadManager *MTHREAD)
 
 ~MainProgram ()
 
void run ()
 Run the program. More...
 
- 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. More...
 
void msgOut (const int &msgCode_h, const int &msg_h, const bool &refreshGUI_h=true) const
 Overloaded function to print the output log. More...
 
void msgOut (const int &msgCode_h, const double &msg_h, const bool &refreshGUI_h=true) const
 Overloaded function to print the output log. More...
 
int s2i (const string &string_h) const
 string to integer conversion More...
 
double s2d (const string &string_h) const
 string to double conversion More...
 
double s2d (const string &string_h, const bool &replaceComma) const
 string to double conversion More...
 
bool s2b (const string &string_h) const
 string to bool conversion More...
 
string i2s (const int &int_h) const
 integer to string conversion More...
 
string d2s (const double &double_h) const
 double to string conversion More...
 
string b2s (const bool &bool_h) const
 bool to string conversion More...
 
vector< int > s2i (const vector< string > &string_h) const
 string to integer conversion (vector) More...
 
vector< double > s2d (const vector< string > &string_h, const bool &replaceComma=false) const
 string to double conversion (vector) More...
 
vector< bool > s2b (const vector< string > &string_h) const
 string to bool conversion (vector) More...
 
vector< string > i2s (const vector< int > &int_h) const
 integer to string conversion (vector) More...
 
vector< string > d2s (const vector< double > &double_h) const
 double to string conversion (vector) More...
 
vector< string > b2s (const vector< bool > &bool_h) const
 bool to string conversion (vector) More...
 
int getType (const string &type_h) const
 Return a type according to enum TYPE_* from a string (eg: "string" -> TYPE_STRING (2)) More...
 
void refreshGUI () const
 Ping to periodically return the control to the GUI. More...
 
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) More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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) More...
 
template<typename V >
void debugMap (const map< iisskey, V > &mymap)
 Debug a map. More...
 
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) More...
 
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) More...
 
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) More...
 
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) More...
 
template<typename K >
double getAvg (const vector< K > &v)
 Returns the average of the elements in the vector. More...
 
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). More...
 
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. More...
 
template<typename T >
std::string toString (const T &x) const
 

Additional Inherited Members

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

Detailed Description

Main program scheleton. It control the flow of the program.

There is only one istance of this class. It is responsable to load the setting files, call the Init class, "speack" with the Scheduler and finally end the program.

Author
Antonello Lobianco

Definition at line 47 of file MainProgram.h.

Constructor & Destructor Documentation

MainProgram ( ThreadManager MTHREAD)

Definition at line 33 of file MainProgram.cpp.

34 {
35  //input_filename = input_filename_h;
36  MTHREAD = MTHREAD_h;
37  // Creating objects for the program flow:
38  // the regional data object..
39  ModelData *MD = new ModelData(MTHREAD);
40  MTHREAD->setMDPointer(MD);
41  MTHREAD->MD->setBaseDiretory(MTHREAD->getBaseDirectory());
42  MTHREAD->MD->loadInput(); // Unzip the ooffice input file and load it into memory
43 
44 }
ModelData * MD
the model data object
Definition: ThreadManager.h:72
Regional data, including macros and settings.
Definition: ModelData.h:80
void loadInput()
Unzip the OpenOffice input file (NEW 2008.05.13)
Definition: ModelData.cpp:1527
string getBaseDirectory()
Definition: ThreadManager.h:98
void setMDPointer(ModelData *MD_h)
the regional data object..
void setBaseDiretory(string baseDirectory_h)
Definition: ModelData.h:183

Here is the call graph for this function:

Definition at line 47 of file MainProgram.cpp.

47  {
48 
49 }

Member Function Documentation

void run ( )

Run the program.

This is the main call of the program.
It firstly create the objects (and keep track of them trough pointers) of the main functional objects of the program.
Then it call the INIT object to do its jobs and when it ends, it gives control to SCD (Scheduler) for the year loops.
Finally it clean-up and returns.

Definition at line 58 of file MainProgram.cpp.

Referenced by ThreadManager::run(), and ThreadManager::runFromConsole().

58  {
59 
60  setlocale(LC_ALL, "C"); // force to use the dot as digital separator also if we are running under the GUI
61 
62  // GIS information and methods..
63  Gis *GIS = new Gis(MTHREAD);
64  MTHREAD->setGISPointer(GIS);
65  // a test object for various 0-effects tests (sandbox)..
66  Sandbox* TEST = new Sandbox(MTHREAD);
67  MTHREAD->setTestPointer(TEST);
68  // the Init object, it schedule the pre-simulation phase..
69  Init *INIT = new Init(MTHREAD);
70  MTHREAD->setINITPointer(INIT);
71  // the scheduler object. It manage the simulation loops..
72  Scheduler *SCD = new Scheduler(MTHREAD);
73  MTHREAD->setSCDPointer(SCD);
74  // the core of the model
75  ModelCore *CORE = new ModelCore(MTHREAD);
76  MTHREAD->setCOREPointer(CORE);
77  // the core of the model (spatial version)
79  MTHREAD->setSCOREPointer(SCORE);
80  // the market optimisation algorithm
81  Opt *OPT = new Opt(MTHREAD);
82  MTHREAD->setOPTPointer(OPT);
83  // manage the printing of data needed for scenario-analisys. The "message output" (needed to see "what is it happening?" are instead simply printed with msgOut()..
84  Output *DO = new Output(MTHREAD);
85  MTHREAD->setDOPointer(DO);
86  // the carbon balance
87  Carbon *CBAL = new Carbon(MTHREAD);
88  MTHREAD->setCBALPointer(CBAL);
89 
90  // Creating an istance of INIT and delegating to it the Initialization phase..
91  MTHREAD->INIT->setInitLevel(1); // Initial environment setting and agent rising
92  refreshGUI();
93  MTHREAD->INIT->setInitLevel(3); // assigning resources to agents and evenutal env reallocation
94  refreshGUI();
95  MTHREAD->INIT->setInitLevel(5); // starting simulations. Once INIT has ended it is the turn of SCD (Scheduler) to manage the simulation...
96  refreshGUI();
97  MTHREAD->INIT->setInitLevel(6); // ending simulations
98  refreshGUI();
99 
100  // Deleting the pointers...
101  // 20070102: if I delete the pointers I can not access the legend after simulation has ended
102  // 20070109: pointers (e.g. INIT) are deleted in ThreadManager when a new simulation start
103 }
void setSCDPointer(Scheduler *SCD_h)
the scheduler object. It manage the simulation loops..
Manage the yearly loops.
Definition: Scheduler.h:42
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
Init * INIT
the Init object (pre-simulation scheduler)
Definition: ThreadManager.h:74
Init the environment, the objects and the agents of the model
Definition: Init.h:45
void setSCOREPointer(ModelCoreSpatial *SCORE_h)
Perform the algorithms of the model.
Output methods
Definition: Output.h:48
void setCOREPointer(ModelCore *CORE_h)
Perform the algorithms of the model.
void setTestPointer(Sandbox *TEST_h)
the sandbox object for within-development quick tests
void setINITPointer(Init *INIT_h)
the Init object, it schedule the pre-simulation phase..
Class to manage the spatial dimension.
Definition: Gis.h:67
void setCBALPointer(Carbon *CBAL_h)
Module that account for the Carbon Balance.
Class responsable to keep the logbook of the Carbon Balance.
Definition: Carbon.h:50
void setGISPointer(Gis *GIS_h)
GIS information and methods..
Definition: Opt.h:52
void setInitLevel(int level_h)
Wrapper to the correct setInitLevelX()
Definition: Init.cpp:48
void refreshGUI() const
Ping to periodically return the control to the GUI.
Definition: BaseClass.cpp:142
The core of the model (spatial version).
void setOPTPointer(Ipopt::SmartPtr< Ipopt::TNLP > OPT_h)
Perform the market optimisation.
void setDOPointer(Output *DO_h)
manage the printing of data needed for scenario-analisys. The "message output" (needed to see "what i...

Here is the call graph for this function:

Here is the caller graph for this function:


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