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

Base class for the regmas application. More...

#include <BaseClass.h>

Inheritance diagram for BaseClass:
Collaboration diagram for BaseClass:

Public Member Functions

 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
 

Protected Attributes

ThreadManagerMTHREAD
 Pointer to the Thread manager.
 

Private Member Functions

void msgOut2 (const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h) const
 Do the job of the overloaded functions.
 

Detailed Description

Base class for the regmas application.

This class is the base class for all classes in regmas. \ It provides common methods in all parts of the application for printing the output, converting strings vs. values or regularly "ping" the GUI. \

Author
Antonello Lobianco

Definition at line 239 of file BaseClass.h.

Constructor & Destructor Documentation

◆ BaseClass()

BaseClass ( )

Definition at line 31 of file BaseClass.cpp.

32{
33 MTHREAD=NULL;
34}
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition BaseClass.h:467

◆ ~BaseClass()

~BaseClass ( )

Definition at line 36 of file BaseClass.cpp.

37{
38
39}

Member Function Documentation

◆ b2s() [1/2]

string b2s ( const bool &  bool_h) const

bool to string conversion

Definition at line 239 of file BaseClass.cpp.

239 {
240 if (bool_h) return "true";
241 else return "false";
242}

◆ b2s() [2/2]

vector< string > b2s ( const vector< bool > &  bool_h) const

bool to string conversion (vector)

Definition at line 299 of file BaseClass.cpp.

299 {
300 vector <string> valuesAsString;
301 for (uint i=0;i<bool_h.size();i++){
302 if(bool_h[i]) valuesAsString.push_back("true");
303 else valuesAsString.push_back("false");
304 }
305 return valuesAsString;
306}

◆ changeMapValue()

template<typename K , typename V >
void changeMapValue ( map< K, V > &  mymap,
const K &  key,
const V &  value,
const int &  error_level = MSG_CRITICAL_ERROR 
)
inline

Change the value stored in a map given the key and the new value.

Definition at line 299 of file BaseClass.h.

299 {
300 typename map<K, V>::iterator p;
301 p=mymap.find(key);
302 if(p != mymap.end()) {
303 p->second = value;
304 return;
305 }
306 else {
307 msgOut(error_level, "Error in finding a value in a map (no value found)");
308 }
309 }
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition BaseClass.cpp:50
Here is the call graph for this function:

◆ d2s() [1/2]

string d2s ( const double &  double_h) const

double to string conversion

Definition at line 229 of file BaseClass.cpp.

229 {
230 //ostringstream out;
231 //out<<double_h;
232 //return out.str();
233 char outChar[24];
234 snprintf ( outChar, sizeof(outChar), "%f", double_h );
235 return string(outChar);
236}

Referenced by Layers::countMyPixels(), d2s(), Layers::filterExogenousDataset(), Gis::getAllPlotsByValue(), Gis::getAllPlotsByValue(), Gis::getRandomPlotByValue(), msgOut(), Layers::print(), Gis::printDebugValues(), ModelCoreSpatial::runBiologicalModule(), ModelCoreSpatial::runManagementModule(), ModelCoreSpatial::runMarketModule(), and Gis::setSpace().

Here is the caller graph for this function:

◆ d2s() [2/2]

vector< string > d2s ( const vector< double > &  double_h) const

double to string conversion (vector)

Definition at line 290 of file BaseClass.cpp.

290 {
291 vector <string> valuesAsString;
292 for (uint i=0;i<double_h.size();i++){
293 valuesAsString.push_back(d2s(double_h[i]));
294 }
295 return valuesAsString;
296}
string d2s(const double &double_h) const
double to string conversion
Here is the call graph for this function:

◆ debugMap() [1/2]

template<typename V >
void debugMap ( const map< iisskey, V > &  mymap)
inline

Debug a map.

Definition at line 368 of file BaseClass.h.

368 {
369 iisskey mykey(NULL,NULL,"","");
370 debugMap(mymap, mykey);
371 }
void debugMap(const map< iisskey, V > &mymap)
Debug a map.
Definition BaseClass.h:368
Class to provide a simple integer-integer-string-string key in std maps.
Definition BaseClass.h:213

Referenced by debugMap().

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

◆ debugMap() [2/2]

template<typename K , typename V >
void debugMap ( const map< K, V > &  mymap,
const K &  key 
)
inline

Definition at line 372 of file BaseClass.h.

372 {
373 cout<<"Debugging a map" << endl;
374 for (auto const &themap: mymap) {
375 if(themap.first.filter(key)){
376 cout << themap.first.print() << '\t' << themap.second << endl;
377 }
378 }
379 }

◆ findMap()

template<typename K , typename V >
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
inline

Lookup a map for a value. Return the value starting from the key.

Definition at line 286 of file BaseClass.h.

286 {
287 typename map<K, V>::const_iterator p;
288 p=mymap.find(key);
289 if(p != mymap.end()) {
290 return p->second;
291 }
292 else {
293 msgOut(error_level, "Error in finding a value in a map (no value found)");
294 return notFoundValue;
295 }
296 }

Referenced by ModelData::deathTimberInventory_get(), ModelData::getAvailableDeathTimber(), Carbon::getCumSavedEmissions(), Carbon::getStock(), Carbon::HWP_eol2energy(), Output::printDetailedHV(), ModelCoreSpatial::runManagementModule(), ModelCoreSpatial::sumRegionalForData(), and ModelCoreSpatial::updateMapAreas().

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

◆ getAvg()

template<typename K >
double getAvg ( const vector< K > &  v)
inline

Returns the average of the elements in the vector.

Definition at line 399 of file BaseClass.h.

399 {
400 return v.size()==0 ? 0.0 : vSum(v)/ ( (double) v.size() );
401 }
int vSum(const vector< int > &vector_h) const
Definition BaseClass.h:276

Referenced by ModelCoreSpatial::assignSpMultiplierPropToVols().

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

◆ getMax()

template<typename K >
K getMax ( const vector< K > &  v)
inline

Returns the value of the maximum element in the vector (the last one in case of multiple equivalent maxima)

Definition at line 391 of file BaseClass.h.

391 {
392 return *minmax_element(v.begin(), v.end()).second;
393 }

Referenced by ModelCoreSpatial::assignSpMultiplierPropToVols(), and ModelCoreSpatial::sumRegionalForData().

Here is the caller graph for this function:

◆ getMaxPos()

template<typename K >
int getMaxPos ( const vector< K > &  v)
inline

Returns the position of the maximum element in the vector (the last one in case of multiple equivalent maxima)

Definition at line 383 of file BaseClass.h.

383 {
384 return (minmax_element(v.begin(), v.end()).second - v.begin());
385 }

Referenced by ModelCoreSpatial::runManagementModule().

Here is the caller graph for this function:

◆ getMin()

template<typename K >
K getMin ( const vector< K > &  v)
inline

Returns the value of the minimum element in the vector (the first one in case of multiple equivalent minima)

Definition at line 395 of file BaseClass.h.

395 {
396 return *minmax_element(v.begin(), v.end()).first;
397 }

◆ getMinPos()

template<typename K >
int getMinPos ( const vector< K > &  v)
inline

Returns the position of the minimum element in the vector (the first one in case of multiple equivalent minima)

Definition at line 387 of file BaseClass.h.

387 {
388 return (minmax_element(v.begin(), v.end()).first - v.begin());
389 }

◆ getPos()

template<typename K >
int getPos ( const K &  element,
const vector< K > &  v,
const int &  msgCode_h = MSG_CRITICAL_ERROR 
)
inline

Definition at line 421 of file BaseClass.h.

421 {
422 for(unsigned int i=0; i<v.size(); i++){
423 if(v[i]== element) return i;
424 }
425 msgOut(msgCode_h, "Element not found in vector in getPos()");
426 return -1;
427 }

Referenced by ModelCoreSpatial::runManagementModule().

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

◆ getSd()

template<typename K >
double getSd ( const vector< K > &  v,
bool  sample = true 
)
inline

Returns the sd of the elements of a vector. Default to sample sd.

See http://stackoverflow.com/questions/7616511/calculate-mean-and-standard-deviation-from-a-vector-of-samples-in-c-using-boos where there is also an example for covariance

Definition at line 408 of file BaseClass.h.

408 {
409 if (v.size()==0) return 0.0;
410 int sampleCorrection = sample==true?1:0;
411 double sum = std::accumulate(std::begin(v), std::end(v), 0.0);
412 double m = sum / v.size();
413 double accum = 0.0;
414 std::for_each (std::begin(v), std::end(v), [&](const double d) {
415 accum += (d - m) * (d - m);
416 });
417 double stdev = sqrt(accum / ( (double) (v.size()-sampleCorrection)));
418 return stdev;
419 }

Referenced by ModelCoreSpatial::assignSpMultiplierPropToVols().

Here is the caller graph for this function:

◆ getType()

int getType ( const string &  type_h) const

Return a type according to enum TYPE_* from a string (eg: "string" -> TYPE_STRING (2))

Definition at line 310 of file BaseClass.cpp.

310 {
311 int toReturn=0;
312 if (type_h == "int") toReturn = TYPE_INT;
313 else if (type_h == "double") toReturn = TYPE_DOUBLE;
314 else if (type_h == "string") toReturn = TYPE_STRING;
315 else if (type_h == "bool") toReturn = TYPE_BOOL;
316 else msgOut(MSG_CRITICAL_ERROR, "Unknow type "+type_h+".");
317 return toReturn;
318}
@ TYPE_DOUBLE
The required data is a double.
Definition BaseClass.h:67
@ TYPE_BOOL
The required data is a bool.
Definition BaseClass.h:69
@ TYPE_INT
The required data is an integer.
Definition BaseClass.h:66
@ TYPE_STRING
The required data is a string.
Definition BaseClass.h:68
@ MSG_CRITICAL_ERROR
Print an error message and stop the model.
Definition BaseClass.h:62

Referenced by ModelData::setDefaultSettings(), and ModelData::setScenarioSettings().

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

◆ i2s() [1/2]

string i2s ( const int &  int_h) const

integer to string conversion

Definition at line 219 of file BaseClass.cpp.

219 {
220 //ostringstream out;
221 //out<<int_h;
222 //return out.str();
223 char outChar[24];
224 snprintf ( outChar, sizeof(outChar), "%d", int_h );
225 return string(outChar);
226}

Referenced by Layers::addLegendItems(), ModelData::applyOverrides(), ModelCoreSpatial::assignSpMultiplierPropToVols(), Opt::calculateNumberVariablesConstrains(), LLData::clean(), ModelCoreSpatial::computeEconomicBalances(), ThreadManager::computeQuery(), Layers::countMyPixels(), Opt::eval_constraints(), Opt::eval_obj(), Opt::finalize_solution(), Opt::get_starting_point(), Gis::getAllPlotsByValue(), Opt::getBoundByIndex(), LLData::getData(), Opt::getDetailedBoundByVarAndIndex(), Opt::getDomainElements(), Pixel::getDoubleValue(), ModelData::getFilenamesByDir(), ModelData::getForData(), Pixel::getPastRegArea(), Pixel::getPathMortality(), ModelData::getProdData(), ModelData::getRegion(), Pixel::getSTData(), i2s(), ModelCore::initMarketModule(), ModelCoreSpatial::initMarketModule(), Output::initOptimisationLog(), Opt::intermediate_callback(), ModelCoreSpatial::loadExogenousForestLayers(), ModelData::loadInput(), msgOut(), Gis::pack(), Layers::print(), Layers::printBinMap(), Output::printDebugPixelValues(), Gis::printDebugValues(), Output::printDetailedHV(), Output::printOptLog(), Output::printProductData(), ModelCoreSpatial::registerCarbonEvents(), Scheduler::run(), ModelCoreSpatial::runInitPeriod(), ModelCoreSpatial::runManagementModule(), ModelCore::runMarketModule(), ModelCoreSpatial::runMarketModule(), ModelData::setDefaultForData(), ModelData::setDefaultPathogenRules(), ModelData::setDefaultProdData(), ModelData::setDefaultSettings(), ModelData::setForData(), Init::setInitLevel1(), Init::setInitLevel6(), ModelData::setProdData(), ModelData::setScenarioForData(), ModelData::setScenarioPathogenRules(), ModelData::setScenarioProdData(), ModelData::setScenarioSettings(), ModelData::setTimedData(), InputNode::setWorkingFile(), ModelCoreSpatial::sumRegionalForData(), Opt::unpack(), and ThreadManager::upgradeYearSBLabel().

◆ i2s() [2/2]

vector< string > i2s ( const vector< int > &  int_h) const

integer to string conversion (vector)

Definition at line 281 of file BaseClass.cpp.

281 {
282 vector <string> valuesAsString;
283 for (uint i=0;i<int_h.size();i++){
284 valuesAsString.push_back(i2s(int_h[i]));
285 }
286 return valuesAsString;
287}
string i2s(const int &int_h) const
integer to string conversion
Here is the call graph for this function:

◆ incrMapValue()

template<typename K , typename V >
void incrMapValue ( map< K, V > &  mymap,
const K &  key,
const V &  value,
const int &  error_level = MSG_CRITICAL_ERROR 
)
inline

Increments a value stored in a map of the specified value, given the key.

Definition at line 312 of file BaseClass.h.

312 {
313 typename map<K, V>::iterator p;
314 p=mymap.find(key);
315 if(p != mymap.end()) {
316 p->second = p->second + value;
317 return;
318 }
319 else {
320 msgOut(error_level, "Error in finding a value in a map (no value found)");
321 }
322 }

Referenced by Carbon::addSavedEmissions(), ModelData::deathTimberInventory_incr(), and ModelCoreSpatial::runManagementModule().

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

◆ incrOrAddMapValue()

template<typename K , typename V >
void incrOrAddMapValue ( map< K, V > &  mymap,
const K &  key,
const V &  value 
)
inline

Increments a value stored in a map of the specified value, given the key.

Definition at line 325 of file BaseClass.h.

325 {
326 typename map<K, V>::iterator p;
327 p=mymap.find(key);
328 if(p != mymap.end()) {
329 // We found the key, we gonna add the value..
330 p->second = p->second + value;
331 return;
332 }
333 else {
334 // We didn't find the key, we gonna add it together with the value
335 pair<K,V> myPair(key,value);
336 mymap.insert(myPair);
337 }
338 }

Referenced by ModelData::deathTimberInventory_incrOrAdd(), Carbon::registerDeathBiomass(), Carbon::registerHarvesting(), and ModelCoreSpatial::sumRegionalForData().

Here is the caller graph for this function:

◆ inVector()

template<typename K >
bool inVector ( const K &  element,
const vector< K > &  v 
)
inline

Definition at line 429 of file BaseClass.h.

429 {
430 for(unsigned int i=0; i<v.size(); i++){
431 if(v[i]== element) return true;
432 }
433 return false;
434 }

Referenced by ModelData::getForTypeParents().

Here is the caller graph for this function:

◆ msgOut() [1/3]

void msgOut ( const int &  msgCode_h,
const double &  msg_h,
const bool &  refreshGUI_h = true 
) const

Overloaded function to print the output log.

Overloaded method for the output log:

Parameters
msgCode_hMSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR, MSG_CRITICAL_ERROR
msg_hmessage text (double)
refreshGUI_huse this call to "ping" the GUI (optional, default=true)

Definition at line 78 of file BaseClass.cpp.

78 {
79 msgOut2(msgCode_h, d2s(msg_h), refreshGUI_h);
80
81}
void msgOut2(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h) const
Do the job of the overloaded functions.
Definition BaseClass.cpp:88
Here is the call graph for this function:

◆ msgOut() [2/3]

void msgOut ( const int &  msgCode_h,
const int &  msg_h,
const bool &  refreshGUI_h = true 
) const

Overloaded function to print the output log.

Overloaded method for the output log:

Parameters
msgCode_hMSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR, MSG_CRITICAL_ERROR
msg_hmessage text (int)
refreshGUI_huse this call to "ping" the GUI (optional, default=true)

Definition at line 65 of file BaseClass.cpp.

65 {
66 msgOut2(msgCode_h, i2s(msg_h), refreshGUI_h);
67}
Here is the call graph for this function:

◆ msgOut() [3/3]

void msgOut ( const int &  msgCode_h,
const string &  msg_h,
const bool &  refreshGUI_h = true 
) const

Overloaded function to print the output log.

Overloaded method for the output log:

Parameters
msgCode_hMSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR, MSG_CRITICAL_ERROR
msg_hmessage text (string)
refreshGUI_huse this call to "ping" the GUI (optional, default=true)

Definition at line 50 of file BaseClass.cpp.

50 {
51
52 msgOut2(msgCode_h, msg_h, refreshGUI_h);
53
54}

Referenced by Gis::addLayer(), Layers::addLegendItem(), Gis::addLegendItem(), Layers::addLegendItems(), Carbon::addSavedEmissions(), ModelData::addSetting(), ModelData::applyOverrides(), Gis::applySpatialStochasticValues(), ModelCoreSpatial::assignSpMultiplierPropToVols(), Opt::buildPositionVector(), ModelCoreSpatial::cacheDynamicSettings(), ModelCoreSpatial::cachePixelExogenousData(), ModelCore::cacheSettings(), ModelCoreSpatial::cacheSettings(), Opt::calculateNumberVariablesConstrains(), changeMapValue(), Pixel::changeValue(), LLData::clean(), Output::cleanScenario(), ModelCore::computeCumulativeData(), ModelCoreSpatial::computeCumulativeData(), ModelCore::computeInventary(), ModelCoreSpatial::computeInventary(), Gis::countItems(), Layers::countMyPixels(), ModelData::delDir(), Layers::filterExogenousDataset(), Opt::finalize_solution(), findMap(), Opt::gdt(), Opt::get_starting_point(), Gis::getAllPlots(), Gis::getAllPlotsByValue(), Gis::getAllPlotsByValue(), ModelRegion::getArea(), ModelRegion::getArea(), ModelData::getBaseData(), InputNode::getBoolContent(), Opt::getBoundByIndex(), Opt::getConNumber(), Opt::getConstrainByIndex(), Opt::getConstrainDirectionByIndex(), Carbon::getCumSavedEmissions(), LLData::getData(), Opt::getDomainElements(), InputNode::getDoubleAttributeByName(), Pixel::getDoubleValue(), ModelData::getFilenamesByDir(), ModelData::getForData(), ModelData::getForType(), ModelData::getForTypeCounter(), ModelData::getForTypeParentId(), InputNode::getIntAttributeByName(), Gis::getLayer(), ModelData::getMaxYearUsableDeathTimber(), Pixel::getMyRegion(), InputNode::getNodeByName(), InputNode::getNodesByName(), Output::getOutputFieldDelimiter(), Pixel::getPastRegArea(), Pixel::getPixelsAtDistLevel(), getPos(), ModelData::getProdData(), Gis::getRandomPlotByValue(), ModelData::getRegion(), ModelData::getScenarioIndex(), Sandbox::getSetting(), Pixel::getSpModifier(), Carbon::getStock(), InputNode::getStringAttributeByName(), ModelData::getTable(), ModelData::getTableFromFile(), ModelData::getTimedData(), getType(), ModelRegion::getValue(), ModelData::getVectorBaseData(), Opt::gip(), Opt::gix(), Opt::gix_uncached(), incrMapValue(), Output::initCarbonBalance(), Output::initDebugOutput(), Output::initDebugPixelValues(), Carbon::initialiseDeathBiomassStocks(), Carbon::initialiseProductsStocks(), ModelCoreSpatial::initializePixelArea(), ModelCoreSpatial::initializePixelVolumes(), Gis::initLayers(), ModelCore::initMarketModule(), ModelCoreSpatial::initMarketModule(), Output::initOptimisationLog(), Output::initOutputForestData(), Output::initOutputMaps(), Output::initOutputProductData(), Opt::intermediate_callback(), ModelData::loadInput(), Gis::loadLayersDataFromFile(), normSample(), normSample(), Layers::print(), Gis::printBinMaps(), Output::printCarbonBalance(), Output::printDebugOutput(), Output::printDebugPixelValues(), Gis::printDebugValues(), Output::printDetailedHV(), Output::printForestData(), Gis::printLayers(), Output::printOptLog(), Output::printProductData(), ModelData::regSName2RegId(), Gis::resetLayer(), ModelCoreSpatial::resetPixelValues(), Scheduler::run(), ModelCore::runBiologicalModule(), ModelCoreSpatial::runBiologicalModule(), ModelCoreSpatial::runInitPeriod(), ModelCore::runManagementModule(), ModelCoreSpatial::runManagementModule(), ModelCore::runMarketModule(), ModelCoreSpatial::runMarketModule(), s2b(), s2d(), ModelData::setDefaultForData(), ModelData::setDefaultPathogenRules(), ModelData::setDefaultProdData(), ModelData::setDefaultProductResourceMatrixLink(), ModelData::setDefaultSettings(), ModelData::setForData(), Init::setInitLevel(), Init::setInitLevel1(), Init::setInitLevel6(), Pixel::setPastRegArea(), ModelData::setProdData(), ModelData::setReclassificationRules(), ModelData::setScenarioData(), ModelData::setScenarioSettings(), Gis::setSpace(), ModelData::setTimedData(), InputNode::setWorkingFile(), ModelCoreSpatial::sumRegionalForData(), Pixel::swap(), Gis::unpack(), Opt::unpack(), ModelData::unpackKeyForData(), ModelData::unpackKeyProdData(), Gis::updateImage(), ModelCore::updateMapAreas(), and ModelCoreSpatial::updateMapAreas().

Here is the call graph for this function:

◆ msgOut2()

void msgOut2 ( const int &  msgCode_h,
const string &  msg_h,
const bool &  refreshGUI_h 
) const
private

Do the job of the overloaded functions.

Convenient (private) function to actually do the job of the overloaded functions

Definition at line 88 of file BaseClass.cpp.

88 {
89
90 string prefix;
91 switch (msgCode_h){
92 case MSG_NO_MSG:
93 return;
94 case MSG_DEBUG:
95 prefix="*DEBUG: ";
96 break;
97 case MSG_INFO:
98 prefix="**INFO: ";
99 break;
100 case MSG_WARNING:
101 prefix="**WARNING: ";
102 break;
103 case MSG_ERROR:
104 prefix="***ERROR: ";
105 break;
107 prefix="****CRITICAL ERROR: ";
108 break;
109 default:
110 cerr<<"I got an unknow error code: "<<msgCode_h<<" ("<<msg_h<<")"<<endl;
111 exit(EXIT_FAILURE);
112 }
113
114 string message = prefix+msg_h;
115 if (MTHREAD && MTHREAD->usingGUI()){
116 MTHREAD->msgOut(msgCode_h, message);
117 }
118 else {
119 string totalMsg = prefix+msg_h;
120 cout<< totalMsg <<endl;
121 }
122
123 if(refreshGUI_h) {refreshGUI();}
124
125 //if(msgCode_h==MSG_CRITICAL_ERROR){
126 // if (MTHREAD && MTHREAD->usingGUI()){
127 // throw(2);
128 // }
129 // else {
130 // throw(2);
131 // exit(EXIT_FAILURE);
132 // }
133 //}
134
135 if(msgCode_h==MSG_CRITICAL_ERROR){ // I can't throw an exception for any case, as code would resume from where it has been caught, not from here..
136 throw(msgCode_h);
137 }
138
139}
@ MSG_ERROR
Print an ERROR message, but don't stop the model.
Definition BaseClass.h:61
@ MSG_DEBUG
Print a debug message, normally filtered out.
Definition BaseClass.h:58
@ MSG_WARNING
Print a WARNING message.
Definition BaseClass.h:60
@ MSG_INFO
Print an INFO message.
Definition BaseClass.h:59
@ MSG_NO_MSG
Do not actually output any message.
Definition BaseClass.h:57
void refreshGUI() const
Ping to periodically return the control to the GUI.
void msgOut(const int msgCode_h, const string message_h)

Referenced by msgOut(), msgOut(), and msgOut().

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

◆ normSample() [1/2]

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

It doesn't require the normal_distribution to be passed to it, but due to including MTHREAD its definition can't be placed in the header and hence it can not be templated, so it works only with doubles.

Definition at line 330 of file BaseClass.cpp.

330 {
331 if(minval != NULL && maxval != NULL){
332 if (maxval <= minval){
333 msgOut(MSG_CRITICAL_ERROR,"Error in normSample: the maxvalue is lower than the minvalue");
334 }
335 }
336 for(;;){
337 normal_distribution<double> d(avg,stdev);
338 double c = d(*MTHREAD->gen);
339 if( (minval == NULL || c >= minval) && (maxval == NULL || c <= maxval) ){
340 return c;
341 }
342 }
343 return minval;
344}
std::mt19937 * gen
used in the sampling from normal distribution

Referenced by Gis::applySpatialStochasticValues().

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

◆ normSample() [2/2]

template<typename K >
K normSample ( normal_distribution< K > &  d,
std::mt19937 &  gen,
const K &  minval = NULL,
const K &  maxval = NULL 
) const
inline

Sample from a normal distribution with bounds. Faster (half time) as the normal_distribution is made only once.

Definition at line 443 of file BaseClass.h.

443 {
444 if(minval != NULL && maxval != NULL){
445 if (maxval <= minval){
446 msgOut(MSG_CRITICAL_ERROR,"Error in normSample: the maxvalue is lower than the minvalue");
447 }
448 }
449 for(;;){
450 K c = d(gen);
451 if( (minval == NULL || c >= minval) && (maxval == NULL || c <= maxval) ){
452 return c;
453 }
454 }
455 return minval;
456 }
Here is the call graph for this function:

◆ positionsToContent()

template<typename T >
vector< T > positionsToContent ( const vector< T > &  vector_h,
const vector< int > &  positions 
)
inline

Return a vector of content from a vector and a vector of positions (int)

Definition at line 359 of file BaseClass.h.

359 {
360 vector <T> toReturn;
361 for(uint i=0; i<positions.size(); i++){
362 toReturn.push_back(vector_h.at(positions[i]));
363 }
364 return toReturn;
365 }

Referenced by ModelCoreSpatial::computeInventary().

Here is the caller graph for this function:

◆ refreshGUI()

void refreshGUI ( ) const

Ping to periodically return the control to the GUI.

Definition at line 142 of file BaseClass.cpp.

142 {
143 if (MTHREAD && MTHREAD->usingGUI()){
145 }
146}

Referenced by Gis::applyForestReclassification(), Gis::loadLayersDataFromFile(), msgOut2(), MainProgram::run(), and Gis::updateImage().

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

◆ resetMapValues()

template<typename K , typename V >
void resetMapValues ( map< K, V > &  mymap,
const V &  value 
)
inline

Reset all values stored in a map to the specified one.

Definition at line 341 of file BaseClass.h.

341 {
342 typename map<K, V>::iterator p;
343 for(p=mymap.begin(); p!=mymap.end(); p++) {
344 p->second =value;
345 }
346 }

Referenced by ModelCoreSpatial::runManagementModule().

Here is the caller graph for this function:

◆ s2b() [1/2]

bool s2b ( const string &  string_h) const

string to bool conversion

Includes conversion checks.

Definition at line 208 of file BaseClass.cpp.

208 {
209 if (string_h == "true" || string_h == "vero" || string_h == "TRUE" || string_h == "VRAI" || string_h == "1" || string_h == "True")
210 return true;
211 else if (string_h == "false" || string_h == "falso" || string_h == "FALSE" || string_h == "FAUX" || string_h == "0" || string_h == "" || string_h == "False")
212 return false;
213
214 msgOut(MSG_CRITICAL_ERROR,"Conversion string to bool failed. Some problems with the data? (got\""+string_h+"\")");
215 return true;
216}

Referenced by ModelData::createRegions(), ModelData::getBoolSetting(), ModelData::getBoolVectorSetting(), and s2b().

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

◆ s2b() [2/2]

vector< bool > s2b ( const vector< string > &  string_h) const

string to bool conversion (vector)

Includes conversion checks.

Definition at line 272 of file BaseClass.cpp.

272 {
273 vector <bool> valuesAsBool;
274 for (uint i=0;i<string_h.size();i++){
275 valuesAsBool.push_back(s2b(string_h[i]));
276 }
277 return valuesAsBool;
278}
bool s2b(const string &string_h) const
string to bool conversion
Here is the call graph for this function:

◆ s2d() [1/3]

double s2d ( const string &  string_h) const

string to double conversion

Definition at line 171 of file BaseClass.cpp.

171 {
172 if (string_h == "") return 0.;
173 double valueAsDouble;
174 istringstream totalSString( string_h );
175 totalSString >> valueAsDouble;
176 return valueAsDouble;
177 /*
178 if (string_h == "") return 0.;
179 try {
180 return stod(string_h); // stod want dot as decimal separator in console mode and comma in gui mode. Further the decimal digits left are only 2 !!
181 } catch (...) {
182 if (string_h == "") return 0.;
183 else {
184 msgOut(MSG_CRITICAL_ERROR,"Conversion string to double failed. Some problems with the data? (got\""+string_h+"\")");
185 }
186 }
187 return 0.;
188 */
189}

Referenced by ModelData::getDoubleSetting(), ModelData::getDoubleVectorSetting(), s2d(), s2d(), ModelData::setDefaultForData(), ModelData::setDefaultPathogenRules(), ModelData::setDefaultProdData(), ModelData::setReclassificationRules(), ModelData::setScenarioForData(), ModelData::setScenarioPathogenRules(), and ModelData::setScenarioProdData().

Here is the caller graph for this function:

◆ s2d() [2/3]

double s2d ( const string &  string_h,
const bool &  replaceComma 
) const

string to double conversion

Includes comma to dot conversion if needed.

Definition at line 194 of file BaseClass.cpp.

194 {
195 if(replaceComma){
196 string valueAsString = string_h;
197 // replace commas with dots. This is not needed when directly reading the input nodes as double, as the Qt function to Double does the same.
198 replace(valueAsString.begin(), valueAsString.end(), ',', '.');
199 return s2d(valueAsString);
200 }
201 return s2d(string_h);
202 msgOut(MSG_CRITICAL_ERROR, "debug me please!");
203 return 0.;
204}
double s2d(const string &string_h) const
string to double conversion
Here is the call graph for this function:

◆ s2d() [3/3]

vector< double > s2d ( const vector< string > &  string_h,
const bool &  replaceComma = false 
) const

string to double conversion (vector)

Includes comma to dot conversion if needed.

Definition at line 255 of file BaseClass.cpp.

255 {
256 vector <double> valuesAsDouble;
257 for (uint i=0;i<string_h.size();i++){
258 if(replaceComma){
259 string valueAsString = string_h[i];
260 // replace commas with dots. This is not needed when directly reading the input nodes as double, as the Qt function to Double does the same.
261 replace(valueAsString.begin(), valueAsString.end(), ',', '.');
262 valuesAsDouble.push_back(s2d(valueAsString));
263 } else {
264 valuesAsDouble.push_back(s2d(string_h[i]));
265 }
266 }
267 return valuesAsDouble;
268}

Referenced by s2d().

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

◆ s2i() [1/2]

int s2i ( const string &  string_h) const

string to integer conversion

Definition at line 149 of file BaseClass.cpp.

149 {
150 if (string_h == "") return 0;
151 int valueAsInteger;
152 stringstream ss(string_h);
153 ss >> valueAsInteger;
154 return valueAsInteger;
155 /*
156 // I can't use stoi as of bug in MinGW
157 try {
158 return stoi(string_h);
159 } catch (...) {
160 if (string_h == "") return 0;
161 else {
162 msgOut(MSG_CRITICAL_ERROR,"Conversion string to integer failed. Some problems with the data? (got\""+string_h+"\")");
163 }
164 }
165 return 0;
166 */
167
168}

Referenced by ModelData::createRegions(), ModelData::getIntSetting(), ModelData::getIntVectorSetting(), s2i(), ModelData::setDefaultProductResourceMatrixLink(), ModelData::setDefaultSettings(), ModelData::setForestTypes(), ModelData::setReclassificationRules(), ModelData::setScenarioSettings(), Gis::unpack(), ModelData::unpackKeyForData(), and ModelData::unpackKeyProdData().

Here is the caller graph for this function:

◆ s2i() [2/2]

vector< int > s2i ( const vector< string > &  string_h) const

string to integer conversion (vector)

Definition at line 245 of file BaseClass.cpp.

245 {
246 vector <int> valuesAsInteger;
247 for (uint i=0;i<string_h.size();i++){
248 valuesAsInteger.push_back(s2i(string_h[i]));
249 }
250 return valuesAsInteger;
251}
int s2i(const string &string_h) const
string to integer conversion
Here is the call graph for this function:

◆ stringTo()

template<typename T >
T stringTo ( const std::string &  s) const

Definition at line 348 of file BaseClass.cpp.

348 {
349 std::istringstream iss(s);
350 T x;
351 iss >> x;
352 return x;
353}

◆ tokenize()

void tokenize ( const string &  str,
vector< string > &  tokens,
const string &  delimiter = " " 
) const

Tokenize a string using a delimiter (default is space)

Definition at line 374 of file BaseClass.cpp.

374 {
375 // Skip delimiters at beginning.
376 string::size_type lastPos = str.find_first_not_of(delimiter, 0);
377 // Find first "non-delimiter".
378 string::size_type pos = str.find_first_of(delimiter, lastPos);
379
380 while (string::npos != pos || string::npos != lastPos)
381 {
382 // Found a token, add it to the vector.
383 tokens.push_back(str.substr(lastPos, pos - lastPos));
384 // Skip delimiters. Note the "not_of"
385 lastPos = str.find_first_not_of(delimiter, pos);
386 // Find next "non-delimiter"
387 pos = str.find_first_of(delimiter, lastPos);
388 }
389}

Referenced by Output::cleanScenario().

Here is the caller graph for this function:

◆ toString() [1/2]

template<typename T >
std::string toString ( const T &  x) const

Definition at line 322 of file BaseClass.cpp.

322 {
323 std::ostringstream oss;
324 oss << x;
325 return oss.str();
326}

◆ toString() [2/2]

template<typename T >
string toString ( const T &  x) const

◆ untokenize()

void untokenize ( string &  str,
vector< string > &  tokens,
const string &  delimiter = " " 
) const

Definition at line 392 of file BaseClass.cpp.

392 {
393 // add initial loken in str is not empty
394 if(str != ""){
395 str += delimiter;
396 }
397 for(int i=0;i<tokens.size();i++){
398 str += tokens[i];
399 // don't add final delimiter
400 if(i != (tokens.size()-1)){
401 str += delimiter;
402 }
403 }
404}

◆ vectorToMap()

template<typename K , typename V >
map< K, V > vectorToMap ( const vector< K > &  keys,
const V &  value = 0.0 
)
inline

Returns a map built using the given vector and the given (scalar) value as keys/values pairs.

Definition at line 349 of file BaseClass.h.

349 {
350 map<K,V> returnMap;
351 for(unsigned int i=0; i<keys.size();i++){
352 pair<K,V> apair(keys[i],value);
353 returnMap.insert(apair);
354 }
355 return returnMap;
356 }

Referenced by ModelCoreSpatial::runManagementModule().

Here is the caller graph for this function:

◆ vSum() [1/4]

double vSum ( const vector< double > &  vector_h) const
inline

Definition at line 277 of file BaseClass.h.

277{return accumulate(vector_h.begin(),vector_h.end(),0.);};

◆ vSum() [2/4]

◆ vSum() [3/4]

double vSum ( const vector< vector< double > > &  vector_h) const

Definition at line 365 of file BaseClass.cpp.

365 {
366 double toReturn = 0.0;
367 for(vector < vector<double> >::const_iterator j=vector_h.begin();j!=vector_h.end();++j){
368 toReturn += accumulate(j->begin(),j->end(),0.0);
369 }
370 return toReturn;
371}

◆ vSum() [4/4]

int vSum ( const vector< vector< int > > &  vector_h) const

Definition at line 356 of file BaseClass.cpp.

356 {
357 int toReturn = 0;
358 for(vector < vector<int> >::const_iterator j=vector_h.begin();j!=vector_h.end();++j){
359 toReturn += accumulate(j->begin(),j->end(),0);
360 }
361 return toReturn;
362}

Member Data Documentation

◆ MTHREAD

ThreadManager* MTHREAD
protected

Pointer to the Thread manager.

Through this pointer each derived subclass (the vast maiority of those used on FFSM) can "ask" for sending signals to the GUI, like append the log or modify the map.

Definition at line 467 of file BaseClass.h.

Referenced by Gis::addLayer(), ModelCoreSpatial::allocateHarvesting(), ModelCore::app(), ModelCoreSpatial::app(), Opt::app(), Gis::applyForestReclassification(), Gis::applySpatialStochasticValues(), Gis::applyStochasticRiskAdversion(), ModelCoreSpatial::assignSpMultiplierPropToVols(), BaseClass(), ModelCoreSpatial::cacheDynamicSettings(), ModelCoreSpatial::cachePixelExogenousData(), ModelCore::cacheSettings(), ModelCoreSpatial::cacheSettings(), Carbon::Carbon(), Pixel::changeValue(), Output::commonInit(), ModelCore::computeCumulativeData(), ModelCoreSpatial::computeCumulativeData(), ModelCoreSpatial::computeEconomicBalances(), ModelCore::computeInventary(), ModelCoreSpatial::computeInventary(), Opt::copyInventoryResourses(), Layers::countMyPixels(), ModelData::createRegions(), Opt::eval_constraints(), Opt::get_nlp_info(), ModelData::getAllocableProductIdsFromDeathTimber(), Gis::getAllPlots(), Gis::getAllPlotsByRegion(), ModelRegion::getArea(), ModelRegion::getArea(), ModelData::getAvailableAliveTimber(), ModelData::getBaseData(), ModelData::getBoolSetting(), ModelData::getBoolVectorSetting(), Layers::getCategory(), Layers::getColor(), ModelData::getDoubleSetting(), Pixel::getDoubleValue(), Pixel::getDoubleValue(), ModelData::getDoubleVectorSetting(), ModelData::getIntSetting(), ModelData::getIntVectorSetting(), Pixel::getMultiplier(), Output::getOutputFieldDelimiter(), Pixel::getPathMortality(), Pixel::getPixelsAtDistLevel(), ModelData::getRegionIds(), ModelData::getScenarioIndex(), ModelRegion::getSiblings(), Pixel::getSpModifier(), Pixel::getSTData(), Carbon::getStock(), ModelData::getStringSetting(), ModelData::getStringVectorSetting(), ModelData::getTable(), ModelData::getTableFromFile(), ModelData::getTimedData(), ModelCoreSpatial::getVHaByYear(), Opt::gfd(), ModelCore::gfd(), ModelCoreSpatial::gfd(), Gis::Gis(), ModelCore::gpd(), ModelCoreSpatial::gpd(), Opt::gpd(), Carbon::HWP_eol2energy(), Init::Init(), ModelCoreSpatial::initialiseCarbonModule(), Carbon::initialiseDeathBiomassStocks(), ModelCoreSpatial::initialiseDeathTimber(), Carbon::initialiseEmissionCounters(), Carbon::initialiseProductsStocks(), ModelCoreSpatial::initializePixelArea(), ModelCoreSpatial::initializePixelVolumes(), Gis::initLayers(), Gis::initLayersPixelData(), Output::initOutputForestData(), Layers::Layers(), LLData::LLData(), ModelCoreSpatial::loadExogenousForestLayers(), ModelData::loadInput(), Gis::loadLayersDataFromFile(), MainProgram::MainProgram(), ModelCore::ModelCore(), ModelCoreSpatial::ModelCoreSpatial(), ModelData::ModelData(), ModelRegion::ModelRegion(), msgOut2(), normSample(), Opt::Opt(), Output::Output(), Pixel::Pixel(), Layers::print(), Output::print(), Layers::printBinMap(), Gis::printBinMaps(), Output::printCarbonBalance(), Output::printDebugOutput(), Output::printDebugPixelValues(), Output::printDetailedHV(), Output::printFinalOutput(), Output::printForestData(), Gis::printLayers(), Output::printMaps(), Output::printOptLog(), Output::printProductData(), Layers::randomShuffle(), refreshGUI(), ModelData::regId2RegSName(), ModelCoreSpatial::registerCarbonEvents(), Carbon::registerDeathBiomass(), Carbon::registerHarvesting(), Carbon::registerProducts(), Carbon::registerTransports(), ModelData::regSName2RegId(), ModelCoreSpatial::resetPixelValues(), MainProgram::run(), Scheduler::run(), ModelCore::runBiologicalModule(), ModelCoreSpatial::runBiologicalModule(), ModelCore::runInitPeriod(), ModelCoreSpatial::runInitPeriod(), ModelCore::runManagementModule(), ModelCoreSpatial::runManagementModule(), ModelCore::runMarketModule(), ModelCoreSpatial::runMarketModule(), ModelCore::runSimulationYear(), ModelCoreSpatial::runSimulationYear(), Sandbox::Sandbox(), Scheduler::Scheduler(), ModelData::setDefaultSettings(), Init::setInitLevel1(), Init::setInitLevel3(), Init::setInitLevel5(), Init::setInitLevel6(), ModelRegion::setMyPixels(), ModelData::setOutputDirectory(), ModelData::setScenarioData(), ModelData::setScenarioSettings(), Gis::setSpace(), ModelData::setTimedData(), Opt::sfd(), ModelCore::sfd(), ModelCoreSpatial::sfd(), ModelCore::spd(), ModelCoreSpatial::spd(), Opt::spd(), ModelCoreSpatial::sumRegionalForData(), Gis::updateImage(), ModelCore::updateMapAreas(), ModelCoreSpatial::updateMapAreas(), and ModelCoreSpatial::updateOtherMapData().


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