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

Thread manager. Responsable to manage the main thread and "speak" with the GUI. More...

#include <ThreadManager.h>

Inheritance diagram for ThreadManager:
Collaboration diagram for ThreadManager:

Public Slots

void checkQuery (int px_ID, int currentLayerIndex, bool newRequest=true)
 Switch and control the access to pxQueryID and layerQueryPos members. More...
 
void computeQuery (int px_ID, int currentLayerIndex)
 Compute the pixel query and return it to the GUI (with a signal) More...
 
void retrieveScenarioNameFromGUI (const QString &scenarioName_h)
 

Signals

void upgradeLogArea (const QString &logMessage)
 
void upgradeMainSBLabelToGui (const QString &logMessage)
 
void upgradeYearSBLabelToGui (const QString &logMessage)
 
void addLayerToGui (QString layerName, QString layerLabel)
 
void updatePixelToGui (QString layerName_h, int x_h, int y_h, QColor color)
 
void updateImageToGui (QString layerName_h, QImage image_h)
 
void setOutputDirNameToGui (string outputDirname_h)
 
void setGUIUnsavedStatus (bool status_h)
 
void setGUIMapDimension (int x_h, int y_h)
 
void treeViewerItemChangeValueToGui (string itemID, string newValue)
 
void treeViewerItemRemoveToGui (string itemID)
 
void treeViewerAddItemToGui (string text, string itemID, string parentID)
 
void fitInWindowToGui ()
 
void queryRequestOnPx (int px_ID, int currentLayerIndex)
 
void publishQueryResults (const QString &results)
 
void activateTab (int pos_h)
 
void resetGUIForNewSimulation ()
 
void sendScenarioOptionsToGUI (const QVector< QString > &scenarios_h)
 

Public Member Functions

 ThreadManager ()
 
void setMessage (const QString &message)
 
void stop ()
 
void deleteDeadOldPointers ()
 Useful for several model running without leaving the GUI. More...
 
void pauseOrResume ()
 
void pause ()
 
void resume ()
 
void refreshGUI ()
 
void msgOut (const int msgCode_h, const string message_h)
 
void addLayer (string layerName_h, string layerLabel_h)
 
void updatePixel (string layerName_h, int x_h, int y_h, QColor color)
 
void updateImage (string layerName_h, const QImage &image_h)
 
void upgradeMainSBLabel (const string message_h)
 
void upgradeYearSBLabel (int year)
 
string getBaseDirectory ()
 
string getInputFileName ()
 
string getScenarioName ()
 
void setScenarioName (const string &scenarioName_h)
 
void setOutputDirName (string outputDirname_h)
 
void setMDPointer (ModelData *MD_h)
 the regional data object.. More...
 
void setGISPointer (Gis *GIS_h)
 GIS information and methods.. More...
 
void setINITPointer (Init *INIT_h)
 the Init object, it schedule the pre-simulation phase.. More...
 
void setTestPointer (Sandbox *TEST_h)
 the sandbox object for within-development quick tests More...
 
void setSCDPointer (Scheduler *SCD_h)
 the scheduler object. It manage the simulation loops.. More...
 
void setDOPointer (Output *DO_h)
 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().. More...
 
void setCOREPointer (ModelCore *CORE_h)
 Perform the algorithms of the model. More...
 
void setSCOREPointer (ModelCoreSpatial *SCORE_h)
 Perform the algorithms of the model. More...
 
void setOPTPointer (Ipopt::SmartPtr< Ipopt::TNLP > OPT_h)
 Perform the market optimisation. More...
 
void setCBALPointer (Carbon *CBAL_h)
 Module that account for the Carbon Balance. More...
 
void setInputFileName (QString inputFileName_h)
 
void treeViewerChangeGeneralPropertyValue (string propertyName, string newValue)
 
void fitInWindow ()
 
void runFromConsole (QString inputFileName_h, QString scenarioName_h)
 Re-draw the map making it to fit (with the right proportions) to the widget. More...
 
bool usingGUI ()
 
- 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
 

Public Attributes

ModelDataMD
 the model data object More...
 
GisGIS
 GIS information and methods. More...
 
InitINIT
 the Init object (pre-simulation scheduler) More...
 
SchedulerSCD
 the scheduler object (simulation-loops scheduler) More...
 
OutputDO
 data output More...
 
ModelCoreCORE
 Core of the model. More...
 
ModelCoreSpatialSCORE
 Core of the model (spatial version) More...
 
CarbonCBAL
 Module for the Carbon Balance. More...
 
SandboxTEST
 Various debugging code for development. More...
 
Ipopt::SmartPtr< Ipopt::TNLP > OPT
 Market optimisation. More...
 
std::mt19937 * gen
 used in the sampling from normal distribution More...
 

Protected Member Functions

void run ()
 

Private Attributes

QString messageStr
 
volatile bool stopped
 
volatile bool running
 
QString inputFileName
 
QString baseDirectory
 
QString scenarioName
 
volatile int pxQueryID
 
volatile int layerQueryPos
 
QMutex mutex
 
bool GUI
 

Additional Inherited Members

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

Detailed Description

Thread manager. Responsable to manage the main thread and "speak" with the GUI.

ThreadManager is responsable for the actions on the main thread (run/pause/resume/stop) and to speack with the GUI using the signal/slot tecniques.

Author
Antonello Lobianco

Definition at line 65 of file ThreadManager.h.

Constructor & Destructor Documentation

Definition at line 35 of file ThreadManager.cpp.

35  {
36  running=false;
37  stopped=false;
38  layerQueryPos = -1;
39 
40  // initializing pointers...
41  MD = NULL;
42  GIS = NULL;
43  INIT = NULL;
44  SCD = NULL;
45  DO = NULL;
46  CORE = NULL;
47  SCORE = NULL;
48  TEST = NULL;
49  CBAL = NULL;
50  //randev = NULL;
51  gen = NULL;
52 
53  GUI = false;
54 
55  scenarioName="";
56  inputFileName="";
57  baseDirectory="";
58 
59 }
volatile bool stopped
QString scenarioName
volatile bool running
volatile int layerQueryPos
ModelData * MD
the model data object
Definition: ThreadManager.h:72
Init * INIT
the Init object (pre-simulation scheduler)
Definition: ThreadManager.h:74
Scheduler * SCD
the scheduler object (simulation-loops scheduler)
Definition: ThreadManager.h:75
Gis * GIS
GIS information and methods.
Definition: ThreadManager.h:73
ModelCore * CORE
Core of the model.
Definition: ThreadManager.h:77
ModelCoreSpatial * SCORE
Core of the model (spatial version)
Definition: ThreadManager.h:78
Output * DO
data output
Definition: ThreadManager.h:76
Carbon * CBAL
Module for the Carbon Balance.
Definition: ThreadManager.h:79
std::mt19937 * gen
used in the sampling from normal distribution
Definition: ThreadManager.h:83
QString baseDirectory
QString inputFileName
Sandbox * TEST
Various debugging code for development.
Definition: ThreadManager.h:80

Member Function Documentation

void activateTab ( int  pos_h)
signal
void addLayer ( string  layerName_h,
string  layerLabel_h 
)

Definition at line 259 of file ThreadManager.cpp.

259  {
260  QString layerName = layerName_h.c_str();
261  QString layerLabel = layerLabel_h.c_str();
262  emit addLayerToGui(layerName, layerLabel);
263 }
void addLayerToGui(QString layerName, QString layerLabel)
void addLayerToGui ( QString  layerName,
QString  layerLabel 
)
signal
void checkQuery ( int  px_ID,
int  currentLayerIndex,
bool  newRequest = true 
)
slot

Switch and control the access to pxQueryID and layerQueryPos members.

checkQuery() is a function that can be called my the GUI trough a signal or from the running thread under refreshGUI(), and it is protected with a mutex.
It's role is to control the status of pxQueryID and layerQueryPos member variables.
If the call come from the GUI, it is a new request and we set them to the new values, otherwise we gonna see if they are just beed changed and if so (layerQueryPos>=0) we call computeQuery().

Definition at line 293 of file ThreadManager.cpp.

293  {
294  QMutexLocker locker(&mutex);
295  if(newRequest){
296  pxQueryID = px_ID;
297  layerQueryPos = currentLayerIndex;
298  if(stopped){computeQuery(pxQueryID, layerQueryPos);layerQueryPos = -1;} // model is stopped, no way the model thread will do the query work
299  else{emit publishQueryResults("<i>..wait.. processing query..</i>");} // model is running.. it will be the model thread to execute the query
300  return;
301  } else {
302  if(layerQueryPos<0){
303  return;
304  } else {
306  layerQueryPos = -1;
307  return;
308  }
309  }
310 }
volatile bool stopped
void publishQueryResults(const QString &results)
volatile int layerQueryPos
void computeQuery(int px_ID, int currentLayerIndex)
Compute the pixel query and return it to the GUI (with a signal)
volatile int pxQueryID
void computeQuery ( int  px_ID,
int  currentLayerIndex 
)
slot

Compute the pixel query and return it to the GUI (with a signal)

Definition at line 313 of file ThreadManager.cpp.

313  {
314 
315  // IMPORTANT: this function is called at refreshGUI() times, so if there are output messages, call them with the option to NOT refresh the gui, otherwise we go to an infinite loop...
316 
317  vector<Layers*> layers;
318  try {
319  layers = GIS->getLayerPointers();
320  }catch (...) {
321  emit activateTab(2); // tell the gui to activate the 3rd page, those with the pixel info
322  emit publishQueryResults("GIS pointer is dead.. maybe simulation has ended???");
323  return;
324  }
325  QString result= "";
326  int realID = GIS->sub2realID(px_ID);
327  if (realID<0) {
328  emit publishQueryResults("Query result: Spatial data is not yet ready in the model. Please click again later.");
329  return; // on early stage we may have errors, and here we prevent this error to have further consequences.
330  }
331  Pixel* px;
332  try {
333  px = GIS->getPixel(realID);
334  }catch (...) {
335  emit activateTab(2); // tell the gui to activate the 3rd page, those with the pixel info
336  emit publishQueryResults("Query result: Spatial data is not yet ready in the model. Please click again later.");
337  return;
338  }
339  result += "Pixel: ";
340  result += i2s(realID).c_str();
341  result += " (";
342  result += i2s(px->getX()).c_str();
343  result += ",";
344  result += i2s(px->getY()).c_str();
345  result += ")";
346  result +="<p><table>";
347  uint countVisibleLayers = 0;
348  for (uint i=0;i<layers.size();i++){
349  if(!layers[i]->getDisplay()){
350  continue;
351  }
352  QString boldStart="";
353  QString boldEnd = "";
354  if (countVisibleLayers == currentLayerIndex){
355  boldStart = "<b>";
356  boldEnd = "</b>";
357  }
358  result += "<tr>";
359  string layerName = layers[i]->getName();
360  double value = px->getDoubleValue(layerName);
361  string category = layers[i]->getCategory(value);
362  //QColor color = layers[i]->getColor(value);
363  result += "<td>";
364  result += boldStart;
365  result += layerName.c_str();
366  result += boldEnd;
367  result += "</td><td>";
368  result += boldStart;
369  result += category.c_str();
370  result += boldEnd;
371  result += "</td>";
372  result += "</tr>";
373  if(layers[i]->getDisplay()){ // if not really needed, but ok if we decide to change and get displayed also hidden layers
374  countVisibleLayers++;
375  }
376  }
377  result += "</table>";
378  emit activateTab(2); // tell the gui to activate the 3rd page, those with the pixel info
379  emit publishQueryResults(result);
380 }
string i2s(const int &int_h) const
integer to string conversion
Definition: BaseClass.cpp:219
void publishQueryResults(const QString &results)
int getX() const
Definition: Pixel.h:68
Gis * GIS
GIS information and methods.
Definition: ThreadManager.h:73
double getDoubleValue(const string &layerName_h, const bool &returnZeroForNoValue=false) const
Return the value for a specific layer.
Definition: Pixel.cpp:158
Pixel-level class.
Definition: Pixel.h:47
vector< Layers * > getLayerPointers()
Return a vector of pointers of existing layers.
Definition: Gis.cpp:881
Pixel * getPixel(int x_h, int y_h)
Definition: Gis.h:134
int sub2realID(int id_h)
Transform the ID of a pixel in subregion coordinates to the real (and model used) coordinates...
Definition: Gis.cpp:982
void activateTab(int pos_h)
int getY() const
Definition: Pixel.h:69

Here is the call graph for this function:

void deleteDeadOldPointers ( )

Useful for several model running without leaving the GUI.

Delete the pointers (e.g. GIS) eventually remained from a previous run.
This function is called at the START of a new simulation, and it will check if model pointers (e.g. GIS) exist , and if so it will delete them.
This is useful when we keep the MainWindow open but we run the model for a second time.
Why we don't delete them at the end of a simulation, instead of deleting them on a new run? That's because we want let the user to interface with the model even when this is ended, w.g. for query the map.

Definition at line 165 of file ThreadManager.cpp.

165  {
166  if (DO) {delete DO; DO=0;}
167  if (INIT) {delete INIT; INIT=0;}
168  if (SCD) {delete SCD; SCD=0;}
169  if (GIS) {delete GIS; GIS=0;}
170  if (MD) {delete MD; MD=0;}
171  if (CORE){delete CORE; CORE=0;}
172  if (SCORE){delete SCORE; SCORE=0;}
173  if (CBAL) {delete CBAL; CBAL=0;}
174  //if (OPT) {delete OPT; OPT=0;} // not needed, it's a "smart point"
175  if(TEST){delete TEST; TEST=0;}
176  //if(randev){delete randev; randev=0;}
177  if(gen){delete gen; gen=0;}
178 }
ModelData * MD
the model data object
Definition: ThreadManager.h:72
Init * INIT
the Init object (pre-simulation scheduler)
Definition: ThreadManager.h:74
Scheduler * SCD
the scheduler object (simulation-loops scheduler)
Definition: ThreadManager.h:75
Gis * GIS
GIS information and methods.
Definition: ThreadManager.h:73
ModelCore * CORE
Core of the model.
Definition: ThreadManager.h:77
ModelCoreSpatial * SCORE
Core of the model (spatial version)
Definition: ThreadManager.h:78
Output * DO
data output
Definition: ThreadManager.h:76
Carbon * CBAL
Module for the Carbon Balance.
Definition: ThreadManager.h:79
std::mt19937 * gen
used in the sampling from normal distribution
Definition: ThreadManager.h:83
Sandbox * TEST
Various debugging code for development.
Definition: ThreadManager.h:80
void fitInWindow ( )
inline

Definition at line 148 of file ThreadManager.h.

148 {emit fitInWindowToGui();}; ///< Re-draw the map making it to fit (with the right proportions) to the widget
void fitInWindowToGui()
void fitInWindowToGui ( )
signal
string getBaseDirectory ( )
inline

Definition at line 98 of file ThreadManager.h.

Referenced by ModelData::getTableFromFile(), ModelData::loadInput(), and MainProgram::MainProgram().

98 {return baseDirectory.toStdString();};
QString baseDirectory

Here is the caller graph for this function:

string getInputFileName ( )
inline

Definition at line 99 of file ThreadManager.h.

Referenced by ModelData::loadInput().

99 {return inputFileName.toStdString();};
QString inputFileName

Here is the caller graph for this function:

string getScenarioName ( )
inline
void msgOut ( const int  msgCode_h,
const string  message_h 
)

Definition at line 245 of file ThreadManager.cpp.

245  {
246  QString message = message_h.c_str();
247  emit upgradeLogArea(message);
248  if (msgCode_h == 2){
249  emit upgradeMainSBLabelToGui(message);
250  }
251 }
void upgradeMainSBLabelToGui(const QString &logMessage)
void upgradeLogArea(const QString &logMessage)
void pause ( )

Definition at line 203 of file ThreadManager.cpp.

203  {
204  if(!stopped){
205  if(running){
206  running= false;
207  }
208  else {
209  return;
210  }
211  }
212  return;
213 }
volatile bool stopped
volatile bool running
void pauseOrResume ( )

Definition at line 187 of file ThreadManager.cpp.

187  {
188  if(!stopped){
189  if(running){
190  running= false;
191  emit upgradeLogArea("PAUSE cliccked PAUSING");
192  }
193  else {
194  running=true;
195  emit upgradeLogArea("PAUSE cliccked RESUMING");
196  emit setGUIUnsavedStatus(true);
197  }
198  }
199  return;
200 }
volatile bool stopped
volatile bool running
void setGUIUnsavedStatus(bool status_h)
void upgradeLogArea(const QString &logMessage)
void publishQueryResults ( const QString &  results)
signal
void queryRequestOnPx ( int  px_ID,
int  currentLayerIndex 
)
signal
void refreshGUI ( )

Definition at line 230 of file ThreadManager.cpp.

230  {
231  checkQuery(0,0,false);
232  while (!running){
233  if(stopped){
234  break;
235  }
236  }
237  if (stopped){
238  emit upgradeLogArea("Model has been stopped.");
239  running= false;
240  throw(2);
241  }
242 }
volatile bool stopped
volatile bool running
void upgradeLogArea(const QString &logMessage)
void checkQuery(int px_ID, int currentLayerIndex, bool newRequest=true)
Switch and control the access to pxQueryID and layerQueryPos members.
void resetGUIForNewSimulation ( )
signal
void resume ( )

Definition at line 216 of file ThreadManager.cpp.

216  {
217  if(!stopped){
218  if(running){
219  return;
220  }
221  else {
222  running=true;
223  emit setGUIUnsavedStatus(true);
224  }
225  }
226  return;
227 }
volatile bool stopped
volatile bool running
void setGUIUnsavedStatus(bool status_h)
void retrieveScenarioNameFromGUI ( const QString &  scenarioName_h)
slot

Definition at line 117 of file ThreadManager.cpp.

117  {
118  scenarioName = scenarioName_h;
119  msgOut(MSG_INFO, "Selected scenario: "+scenarioName.toStdString());
120  cout << "Selected scenario: "+scenarioName.toStdString() << endl;
121  resume();
122 }
QString scenarioName
Print an INFO message.
Definition: BaseClass.h:59
void msgOut(const int msgCode_h, const string message_h)
void run ( )
protected

Definition at line 66 of file ThreadManager.cpp.

66  {
67  running=true;
68  stopped=false;
69 
70  srand(1);
71  GUI=true;
72 
73  emit upgradeLogArea("**INFO: Start running the model...");
74 
75  MainProgram* myProgram;
76  try{
79 
80 
81  QFileInfo file(inputFileName);
82  QDir baseDir = file.absoluteDir();
83  baseDirectory = baseDir.absolutePath()+"/";
84  myProgram = new MainProgram(this);
85 
86  //myProgram->setBaseDirectory(baseDirectory);
87 
88  vector<string> scenarios = MD->getScenarios();
89  QVector<QString> qscenarios;
90  for(uint i=0;i<scenarios.size();i++){
91  qscenarios.push_back(scenarios.at(i).c_str());
92  }
93  running = false;
94  emit sendScenarioOptionsToGUI(qscenarios);
95  refreshGUI();
96 
97  myProgram->run();
98 
99  // Here the model has come to an end...
100  running=false;
101  stopped=true;
102  delete myProgram;
103  refreshGUI();
104 
105  }catch (...) {
106  // Here the model has come to an end...
107  running=false;
108  stopped=true;
109  delete myProgram;
110  emit upgradeLogArea("**INFO: Model has stopped or rised an error (read previous line).");
111  }
112  emit upgradeLogArea("**INFO: Model has ended.");
113 
114 }
volatile bool stopped
volatile bool running
ModelData * MD
the model data object
Definition: ThreadManager.h:72
Main program scheleton. It control the flow of the program.
Definition: MainProgram.h:47
void deleteDeadOldPointers()
Useful for several model running without leaving the GUI.
void sendScenarioOptionsToGUI(const QVector< QString > &scenarios_h)
void upgradeLogArea(const QString &logMessage)
void resetGUIForNewSimulation()
vector< string > getScenarios()
Definition: ModelData.cpp:146
void run()
Run the program.
Definition: MainProgram.cpp:58
QString baseDirectory
QString inputFileName

Here is the call graph for this function:

void runFromConsole ( QString  inputFileName_h,
QString  scenarioName_h 
)

Re-draw the map making it to fit (with the right proportions) to the widget.

Definition at line 125 of file ThreadManager.cpp.

Referenced by main().

125  {
126  try{
127  GUI = false;
128  scenarioName = scenarioName_h;
129  inputFileName = inputFileName_h;
130  QFileInfo file(inputFileName);
131  QDir baseDir = file.absoluteDir();
132  baseDirectory = baseDir.absolutePath()+"/";
133  cout <<"Using base directory: "<< baseDirectory.toStdString() << endl;
134 
135 
136  MainProgram* myProgram = new MainProgram(this);
137 
138  if( scenarioName_h == ""){ // if the scenario option has not been choosed, go for the first one!
139  vector<string> scenarios = MD->getScenarios();
140  scenarioName = scenarios.at(0).c_str();
141  }
142 
143  //myProgram->setBaseDirectory(baseDirectory);
144  myProgram->run();
145  }catch (...) {
146  exit(EXIT_FAILURE);
147  }
148 }
QString scenarioName
ModelData * MD
the model data object
Definition: ThreadManager.h:72
Main program scheleton. It control the flow of the program.
Definition: MainProgram.h:47
vector< string > getScenarios()
Definition: ModelData.cpp:146
void run()
Run the program.
Definition: MainProgram.cpp:58
QString baseDirectory
QString inputFileName

Here is the call graph for this function:

Here is the caller graph for this function:

void sendScenarioOptionsToGUI ( const QVector< QString > &  scenarios_h)
signal
void setCBALPointer ( Carbon CBAL_h)
inline

Module that account for the Carbon Balance.

Definition at line 123 of file ThreadManager.h.

Referenced by MainProgram::run().

123 {CBAL=CBAL_h;};
Carbon * CBAL
Module for the Carbon Balance.
Definition: ThreadManager.h:79

Here is the caller graph for this function:

void setCOREPointer ( ModelCore CORE_h)
inline

Perform the algorithms of the model.

Definition at line 117 of file ThreadManager.h.

Referenced by MainProgram::run().

117 {CORE=CORE_h;};
ModelCore * CORE
Core of the model.
Definition: ThreadManager.h:77

Here is the caller graph for this function:

void setDOPointer ( Output DO_h)
inline

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()..

Definition at line 115 of file ThreadManager.h.

Referenced by MainProgram::run().

115 {DO=DO_h;};
Output * DO
data output
Definition: ThreadManager.h:76

Here is the caller graph for this function:

void setGISPointer ( Gis GIS_h)
inline

GIS information and methods..

Definition at line 107 of file ThreadManager.h.

Referenced by MainProgram::run().

107 {GIS=GIS_h;};
Gis * GIS
GIS information and methods.
Definition: ThreadManager.h:73

Here is the caller graph for this function:

void setGUIMapDimension ( int  x_h,
int  y_h 
)
signal
void setGUIUnsavedStatus ( bool  status_h)
signal
void setINITPointer ( Init INIT_h)
inline

the Init object, it schedule the pre-simulation phase..

Definition at line 109 of file ThreadManager.h.

Referenced by MainProgram::run().

109 {INIT=INIT_h;};
Init * INIT
the Init object (pre-simulation scheduler)
Definition: ThreadManager.h:74

Here is the caller graph for this function:

void setInputFileName ( QString  inputFileName_h)

Definition at line 151 of file ThreadManager.cpp.

151  {
152  inputFileName= inputFileName_h;
153  QFileInfo file(inputFileName);
154  QDir baseDir = file.absoluteDir();
155  baseDirectory = baseDir.absolutePath()+"/";
156 }
QString baseDirectory
QString inputFileName
void setMDPointer ( ModelData MD_h)
inline

the regional data object..

Definition at line 105 of file ThreadManager.h.

Referenced by MainProgram::MainProgram().

105 {MD=MD_h;};
ModelData * MD
the model data object
Definition: ThreadManager.h:72

Here is the caller graph for this function:

void setMessage ( const QString &  message)

Definition at line 62 of file ThreadManager.cpp.

62  {
63  messageStr = message;
64 }
QString messageStr
void setOPTPointer ( Ipopt::SmartPtr< Ipopt::TNLP >  OPT_h)
inline

Perform the market optimisation.

Definition at line 121 of file ThreadManager.h.

Referenced by MainProgram::run().

121 {OPT=OPT_h;};
Ipopt::SmartPtr< Ipopt::TNLP > OPT
Market optimisation.
Definition: ThreadManager.h:81

Here is the caller graph for this function:

void setOutputDirName ( string  outputDirname_h)

Definition at line 254 of file ThreadManager.cpp.

Referenced by ModelData::setOutputDirectory().

254  {
255  emit setOutputDirNameToGui(outputDirname_h);
256 }
void setOutputDirNameToGui(string outputDirname_h)

Here is the caller graph for this function:

void setOutputDirNameToGui ( string  outputDirname_h)
signal
void setSCDPointer ( Scheduler SCD_h)
inline

the scheduler object. It manage the simulation loops..

Definition at line 113 of file ThreadManager.h.

Referenced by MainProgram::run().

113 {SCD=SCD_h;};
Scheduler * SCD
the scheduler object (simulation-loops scheduler)
Definition: ThreadManager.h:75

Here is the caller graph for this function:

void setScenarioName ( const string &  scenarioName_h)
inline

Definition at line 101 of file ThreadManager.h.

Referenced by Init::setInitLevel1().

101 {scenarioName=scenarioName_h.c_str();};
QString scenarioName

Here is the caller graph for this function:

void setSCOREPointer ( ModelCoreSpatial SCORE_h)
inline

Perform the algorithms of the model.

Definition at line 119 of file ThreadManager.h.

Referenced by MainProgram::run().

119 {SCORE=SCORE_h;};
ModelCoreSpatial * SCORE
Core of the model (spatial version)
Definition: ThreadManager.h:78

Here is the caller graph for this function:

void setTestPointer ( Sandbox TEST_h)
inline

the sandbox object for within-development quick tests

Definition at line 111 of file ThreadManager.h.

Referenced by MainProgram::run().

111 {TEST=TEST_h;};
Sandbox * TEST
Various debugging code for development.
Definition: ThreadManager.h:80

Here is the caller graph for this function:

void stop ( )

Definition at line 181 of file ThreadManager.cpp.

181  {
182  stopped = true;
183  emit upgradeLogArea("STOP cliccked stopping");
184 }
volatile bool stopped
void upgradeLogArea(const QString &logMessage)
void treeViewerAddItemToGui ( string  text,
string  itemID,
string  parentID 
)
signal
void treeViewerChangeGeneralPropertyValue ( string  propertyName,
string  newValue 
)
inline

Definition at line 144 of file ThreadManager.h.

Referenced by Scheduler::run().

144  {
145  emit treeViewerItemChangeValueToGui("general_"+propertyName, newValue);};
void treeViewerItemChangeValueToGui(string itemID, string newValue)

Here is the caller graph for this function:

void treeViewerItemChangeValueToGui ( string  itemID,
string  newValue 
)
signal
void treeViewerItemRemoveToGui ( string  itemID)
signal
void updateImage ( string  layerName_h,
const QImage &  image_h 
)

Definition at line 271 of file ThreadManager.cpp.

271  {
272  emit updateImageToGui(layerName_h.c_str(), image_h);
273 }
void updateImageToGui(QString layerName_h, QImage image_h)
void updateImageToGui ( QString  layerName_h,
QImage  image_h 
)
signal
void updatePixel ( string  layerName_h,
int  x_h,
int  y_h,
QColor  color 
)

Definition at line 266 of file ThreadManager.cpp.

266  {
267  emit updatePixelToGui(layerName_h.c_str(), x_h, y_h, color_h);
268 }
void updatePixelToGui(QString layerName_h, int x_h, int y_h, QColor color)
void updatePixelToGui ( QString  layerName_h,
int  x_h,
int  y_h,
QColor  color 
)
signal
void upgradeLogArea ( const QString &  logMessage)
signal
void upgradeMainSBLabel ( const string  message_h)

Definition at line 276 of file ThreadManager.cpp.

Referenced by Scheduler::run().

276  {
277  emit upgradeMainSBLabelToGui(message_h.c_str());
278 }
void upgradeMainSBLabelToGui(const QString &logMessage)

Here is the caller graph for this function:

void upgradeMainSBLabelToGui ( const QString &  logMessage)
signal
void upgradeYearSBLabel ( int  year)

Definition at line 281 of file ThreadManager.cpp.

Referenced by Scheduler::run().

281  {
282  QString temp;
283  temp= i2s(year).c_str();
284  emit upgradeYearSBLabelToGui(temp);
285 }
string i2s(const int &int_h) const
integer to string conversion
Definition: BaseClass.cpp:219
void upgradeYearSBLabelToGui(const QString &logMessage)

Here is the caller graph for this function:

void upgradeYearSBLabelToGui ( const QString &  logMessage)
signal
bool usingGUI ( )
inline

Definition at line 150 of file ThreadManager.h.

150 {return GUI;};

Here is the call graph for this function:

Member Data Documentation

QString baseDirectory
private

Definition at line 188 of file ThreadManager.h.

ModelCore* CORE

Core of the model.

Definition at line 77 of file ThreadManager.h.

Referenced by Scheduler::run(), and Init::setInitLevel3().

std::mt19937* gen

used in the sampling from normal distribution

Definition at line 83 of file ThreadManager.h.

Referenced by Init::setInitLevel1().

bool GUI
private

Definition at line 193 of file ThreadManager.h.

Init* INIT

the Init object (pre-simulation scheduler)

Definition at line 74 of file ThreadManager.h.

Referenced by MainProgram::run().

QString inputFileName
private

Definition at line 187 of file ThreadManager.h.

volatile int layerQueryPos
private

Definition at line 191 of file ThreadManager.h.

ModelData* MD

the model data object

Definition at line 72 of file ThreadManager.h.

Referenced by ModelCoreSpatial::assignSpMultiplierPropToVols(), ModelCoreSpatial::cacheDynamicSettings(), ModelCoreSpatial::cachePixelExogenousData(), ModelCore::cacheSettings(), ModelCoreSpatial::cacheSettings(), Output::commonInit(), ModelCoreSpatial::computeCumulativeData(), ModelCoreSpatial::computeInventary(), ModelRegion::getArea(), ModelData::getAvailableAliveTimber(), ModelData::getBoolSetting(), ModelData::getBoolVectorSetting(), ModelData::getDoubleSetting(), ModelData::getDoubleVectorSetting(), ModelData::getIntSetting(), ModelData::getIntVectorSetting(), Pixel::getMultiplier(), Output::getOutputFieldDelimiter(), Pixel::getPathMortality(), ModelData::getRegionIds(), ModelRegion::getSiblings(), Pixel::getSpModifier(), Pixel::getSTData(), Carbon::getStock(), ModelData::getStringSetting(), ModelData::getStringVectorSetting(), ModelCore::gfd(), ModelCoreSpatial::gfd(), ModelCore::gpd(), ModelCoreSpatial::gpd(), Carbon::HWP_eol2energy(), Carbon::initialiseDeathBiomassStocks(), Carbon::initialiseEmissionCounters(), Carbon::initialiseProductsStocks(), Output::initOutputForestData(), ModelCoreSpatial::loadExogenousForestLayers(), ModelData::loadInput(), MainProgram::MainProgram(), ModelRegion::ModelRegion(), Pixel::Pixel(), Output::print(), Layers::print(), Layers::printBinMap(), Output::printCarbonBalance(), Output::printDebugOutput(), Output::printDebugPixelValues(), Output::printDetailedHV(), Output::printFinalOutput(), Output::printForestData(), Output::printProductData(), ModelData::regId2RegSName(), Carbon::registerDeathBiomass(), Carbon::registerHarvesting(), Carbon::registerProducts(), Carbon::registerTransports(), ModelData::regSName2RegId(), ModelCoreSpatial::resetPixelValues(), Scheduler::run(), ModelCoreSpatial::runBiologicalModule(), ModelCore::runManagementModule(), ModelCoreSpatial::runManagementModule(), ModelCore::runMarketModule(), ModelCoreSpatial::runMarketModule(), Init::setInitLevel1(), Init::setInitLevel3(), ModelCore::sfd(), ModelCoreSpatial::sfd(), ModelCore::spd(), ModelCoreSpatial::spd(), ModelCoreSpatial::sumRegionalForData(), ModelCore::updateMapAreas(), ModelCoreSpatial::updateMapAreas(), and ModelCoreSpatial::updateOtherMapData().

QString messageStr
private

Definition at line 184 of file ThreadManager.h.

QMutex mutex
private

Definition at line 192 of file ThreadManager.h.

Ipopt::SmartPtr<Ipopt::TNLP> OPT

Market optimisation.

Definition at line 81 of file ThreadManager.h.

Referenced by ModelCore::runMarketModule(), and ModelCoreSpatial::runMarketModule().

volatile int pxQueryID
private

Definition at line 190 of file ThreadManager.h.

volatile bool running
private

Definition at line 186 of file ThreadManager.h.

Scheduler* SCD

the scheduler object (simulation-loops scheduler)

Definition at line 75 of file ThreadManager.h.

Referenced by ModelCoreSpatial::allocateHarvesting(), ModelCore::cacheSettings(), ModelCore::computeCumulativeData(), ModelCoreSpatial::computeCumulativeData(), ModelCoreSpatial::computeEconomicBalances(), ModelCore::computeInventary(), ModelCoreSpatial::computeInventary(), ModelData::getAllocableProductIdsFromDeathTimber(), ModelData::getBaseData(), Pixel::getMultiplier(), Pixel::getPathMortality(), Pixel::getSTData(), Carbon::getStock(), ModelData::getTimedData(), ModelCoreSpatial::getVHaByYear(), Carbon::HWP_eol2energy(), Carbon::initialiseDeathBiomassStocks(), ModelCoreSpatial::initialiseDeathTimber(), Carbon::initialiseProductsStocks(), Output::print(), Layers::print(), Layers::printBinMap(), Output::printCarbonBalance(), Output::printDebugOutput(), Output::printDebugPixelValues(), Output::printDetailedHV(), Output::printForestData(), Output::printMaps(), Output::printOptLog(), Output::printProductData(), Carbon::registerDeathBiomass(), Carbon::registerHarvesting(), Carbon::registerProducts(), ModelCore::runBiologicalModule(), ModelCoreSpatial::runBiologicalModule(), ModelCore::runInitPeriod(), ModelCoreSpatial::runInitPeriod(), ModelCore::runManagementModule(), ModelCoreSpatial::runManagementModule(), ModelCore::runMarketModule(), ModelCoreSpatial::runMarketModule(), ModelCore::runSimulationYear(), ModelCoreSpatial::runSimulationYear(), Init::setInitLevel1(), Init::setInitLevel5(), ModelData::setTimedData(), ModelCoreSpatial::sumRegionalForData(), ModelCore::updateMapAreas(), and ModelCoreSpatial::updateMapAreas().

QString scenarioName
private

Definition at line 189 of file ThreadManager.h.

Core of the model (spatial version)

Definition at line 78 of file ThreadManager.h.

Referenced by Scheduler::run(), and Init::setInitLevel3().

volatile bool stopped
private

Definition at line 185 of file ThreadManager.h.

Sandbox* TEST

Various debugging code for development.

Definition at line 80 of file ThreadManager.h.

Referenced by Init::setInitLevel1().


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