FFSM++ 1.1.0
French Forest Sector Model ++
Loading...
Searching...
No Matches
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.
 
void computeQuery (int px_ID, int currentLayerIndex)
 Compute the pixel query and return it to the GUI (with a signal)
 
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.
 
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..
 
void setGISPointer (Gis *GIS_h)
 GIS information and methods..
 
void setINITPointer (Init *INIT_h)
 the Init object, it schedule the pre-simulation phase..
 
void setTestPointer (Sandbox *TEST_h)
 the sandbox object for within-development quick tests
 
void setSCDPointer (Scheduler *SCD_h)
 the scheduler object. It manage the simulation loops..
 
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()..
 
void setCOREPointer (ModelCore *CORE_h)
 Perform the algorithms of the model.
 
void setSCOREPointer (ModelCoreSpatial *SCORE_h)
 Perform the algorithms of the model.
 
void setOPTPointer (Ipopt::SmartPtr< Ipopt::TNLP > OPT_h)
 Perform the market optimisation.
 
void setCBALPointer (Carbon *CBAL_h)
 Module that account for the Carbon Balance.
 
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.
 
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.
 
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
 

Public Attributes

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

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.
 

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

◆ ThreadManager()

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="";
58
59}
QString scenarioName
QString baseDirectory
Init * INIT
the Init object (pre-simulation scheduler)
QString inputFileName
Carbon * CBAL
Module for the Carbon Balance.
Scheduler * SCD
the scheduler object (simulation-loops scheduler)
ModelCoreSpatial * SCORE
Core of the model (spatial version)
Sandbox * TEST
Various debugging code for development.
volatile bool running
Gis * GIS
GIS information and methods.
volatile int layerQueryPos
volatile bool stopped
ModelData * MD
the model data object
std::mt19937 * gen
used in the sampling from normal distribution
Output * DO
data output
ModelCore * CORE
Core of the model.

Member Function Documentation

◆ activateTab

void activateTab ( int  pos_h)
signal

Referenced by computeQuery().

Here is the caller graph for this function:

◆ addLayer()

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)

Referenced by Gis::addLayer().

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

◆ addLayerToGui

void addLayerToGui ( QString  layerName,
QString  layerLabel 
)
signal

Referenced by addLayer().

Here is the caller graph for this function:

◆ checkQuery

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 int pxQueryID
void publishQueryResults(const QString &results)
void computeQuery(int px_ID, int currentLayerIndex)
Compute the pixel query and return it to the GUI (with a signal)

Referenced by refreshGUI().

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

◆ computeQuery

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
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
Pixel-level class.
Definition Pixel.h:47
double getDoubleValue(const string &layerName_h, const bool &returnZeroForNoValue=false) const
Return the value for a specific layer.
Definition Pixel.cpp:158
int getX() const
Definition Pixel.h:68
int getY() const
Definition Pixel.h:69
void activateTab(int pos_h)

Referenced by checkQuery().

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

◆ deleteDeadOldPointers()

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}

Referenced by run().

Here is the caller graph for this function:

◆ fitInWindow()

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

Referenced by Gis::setSpace().

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

◆ fitInWindowToGui

void fitInWindowToGui ( )
signal

Referenced by fitInWindow().

Here is the caller graph for this function:

◆ getBaseDirectory()

string getBaseDirectory ( )
inline

Definition at line 98 of file ThreadManager.h.

98{return baseDirectory.toStdString();};

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

Here is the caller graph for this function:

◆ getInputFileName()

string getInputFileName ( )
inline

Definition at line 99 of file ThreadManager.h.

99{return inputFileName.toStdString();};

Referenced by ModelData::loadInput().

Here is the caller graph for this function:

◆ getScenarioName()

string getScenarioName ( )
inline

◆ msgOut()

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)

Referenced by BaseClass::msgOut2(), and retrieveScenarioNameFromGUI().

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

◆ pause()

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}

◆ pauseOrResume()

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}
void setGUIUnsavedStatus(bool status_h)

Referenced by MainWindow::pauseOrResumeModelMainThread().

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

◆ publishQueryResults

void publishQueryResults ( const QString &  results)
signal

Referenced by checkQuery(), and computeQuery().

Here is the caller graph for this function:

◆ queryRequestOnPx

void queryRequestOnPx ( int  px_ID,
int  currentLayerIndex 
)
signal

◆ refreshGUI()

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}
void checkQuery(int px_ID, int currentLayerIndex, bool newRequest=true)
Switch and control the access to pxQueryID and layerQueryPos members.

Referenced by BaseClass::refreshGUI(), and run().

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

◆ resetGUIForNewSimulation

void resetGUIForNewSimulation ( )
signal

Referenced by run().

Here is the caller graph for this function:

◆ resume()

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}

Referenced by retrieveScenarioNameFromGUI().

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

◆ retrieveScenarioNameFromGUI

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}
@ MSG_INFO
Print an INFO message.
Definition BaseClass.h:59
void msgOut(const int msgCode_h, const string message_h)
Here is the call graph for this function:

◆ run()

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}
Main program scheleton. It control the flow of the program.
Definition MainProgram.h:47
void run()
Run the program.
vector< string > getScenarios()
void sendScenarioOptionsToGUI(const QVector< QString > &scenarios_h)
void resetGUIForNewSimulation()
void deleteDeadOldPointers()
Useful for several model running without leaving the GUI.
Here is the call graph for this function:

◆ runFromConsole()

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.

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}

Referenced by main().

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

◆ sendScenarioOptionsToGUI

void sendScenarioOptionsToGUI ( const QVector< QString > &  scenarios_h)
signal

Referenced by run().

Here is the caller graph for this function:

◆ setCBALPointer()

void setCBALPointer ( Carbon CBAL_h)
inline

Module that account for the Carbon Balance.

Definition at line 123 of file ThreadManager.h.

123{CBAL=CBAL_h;};

Referenced by MainProgram::run().

Here is the caller graph for this function:

◆ setCOREPointer()

void setCOREPointer ( ModelCore CORE_h)
inline

Perform the algorithms of the model.

Definition at line 117 of file ThreadManager.h.

117{CORE=CORE_h;};

Referenced by MainProgram::run().

Here is the caller graph for this function:

◆ setDOPointer()

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.

115{DO=DO_h;};

Referenced by MainProgram::run().

Here is the caller graph for this function:

◆ setGISPointer()

void setGISPointer ( Gis GIS_h)
inline

GIS information and methods..

Definition at line 107 of file ThreadManager.h.

107{GIS=GIS_h;};

Referenced by MainProgram::run().

Here is the caller graph for this function:

◆ setGUIMapDimension

void setGUIMapDimension ( int  x_h,
int  y_h 
)
signal

◆ setGUIUnsavedStatus

void setGUIUnsavedStatus ( bool  status_h)
signal

Referenced by pauseOrResume(), and resume().

Here is the caller graph for this function:

◆ setINITPointer()

void setINITPointer ( Init INIT_h)
inline

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

Definition at line 109 of file ThreadManager.h.

109{INIT=INIT_h;};

Referenced by MainProgram::run().

Here is the caller graph for this function:

◆ setInputFileName()

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}

Referenced by MainWindow::MainWindow(), and MainWindow::setCurrentModelFileName().

Here is the caller graph for this function:

◆ setMDPointer()

void setMDPointer ( ModelData MD_h)
inline

the regional data object..

Definition at line 105 of file ThreadManager.h.

105{MD=MD_h;};

Referenced by MainProgram::MainProgram().

Here is the caller graph for this function:

◆ setMessage()

void setMessage ( const QString &  message)

Definition at line 62 of file ThreadManager.cpp.

62 {
63 messageStr = message;
64}

◆ setOPTPointer()

void setOPTPointer ( Ipopt::SmartPtr< Ipopt::TNLP >  OPT_h)
inline

Perform the market optimisation.

Definition at line 121 of file ThreadManager.h.

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

Referenced by MainProgram::run().

Here is the caller graph for this function:

◆ setOutputDirName()

void setOutputDirName ( string  outputDirname_h)

Definition at line 254 of file ThreadManager.cpp.

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

Referenced by ModelData::setOutputDirectory().

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

◆ setOutputDirNameToGui

void setOutputDirNameToGui ( string  outputDirname_h)
signal

Referenced by setOutputDirName().

Here is the caller graph for this function:

◆ setSCDPointer()

void setSCDPointer ( Scheduler SCD_h)
inline

the scheduler object. It manage the simulation loops..

Definition at line 113 of file ThreadManager.h.

113{SCD=SCD_h;};

Referenced by MainProgram::run().

Here is the caller graph for this function:

◆ setScenarioName()

void setScenarioName ( const string &  scenarioName_h)
inline

Definition at line 101 of file ThreadManager.h.

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

Referenced by Init::setInitLevel1().

Here is the caller graph for this function:

◆ setSCOREPointer()

void setSCOREPointer ( ModelCoreSpatial SCORE_h)
inline

Perform the algorithms of the model.

Definition at line 119 of file ThreadManager.h.

119{SCORE=SCORE_h;};

Referenced by MainProgram::run().

Here is the caller graph for this function:

◆ setTestPointer()

void setTestPointer ( Sandbox TEST_h)
inline

the sandbox object for within-development quick tests

Definition at line 111 of file ThreadManager.h.

111{TEST=TEST_h;};

Referenced by MainProgram::run().

Here is the caller graph for this function:

◆ stop()

void stop ( )

Definition at line 181 of file ThreadManager.cpp.

181 {
182 stopped = true;
183 emit upgradeLogArea("STOP cliccked stopping");
184}

Referenced by MainWindow::closeEvent(), MainWindow::okToContinue(), and MainWindow::stopModelMainThread().

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

◆ treeViewerAddItemToGui

void treeViewerAddItemToGui ( string  text,
string  itemID,
string  parentID 
)
signal

◆ treeViewerChangeGeneralPropertyValue()

void treeViewerChangeGeneralPropertyValue ( string  propertyName,
string  newValue 
)
inline

Definition at line 144 of file ThreadManager.h.

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

Referenced by Scheduler::run(), and Gis::setSpace().

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

◆ treeViewerItemChangeValueToGui

void treeViewerItemChangeValueToGui ( string  itemID,
string  newValue 
)
signal

Referenced by treeViewerChangeGeneralPropertyValue().

Here is the caller graph for this function:

◆ treeViewerItemRemoveToGui

void treeViewerItemRemoveToGui ( string  itemID)
signal

◆ updateImage()

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)

Referenced by Gis::loadLayersDataFromFile(), and Gis::updateImage().

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

◆ updateImageToGui

void updateImageToGui ( QString  layerName_h,
QImage  image_h 
)
signal

Referenced by updateImage().

Here is the caller graph for this function:

◆ updatePixel()

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)
Here is the call graph for this function:

◆ updatePixelToGui

void updatePixelToGui ( QString  layerName_h,
int  x_h,
int  y_h,
QColor  color 
)
signal

Referenced by updatePixel().

Here is the caller graph for this function:

◆ upgradeLogArea

void upgradeLogArea ( const QString &  logMessage)
signal

Referenced by msgOut(), pauseOrResume(), refreshGUI(), run(), and stop().

Here is the caller graph for this function:

◆ upgradeMainSBLabel()

void upgradeMainSBLabel ( const string  message_h)

Definition at line 276 of file ThreadManager.cpp.

276 {
277 emit upgradeMainSBLabelToGui(message_h.c_str());
278}

Referenced by Scheduler::run().

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

◆ upgradeMainSBLabelToGui

void upgradeMainSBLabelToGui ( const QString &  logMessage)
signal

Referenced by msgOut(), and upgradeMainSBLabel().

Here is the caller graph for this function:

◆ upgradeYearSBLabel()

void upgradeYearSBLabel ( int  year)

Definition at line 281 of file ThreadManager.cpp.

281 {
282 QString temp;
283 temp= i2s(year).c_str();
284 emit upgradeYearSBLabelToGui(temp);
285}
void upgradeYearSBLabelToGui(const QString &logMessage)

Referenced by Scheduler::run().

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

◆ upgradeYearSBLabelToGui

void upgradeYearSBLabelToGui ( const QString &  logMessage)
signal

Referenced by upgradeYearSBLabel().

Here is the caller graph for this function:

◆ usingGUI()

bool usingGUI ( )
inline

Definition at line 150 of file ThreadManager.h.

150{return GUI;};

Referenced by BaseClass::msgOut2(), and BaseClass::refreshGUI().

Here is the caller graph for this function:

Member Data Documentation

◆ baseDirectory

QString baseDirectory
private

◆ CBAL

◆ CORE

ModelCore* CORE

Core of the model.

Definition at line 77 of file ThreadManager.h.

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

◆ DO

◆ gen

std::mt19937* gen

◆ GIS

◆ GUI

bool GUI
private

Definition at line 193 of file ThreadManager.h.

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

◆ INIT

Init* INIT

the Init object (pre-simulation scheduler)

Definition at line 74 of file ThreadManager.h.

Referenced by deleteDeadOldPointers(), MainProgram::run(), setINITPointer(), and ThreadManager().

◆ inputFileName

QString inputFileName
private

◆ layerQueryPos

volatile int layerQueryPos
private

Definition at line 191 of file ThreadManager.h.

Referenced by checkQuery(), and ThreadManager().

◆ MD

ModelData* MD

the model data object

Definition at line 72 of file ThreadManager.h.

Referenced by ModelCore::app(), ModelCoreSpatial::app(), Opt::app(), Gis::applyForestReclassification(), Gis::applySpatialStochasticValues(), Gis::applyStochasticRiskAdversion(), ModelCoreSpatial::assignSpMultiplierPropToVols(), ModelCoreSpatial::cacheDynamicSettings(), ModelCoreSpatial::cachePixelExogenousData(), ModelCore::cacheSettings(), ModelCoreSpatial::cacheSettings(), Output::commonInit(), ModelCoreSpatial::computeCumulativeData(), ModelCoreSpatial::computeInventary(), Opt::copyInventoryResourses(), deleteDeadOldPointers(), Opt::eval_constraints(), Opt::get_nlp_info(), Gis::getAllPlots(), Gis::getAllPlotsByRegion(), ModelRegion::getArea(), 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(), Opt::gfd(), ModelCore::gfd(), ModelCoreSpatial::gfd(), ModelCore::gpd(), ModelCoreSpatial::gpd(), Opt::gpd(), Carbon::HWP_eol2energy(), Carbon::initialiseDeathBiomassStocks(), Carbon::initialiseEmissionCounters(), Carbon::initialiseProductsStocks(), Gis::initLayers(), Gis::initLayersPixelData(), Output::initOutputForestData(), ModelCoreSpatial::loadExogenousForestLayers(), ModelData::loadInput(), Gis::loadLayersDataFromFile(), MainProgram::MainProgram(), ModelRegion::ModelRegion(), Pixel::Pixel(), Layers::print(), Output::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(), run(), ModelCoreSpatial::runBiologicalModule(), runFromConsole(), ModelCore::runManagementModule(), ModelCoreSpatial::runManagementModule(), ModelCore::runMarketModule(), ModelCoreSpatial::runMarketModule(), Init::setInitLevel1(), Init::setInitLevel3(), setMDPointer(), Gis::setSpace(), Opt::sfd(), ModelCore::sfd(), ModelCoreSpatial::sfd(), ModelCore::spd(), ModelCoreSpatial::spd(), Opt::spd(), ModelCoreSpatial::sumRegionalForData(), ThreadManager(), ModelCore::updateMapAreas(), ModelCoreSpatial::updateMapAreas(), and ModelCoreSpatial::updateOtherMapData().

◆ messageStr

QString messageStr
private

Definition at line 184 of file ThreadManager.h.

Referenced by setMessage().

◆ mutex

QMutex mutex
private

Definition at line 192 of file ThreadManager.h.

Referenced by checkQuery().

◆ OPT

Ipopt::SmartPtr<Ipopt::TNLP> OPT

Market optimisation.

Definition at line 81 of file ThreadManager.h.

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

◆ pxQueryID

volatile int pxQueryID
private

Definition at line 190 of file ThreadManager.h.

Referenced by checkQuery().

◆ running

volatile bool running
private

Definition at line 186 of file ThreadManager.h.

Referenced by pause(), pauseOrResume(), refreshGUI(), resume(), run(), and ThreadManager().

◆ SCD

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(), deleteDeadOldPointers(), Opt::get_nlp_info(), 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(), Layers::print(), Output::print(), Layers::printBinMap(), Gis::printBinMaps(), Output::printCarbonBalance(), Output::printDebugOutput(), Output::printDebugPixelValues(), Output::printDetailedHV(), Output::printForestData(), Gis::printLayers(), 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(), setSCDPointer(), ModelData::setTimedData(), ModelCoreSpatial::sumRegionalForData(), ThreadManager(), ModelCore::updateMapAreas(), and ModelCoreSpatial::updateMapAreas().

◆ scenarioName

QString scenarioName
private

◆ SCORE

Core of the model (spatial version)

Definition at line 78 of file ThreadManager.h.

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

◆ stopped

volatile bool stopped
private

◆ TEST

Sandbox* TEST

Various debugging code for development.

Definition at line 80 of file ThreadManager.h.

Referenced by deleteDeadOldPointers(), Init::setInitLevel1(), setTestPointer(), and ThreadManager().


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