33 #ifndef BASECLASSBASECLASS_H 34 #define BASECLASSBASECLASS_H 135 #define M_PI 3.1415926535897932384626433832795 139 #define M_LN2 0.69314718055994530941723212145818 143 #define M_LN10 2.3025850929940456840179914546844 148 #define PROD_ALL "PROD_ALL" 151 #define PROD_PRI "PROD_PRI" 154 #define PROD_SEC "PROD_SEC" 157 #define DIAM_ALL "DIAM_ALL" 160 #define DIAM_PROD "DIAM_PROD" 163 #define DIAM_FIRST "DIAM_FIRST_CLASS" 166 #define FT_ALL "FT_ALL" 171 #define LBOUND_MIN -20000000000000000000.0 174 #define UBOUND_MAX 20000000000000000000.0 182 iskey(
int i_h,
string s_h);
184 bool operator == (
const iskey &op2)
const;
185 bool operator != (
const iskey &op2)
const;
186 bool operator < (
const iskey &op2)
const;
187 bool operator > (
const iskey &op2)
const;
188 bool operator <= (
const iskey &op2)
const;
189 bool operator >= (
const iskey &op2)
const;
198 iiskey(
int i_h,
int i2_h,
string s_h);
200 bool operator == (
const iiskey &op2)
const;
201 bool operator != (
const iiskey &op2)
const;
202 bool operator < (
const iiskey &op2)
const;
203 bool operator > (
const iiskey &op2)
const;
204 bool operator <= (
const iiskey &op2)
const;
205 bool operator >= (
const iiskey &op2)
const;
216 iisskey(
int i_h,
int i2_h,
string s_h,
string s2_h);
218 bool filter(
const iisskey & key_h)
const;
219 string print()
const;
220 bool operator == (
const iisskey &op2)
const;
221 bool operator != (
const iisskey &op2)
const;
222 bool operator < (
const iisskey &op2)
const;
223 bool operator > (
const iisskey &op2)
const;
224 bool operator <= (
const iisskey &op2)
const;
225 bool operator >= (
const iisskey &op2)
const;
245 void msgOut(
const int& msgCode_h,
const string& msg_h,
const bool& refreshGUI_h=
true)
const;
246 void msgOut(
const int& msgCode_h,
const int& msg_h,
const bool& refreshGUI_h=
true)
const;
247 void msgOut(
const int& msgCode_h,
const double& msg_h,
const bool& refreshGUI_h=
true)
const;
249 int s2i (
const string& string_h)
const;
250 double s2d (
const string& string_h)
const;
251 double s2d (
const string& string_h,
const bool& replaceComma)
const;
252 bool s2b (
const string& string_h)
const;
257 string i2s (
const int& int_h)
const;
258 string d2s (
const double& double_h)
const;
259 string b2s (
const bool& bool_h)
const;
261 vector<int> s2i (
const vector<string>& string_h)
const;
262 vector<double> s2d (
const vector<string>& string_h,
const bool& replaceComma =
false)
const;
263 vector<bool> s2b (
const vector<string>& string_h)
const;
264 vector<string> i2s (
const vector<int>& int_h)
const;
265 vector<string> d2s (
const vector<double>& double_h)
const;
266 vector<string> b2s (
const vector<bool>& bool_h)
const;
268 int getType(
const string &type_h)
const;
269 void refreshGUI()
const;
272 template<
typename T>
string toString(
const T& x)
const;
273 template<
typename T> T stringTo(
const std::string& s)
const;
276 int vSum(
const vector<int>& vector_h)
const {
return accumulate(vector_h.begin(),vector_h.end(),0);};
277 double vSum(
const vector<double>& vector_h)
const {
return accumulate(vector_h.begin(),vector_h.end(),0.);};
278 int vSum(
const vector< vector <int> >& vector_h)
const;
279 double vSum(
const vector< vector <double> >& vector_h)
const;
282 void tokenize(
const string& str, vector<string>& tokens,
const string& delimiter =
" ")
const;
283 void untokenize(
string &str, vector<string>& tokens,
const string& delimiter =
" ")
const;
286 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{
287 typename map<K, V>::const_iterator p;
289 if(p != mymap.end()) {
293 msgOut(error_level,
"Error in finding a value in a map (no value found)");
294 return notFoundValue;
300 typename map<K, V>::iterator p;
302 if(p != mymap.end()) {
307 msgOut(error_level,
"Error in finding a value in a map (no value found)");
313 typename map<K, V>::iterator p;
315 if(p != mymap.end()) {
316 p->second = p->second + value;
320 msgOut(error_level,
"Error in finding a value in a map (no value found)");
325 template <
typename K,
typename V>
void incrOrAddMapValue(map <K, V> &mymap,
const K& key,
const V& value){
326 typename map<K, V>::iterator p;
328 if(p != mymap.end()) {
330 p->second = p->second + value;
335 pair<K,V> myPair(key,value);
336 mymap.insert(myPair);
341 template <
typename K,
typename V>
void resetMapValues(map <K, V> &mymap,
const V& value){
342 typename map<K, V>::iterator p;
343 for(p=mymap.begin(); p!=mymap.end(); p++) {
349 template <
typename K,
typename V> map <K, V>
vectorToMap(
const vector <K>& keys,
const V& value=0.0){
351 for(
unsigned int i=0; i<keys.size();i++){
352 pair<K,V> apair(keys[i],value);
353 returnMap.insert(apair);
359 template <
typename T> vector <T>
positionsToContent(
const vector <T> & vector_h,
const vector<int> &positions){
361 for(uint i=0; i<positions.size(); i++){
362 toReturn.push_back(vector_h.at(positions[i]));
368 template <
typename V>
void debugMap(
const map <iisskey, V> &mymap){
369 iisskey mykey(NULL,NULL,
"",
"");
370 debugMap(mymap, mykey);
372 template <
typename K,
typename V>
void debugMap(
const map <K, V> &mymap,
const K& key){
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;
383 template <
typename K>
int getMaxPos (
const vector <K> & v){
384 return (minmax_element(v.begin(), v.end()).second - v.begin());
387 template <
typename K>
int getMinPos (
const vector <K> & v){
388 return (minmax_element(v.begin(), v.end()).first - v.begin());
391 template <
typename K> K
getMax(
const vector <K> & v){
392 return *minmax_element(v.begin(), v.end()).second;
395 template <
typename K> K
getMin (
const vector <K> & v){
396 return *minmax_element(v.begin(), v.end()).first;
399 template <
typename K>
double getAvg (
const vector <K> & v){
400 return v.size()==0 ? 0.0 : vSum(v)/ ( (double) v.size() );
408 template <
typename K>
double getSd (
const vector <K> & v,
bool sample=
true){
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();
414 std::for_each (std::begin(v), std::end(v), [&](
const double d) {
415 accum += (d - m) * (d - m);
417 double stdev = sqrt(accum / ( (
double) (v.size()-sampleCorrection)));
422 for(
unsigned int i=0; i<v.size(); i++){
423 if(v[i]== element)
return i;
425 msgOut(msgCode_h,
"Element not found in vector in getPos()");
429 template <
typename K>
bool inVector (
const K & element,
const vector <K> & v){
430 for(
unsigned int i=0; i<v.size(); i++){
431 if(v[i]== element)
return true;
440 double normSample (
const double& avg,
const double& stdev,
const double& minval=NULL,
const double& maxval=NULL)
const;
443 template <
typename K> K
normSample (normal_distribution<K>& d, std::mt19937& gen,
const K& minval=NULL,
const K& maxval=NULL)
const {
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");
451 if( (minval == NULL || c >= minval) && (maxval == NULL || c <= maxval) ){
472 void msgOut2(
const int& msgCode_h,
const string& msg_h,
const bool& refreshGUI_h)
const;
Class to provide a simple integer-integer-string-string key in std maps.
int getPos(const K &element, const vector< K > &v, const int &msgCode_h=MSG_CRITICAL_ERROR)
dataType
Type of data requested.
Print an ERROR message, but don't stop the model.
The required data is for the current year.
Class to provide a simple integer-integer-string key in std maps.
Setting a data request for the init period.
Do not actually output any message.
carbonStocks
Carbon stocks.
The required data is a string.
ThreadManager * MTHREAD
Pointer to the Thread manager.
K getMax(const vector< K > &v)
Returns the value of the maximum element in the vector (the last one in case of multiple equivalent m...
double vSum(const vector< double > &vector_h) const
void resetMapValues(map< K, V > &mymap, const V &value)
Reset all values stored in a map to the specified one.
Output verbosity level none.
Request something that is not region-specific.
Output verbosity level print everything.
The required data is a bool.
Output verbosity level print (also) the maps in ascii grid format.
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)
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 ...
Thread manager. Responsable to manage the main thread and "speak" with the GUI.
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.
Primary products // domain of variables and constrains: primary, secondary, all products or all produ...
int getMaxPos(const vector< K > &v)
Returns the position of the maximum element in the vector (the last one in case of multiple equivalen...
Output verbosity level print aggregated output (e.g. optimisation log)
emissionType
Emission types.
Output verbosity level print (also) detailed output.
Class to provide a simple integer-string key to be used in std maps.
Print an error message and stop the model.
K getMin(const vector< K > &v)
Returns the value of the minimum element in the vector (the first one in case of multiple equivalent ...
Output verbosity level print (also) binary (png) maps.
Secondary products over r2 couple regions (in-country commercial flows)
void debugMap(const map< iisskey, V > &mymap)
Debug a map.
Flow from forest operations.
There is an error in retrieving the data.
int vSum(const vector< int > &vector_h) const
Invetoried biomass (live and death tree logs)
Extra biomass (soils, branches..)
domains
Domain associated to a variable or a constrain in the optimisation of the market module.
Print a debug message, normally filtered out.
bool inVector(const K &element, const vector< K > &v)
Primary products over r2 couple regions (in-country commercial flows)
The required data is a double.
Request the (scenario specific) NO VALUE to be returned.
int getMinPos(const vector< K > &v)
Returns the position of the minimum element in the vector (the first one in case of multiple equivale...
Scalar variable (not used)
double getSd(const vector< K > &v, bool sample=true)
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...
All products over r2 couple regions (in-country commercial flows)
Base class for the regmas application.
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.
void debugMap(const map< K, V > &mymap, const K &key)
All possible combinations of primary products (2^ number of primary products)
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.
dataRequest
A generic enum to deal with data requests.
The required data is an integer.
messageType
Type of message to be printed.
Perform an AVERAGE operation.
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.
outputVerbosity
Verbosity level of the output.
All products (primary+secondary)
double getAvg(const vector< K > &v)
Returns the average of the elements in the vector.
Biomass in forest products (sawns, pannels..)