FFSM++
1.1.0
French Forest Sector Model ++
|
Thread manager. Responsable to manage the main thread and "speak" with the GUI. More...
#include <ThreadManager.h>
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 > | |
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 > | |
V | findMap (const map< K, V > &mymap, const K &key, const int &error_level=MSG_CRITICAL_ERROR, const V ¬FoundValue=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 > | |
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 > | |
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 > | |
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 | |
ModelData * | MD |
the model data object More... | |
Gis * | GIS |
GIS information and methods. More... | |
Init * | INIT |
the Init object (pre-simulation scheduler) More... | |
Scheduler * | SCD |
the scheduler object (simulation-loops scheduler) More... | |
Output * | DO |
data output More... | |
ModelCore * | CORE |
Core of the model. More... | |
ModelCoreSpatial * | SCORE |
Core of the model (spatial version) More... | |
Carbon * | CBAL |
Module for the Carbon Balance. More... | |
Sandbox * | TEST |
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 | |
ThreadManager * | MTHREAD |
Pointer to the Thread manager. More... | |
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.
Definition at line 65 of file ThreadManager.h.
ThreadManager | ( | ) |
Definition at line 35 of file ThreadManager.cpp.
|
signal |
void addLayer | ( | string | layerName_h, |
string | layerLabel_h | ||
) |
Definition at line 259 of file ThreadManager.cpp.
|
signal |
|
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.
|
slot |
Compute the pixel query and return it to the GUI (with a signal)
Definition at line 313 of file ThreadManager.cpp.
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.
|
inline |
Definition at line 148 of file ThreadManager.h.
|
signal |
|
inline |
Definition at line 98 of file ThreadManager.h.
Referenced by ModelData::getTableFromFile(), ModelData::loadInput(), and MainProgram::MainProgram().
|
inline |
Definition at line 99 of file ThreadManager.h.
Referenced by ModelData::loadInput().
|
inline |
Definition at line 100 of file ThreadManager.h.
Referenced by Output::commonInit(), ModelData::getScenarioIndex(), ModelData::loadInput(), Layers::print(), Layers::printBinMap(), ModelData::setDefaultSettings(), Init::setInitLevel1(), and ModelData::setScenarioData().
void msgOut | ( | const int | msgCode_h, |
const string | message_h | ||
) |
Definition at line 245 of file ThreadManager.cpp.
void pause | ( | ) |
Definition at line 203 of file ThreadManager.cpp.
void pauseOrResume | ( | ) |
Definition at line 187 of file ThreadManager.cpp.
|
signal |
|
signal |
void refreshGUI | ( | ) |
Definition at line 230 of file ThreadManager.cpp.
|
signal |
void resume | ( | ) |
Definition at line 216 of file ThreadManager.cpp.
|
slot |
Definition at line 117 of file ThreadManager.cpp.
|
protected |
Definition at line 66 of file ThreadManager.cpp.
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().
|
signal |
|
inline |
Module that account for the Carbon Balance.
Definition at line 123 of file ThreadManager.h.
Referenced by MainProgram::run().
|
inline |
Perform the algorithms of the model.
Definition at line 117 of file ThreadManager.h.
Referenced by MainProgram::run().
|
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().
|
inline |
GIS information and methods..
Definition at line 107 of file ThreadManager.h.
Referenced by MainProgram::run().
|
signal |
|
signal |
|
inline |
the Init object, it schedule the pre-simulation phase..
Definition at line 109 of file ThreadManager.h.
Referenced by MainProgram::run().
void setInputFileName | ( | QString | inputFileName_h | ) |
Definition at line 151 of file ThreadManager.cpp.
|
inline |
the regional data object..
Definition at line 105 of file ThreadManager.h.
Referenced by MainProgram::MainProgram().
void setMessage | ( | const QString & | message | ) |
Definition at line 62 of file ThreadManager.cpp.
|
inline |
Perform the market optimisation.
Definition at line 121 of file ThreadManager.h.
Referenced by MainProgram::run().
void setOutputDirName | ( | string | outputDirname_h | ) |
Definition at line 254 of file ThreadManager.cpp.
Referenced by ModelData::setOutputDirectory().
|
signal |
|
inline |
the scheduler object. It manage the simulation loops..
Definition at line 113 of file ThreadManager.h.
Referenced by MainProgram::run().
|
inline |
Definition at line 101 of file ThreadManager.h.
Referenced by Init::setInitLevel1().
|
inline |
Perform the algorithms of the model.
Definition at line 119 of file ThreadManager.h.
Referenced by MainProgram::run().
|
inline |
the sandbox object for within-development quick tests
Definition at line 111 of file ThreadManager.h.
Referenced by MainProgram::run().
void stop | ( | ) |
Definition at line 181 of file ThreadManager.cpp.
|
signal |
|
inline |
Definition at line 144 of file ThreadManager.h.
Referenced by Scheduler::run().
|
signal |
|
signal |
void updateImage | ( | string | layerName_h, |
const QImage & | image_h | ||
) |
Definition at line 271 of file ThreadManager.cpp.
|
signal |
void updatePixel | ( | string | layerName_h, |
int | x_h, | ||
int | y_h, | ||
QColor | color | ||
) |
Definition at line 266 of file ThreadManager.cpp.
|
signal |
|
signal |
void upgradeMainSBLabel | ( | const string | message_h | ) |
Definition at line 276 of file ThreadManager.cpp.
Referenced by Scheduler::run().
|
signal |
void upgradeYearSBLabel | ( | int | year | ) |
Definition at line 281 of file ThreadManager.cpp.
Referenced by Scheduler::run().
|
signal |
|
inline |
|
private |
Definition at line 188 of file ThreadManager.h.
Carbon* CBAL |
Module for the Carbon Balance.
Definition at line 79 of file ThreadManager.h.
Referenced by ModelCoreSpatial::initialiseCarbonModule(), Output::printCarbonBalance(), and ModelCoreSpatial::registerCarbonEvents().
ModelCore* CORE |
Core of the model.
Definition at line 77 of file ThreadManager.h.
Referenced by Scheduler::run(), and Init::setInitLevel3().
Output* DO |
data output
Definition at line 76 of file ThreadManager.h.
Referenced by ModelCore::runInitPeriod(), ModelCoreSpatial::runInitPeriod(), ModelCore::runManagementModule(), ModelCore::runMarketModule(), ModelCoreSpatial::runMarketModule(), ModelCore::runSimulationYear(), ModelCoreSpatial::runSimulationYear(), Init::setInitLevel3(), Init::setInitLevel6(), and ModelCoreSpatial::sumRegionalForData().
std::mt19937* gen |
used in the sampling from normal distribution
Definition at line 83 of file ThreadManager.h.
Referenced by Init::setInitLevel1().
Gis* GIS |
GIS information and methods.
Definition at line 73 of file ThreadManager.h.
Referenced by ModelCoreSpatial::assignSpMultiplierPropToVols(), Pixel::changeValue(), Layers::countMyPixels(), Layers::getCategory(), Layers::getColor(), Pixel::getDoubleValue(), Pixel::getPathMortality(), Pixel::getPixelsAtDistLevel(), ModelCoreSpatial::initializePixelArea(), ModelCoreSpatial::initializePixelVolumes(), ModelCoreSpatial::loadExogenousForestLayers(), Layers::print(), Layers::printBinMap(), Output::printMaps(), Layers::randomShuffle(), Scheduler::run(), Init::setInitLevel1(), ModelRegion::setMyPixels(), ModelCore::updateMapAreas(), ModelCoreSpatial::updateMapAreas(), and ModelCoreSpatial::updateOtherMapData().
|
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().
|
private |
Definition at line 187 of file ThreadManager.h.
|
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().
|
private |
Definition at line 184 of file ThreadManager.h.
|
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().
|
private |
Definition at line 190 of file ThreadManager.h.
|
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().
|
private |
Definition at line 189 of file ThreadManager.h.
ModelCoreSpatial* SCORE |
Core of the model (spatial version)
Definition at line 78 of file ThreadManager.h.
Referenced by Scheduler::run(), and Init::setInitLevel3().
|
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().