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

#include <Sandbox.h>

Inheritance diagram for Sandbox:
Collaboration diagram for Sandbox:

Public Member Functions

 Sandbox (ThreadManager *MTHREAD_h)
 
 Sandbox ()
 
 ~Sandbox ()
 
template<class T >
getSetting (string name_h, int type)
 
template<class T >
vector< T > getVectorSetting (string name_h, int type)
 
template<class T >
test2 (const std::string &s)
 
void printAString (string what)
 
vector< TestStructure * > getTestStructure ()
 
void testThreads ()
 
void basicTest ()
 Simple tests that doesn't require anything else (are encapsulated) and so they can be run at the beginning of the program. Normally empty. More...
 
void fullTest ()
 Tests that require a full sandbox object including MTHREAD. Normally empty. More...
 
void testIpopt ()
 
int testAdolc ()
 
void testPartMatching ()
 How to partial matching the key of a map. More...
 
void testPartMatching2 ()
 How to partial matching the key of a map. More...
 
- Public Member Functions inherited from BaseClass
 BaseClass ()
 
 ~BaseClass ()
 
void msgOut (const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
 Overloaded function to print the output log. More...
 
void msgOut (const int &msgCode_h, const int &msg_h, const bool &refreshGUI_h=true) const
 Overloaded function to print the output log. More...
 
void msgOut (const int &msgCode_h, const double &msg_h, const bool &refreshGUI_h=true) const
 Overloaded function to print the output log. More...
 
int s2i (const string &string_h) const
 string to integer conversion More...
 
double s2d (const string &string_h) const
 string to double conversion More...
 
double s2d (const string &string_h, const bool &replaceComma) const
 string to double conversion More...
 
bool s2b (const string &string_h) const
 string to bool conversion More...
 
string i2s (const int &int_h) const
 integer to string conversion More...
 
string d2s (const double &double_h) const
 double to string conversion More...
 
string b2s (const bool &bool_h) const
 bool to string conversion More...
 
vector< int > s2i (const vector< string > &string_h) const
 string to integer conversion (vector) More...
 
vector< double > s2d (const vector< string > &string_h, const bool &replaceComma=false) const
 string to double conversion (vector) More...
 
vector< bool > s2b (const vector< string > &string_h) const
 string to bool conversion (vector) More...
 
vector< string > i2s (const vector< int > &int_h) const
 integer to string conversion (vector) More...
 
vector< string > d2s (const vector< double > &double_h) const
 double to string conversion (vector) More...
 
vector< string > b2s (const vector< bool > &bool_h) const
 bool to string conversion (vector) More...
 
int getType (const string &type_h) const
 Return a type according to enum TYPE_* from a string (eg: "string" -> TYPE_STRING (2)) More...
 
void refreshGUI () const
 Ping to periodically return the control to the GUI. More...
 
template<typename T >
string toString (const T &x) const
 
template<typename T >
stringTo (const std::string &s) const
 
int vSum (const vector< int > &vector_h) const
 
double vSum (const vector< double > &vector_h) const
 
int vSum (const vector< vector< int > > &vector_h) const
 
double vSum (const vector< vector< double > > &vector_h) const
 
void tokenize (const string &str, vector< string > &tokens, const string &delimiter=" ") const
 Tokenize a string using a delimiter (default is space) More...
 
void untokenize (string &str, vector< string > &tokens, const string &delimiter=" ") const
 
template<typename K , typename V >
findMap (const map< K, V > &mymap, const K &key, const int &error_level=MSG_CRITICAL_ERROR, const V &notFoundValue=numeric_limits< V >::min()) const
 Lookup a map for a value. Return the value starting from the key. More...
 
template<typename K , typename V >
void changeMapValue (map< K, V > &mymap, const K &key, const V &value, const int &error_level=MSG_CRITICAL_ERROR)
 Change the value stored in a map given the key and the new value. More...
 
template<typename K , typename V >
void incrMapValue (map< K, V > &mymap, const K &key, const V &value, const int &error_level=MSG_CRITICAL_ERROR)
 Increments a value stored in a map of the specified value, given the key. More...
 
template<typename K , typename V >
void incrOrAddMapValue (map< K, V > &mymap, const K &key, const V &value)
 Increments a value stored in a map of the specified value, given the key. More...
 
template<typename K , typename V >
void resetMapValues (map< K, V > &mymap, const V &value)
 Reset all values stored in a map to the specified one. More...
 
template<typename K , typename V >
map< K, V > vectorToMap (const vector< K > &keys, const V &value=0.0)
 Returns a map built using the given vector and the given (scalar) value as keys/values pairs. More...
 
template<typename T >
vector< T > positionsToContent (const vector< T > &vector_h, const vector< int > &positions)
 Return a vector of content from a vector and a vector of positions (int) More...
 
template<typename V >
void debugMap (const map< iisskey, V > &mymap)
 Debug a map. More...
 
template<typename K , typename V >
void debugMap (const map< K, V > &mymap, const K &key)
 
template<typename K >
int getMaxPos (const vector< K > &v)
 Returns the position of the maximum element in the vector (the last one in case of multiple equivalent maxima) More...
 
template<typename K >
int getMinPos (const vector< K > &v)
 Returns the position of the minimum element in the vector (the first one in case of multiple equivalent minima) More...
 
template<typename K >
getMax (const vector< K > &v)
 Returns the value of the maximum element in the vector (the last one in case of multiple equivalent maxima) More...
 
template<typename K >
getMin (const vector< K > &v)
 Returns the value of the minimum element in the vector (the first one in case of multiple equivalent minima) More...
 
template<typename K >
double getAvg (const vector< K > &v)
 Returns the average of the elements in the vector. More...
 
template<typename K >
double getSd (const vector< K > &v, bool sample=true)
 
template<typename K >
int getPos (const K &element, const vector< K > &v, const int &msgCode_h=MSG_CRITICAL_ERROR)
 
template<typename K >
bool inVector (const K &element, const vector< K > &v)
 
double normSample (const double &avg, const double &stdev, const double &minval=NULL, const double &maxval=NULL) const
 Sample from a normal distribution with bounds. Slower (double time, but still you see the diff only after milion of loops). More...
 
template<typename K >
normSample (normal_distribution< K > &d, std::mt19937 &gen, const K &minval=NULL, const K &maxval=NULL) const
 Sample from a normal distribution with bounds. Faster (half time) as the normal_distribution is made only once. More...
 
template<typename T >
std::string toString (const T &x) const
 

Private Member Functions

void testSearchMap (const map< string, string > &map, const string &search_for)
 
void testSearchMap2 (const map< string, string > &map_h, const string &search_for)
 

Private Attributes

vector< TestStructuretestVector
 

Additional Inherited Members

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

Detailed Description

Definition at line 40 of file Sandbox.h.

Constructor & Destructor Documentation

Sandbox ( ThreadManager MTHREAD_h)

Definition at line 81 of file Sandbox.cpp.

81  {
82  MTHREAD=MTHREAD_h;
83 }
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
Sandbox ( )

Definition at line 85 of file Sandbox.cpp.

85  {
86 
87 }
~Sandbox ( )

Definition at line 90 of file Sandbox.cpp.

90  {
91 
92 }

Member Function Documentation

void basicTest ( )

Simple tests that doesn't require anything else (are encapsulated) and so they can be run at the beginning of the program. Normally empty.

Definition at line 132 of file Sandbox.cpp.

Referenced by main(), and printAString().

132  {
133 
134  /*
135  // Checking integer division
136 
137  int a = 19;
138  int b = 5;
139  int c = a/b;
140  int d = a%b;
141  cout << a << " - " << b << " - " << c << " - " << d << endl;
142  exit(0);
143  */
144 
145  /*
146  // Testing initializating a matrix with fixed values in C++11
147  //vector< vector<double> > deltaAreas(fTypes.size()+1, vector<double>(fTypes.size()+1,5));
148  vector< vector<double> > deltaAreas(3, vector<double>(5,4));
149  for (uint i=0;i<3;i++){
150  for (uint j=0;j<5;j++){
151  cout << deltaAreas.at(i).at(j) << "\t";
152  }
153  cout << endl;
154  }
155  exit(1);
156  */
157 
158  /*
159  // Testing map of generic vector of strings
160  //map<vector<string>,double> testMap;
161  map<tr1::array<string, 3>,double> testMap;
162 
163  //vector<string> k1 = {"aa","aa","aa"};
164  tr1::array<string, 3> k1 = {"aa","aa","aa"};
165  double v1 = 1;
166  double v1b = 3;
167  //vector<string> k2 = {"aa","bb","aa"};
168  tr1::array<string, 3> k2 = {"aa","bb","aa"};
169  double v2 = 2;
170  incrOrAddMapValue(testMap, k1, v1);
171  incrOrAddMapValue(testMap, k2, v2);
172  incrOrAddMapValue(testMap, k1, v1b);
173  double debug = findMap(testMap, k1);
174  cout << debug << endl;
175  double debug2 = findMap(testMap, k2);
176  cout << debug2 << endl;
177  exit(1);
178  */
179 
180 
181  /*
182  // Testing debugging a map
183  iisskey k1(2007,11021,"broadL_HighF","15");
184  iisskey k2(2007,11021,"broadL_HighF","30");
185  iisskey k3(2007,11021,"con_HighF","15");
186  iisskey k4(2007,11022,"broadL_HighF","15");
187  iisskey k5(2008,11021,"broadL_HighF","15");
188 
189  // Testing the new changeMapValue(), incrMapValue(), resetMapValues(), incrOrAddMapValue(map, key, value) and vectorToMap() funcions
190  map<iisskey,double> testMap;
191  pair<iisskey,double> pair1(k1,1.1);
192  pair<iisskey,double> pair2(k2,1.2);
193  pair<iisskey,double> pair3(k3,1.3);
194  pair<iisskey,double> pair4(k4,1.4);
195  pair<iisskey,double> pair5(k5,1.5);
196  testMap.insert(pair1);
197  testMap.insert(pair2);
198  testMap.insert(pair3);
199  testMap.insert(pair4);
200  testMap.insert(pair5);
201  debugMap(testMap,iisskey(NULL,NULL,"",""));
202  debugMap(testMap,iisskey(2007,NULL,"con_HighF",""));
203  exit(0);
204  */
205 
206 
207 
208 
209  /*
210  // Testing standard deviation algorithm, as from http://stackoverflow.com/questions/7616511/calculate-mean-and-standard-deviation-from-a-vector-of-samples-in-c-using-boos
211  vector<double> v;
212  v.push_back(3.0);
213  v.push_back(2.0);
214  v.push_back(5.0);
215  v.push_back(4.0);
216  double sum = std::accumulate(std::begin(v), std::end(v), 0.0);
217  double m = sum / v.size();
218  double accum = 0.0;
219  std::for_each (std::begin(v), std::end(v), [&](const double d) {
220  accum += (d - m) * (d - m);
221  });
222  double stdev = sqrt(accum / (v.size()-1));
223  cout << stdev << endl;
224  double sd2 = getSd(v);
225  double sd3 = getSd(v,false);
226  cout << sd2 << endl;
227  cout << sd3 << endl;
228  exit(0);
229  */
230 
231  /*
232  // Testing tokenize, untokenize functions
233  vector<string> istrings;
234  istrings.push_back("Questo");
235  istrings.push_back("cielo");
236  istrings.push_back("è");
237  istrings.push_back("sempre");
238  istrings.push_back("più");
239  istrings.push_back("blu.");
240  string delimiter = " . ";
241 
242  string fullstring="";
243  vector<string> ostrings;
244  untokenize(fullstring, istrings, delimiter);
245  cout << fullstring << endl;
246 
247  fullstring += delimiter;
248  cout << fullstring << endl;
249 
250  tokenize(fullstring, ostrings, delimiter);
251  for (uint i=0;i<ostrings.size();i++){
252  cout << ostrings[i] << endl;
253  }
254  exit(0);
255  */
256 
257 
258  /*
259  // Testing FlopC++
260  // For a single file compile as:
261  // -- two passages:
262  // g++ -O3 -I /usr/include/coin -DFLOPCPP_BUILD `PKG_CONFIG_PATH=/usr/lib64/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig: pkg-config --libs flopcpp osi-cbc osi-clp` transport.cpp -c -o transport.o
263  // g++ -o transport2 transport.o -Wl,-rpath,'$ORIGIN' -L . -DFLOPCPP_BUILD `PKG_CONFIG_PATH=/usr/lib64/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig: pkg-config --libs flopcpp osi-cbc osi-clp`
264  // -- single passage:
265  // g++ -O3 -I /usr/include/coin transport.cpp -DFLOPCPP_BUILD `PKG_CONFIG_PATH=/usr/lib64/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig: pkg-config --libs flopcpp osi-cbc osi-clp` -o transport3
266 
267  MP_model::getDefaultModel().setSolver(new OsiClpSolverInterface);
268  //MP_model::getDefaultModel().setSolver(new OsiCbcSolverInterface);
269  enum {seattle, sandiego, numS};
270  enum {newyork, chicago, topeka,numD};
271 
272  MP_set S(numS); // Sources
273  MP_set D(numD); // Destinations
274  MP_subset<2> Link(S,D); // Transportation links (sparse subset of S*D)
275 
276  Link.insert(seattle,newyork);
277  Link.insert(seattle,chicago);
278  Link.insert(sandiego,chicago);
279  Link.insert(sandiego,topeka);
280 
281  MP_data SUPPLY(S);
282  MP_data DEMAND(D);
283 
284  SUPPLY(seattle)=350; SUPPLY(sandiego)=600;
285  DEMAND(newyork)=325; DEMAND(chicago)=300; DEMAND(topeka)=275;
286 
287  MP_data COST(Link);
288 
289  COST(Link(seattle,newyork)) = 2.5;
290  COST(Link(seattle,chicago)) = 1.7;
291  COST(Link(sandiego,chicago))= 1.8;
292  COST(Link(sandiego,topeka)) = 1.4;
293 
294  COST(Link) = 90 * COST(Link) / 1000.0;
295 
296  MP_variable x(Link);
297  x.display("...");
298 
299  MP_constraint supply(S);
300  MP_constraint demand(D);
301 
302  supply.display("...");
303 
304  supply(S) = sum( Link(S,D), x(Link) ) <= SUPPLY(S);
305  demand(D) = sum( Link(S,D), x(Link) ) >= DEMAND(D);
306 
307  cout<<"Here"<<endl;
308 
309  minimize( sum(Link, COST(Link)*x(Link)) );
310  assert(MP_model::getDefaultModel()->getNumRows()==5);
311  assert(MP_model::getDefaultModel()->getNumCols()==4);
312  assert(MP_model::getDefaultModel()->getNumElements()==8);
313  assert(MP_model::getDefaultModel()->getObjValue()>=156.14 && MP_model::getDefaultModel()->getObjValue()<=156.16);
314 
315  x.display("Optimal solution:");
316  supply.display("Supply dual solution");
317  cout<<"Test transport passed."<<endl;
318  */
319 
320 
321 
322  /*
323  // Testing limits for 0
324  double test = DBL_MIN;
325  cout << test << endl;
326  test = numeric_limits<double>::min();
327  cout << test << endl;
328  exit(0);
329  */
330 
331 
332  /*
333  // Testing getMaxPos()
334  vector<double> test {7,2,6,4,7,2,5,7,2};
335  double maxpos = getMaxPos(test);
336  double maxvalue = getMax(test);
337  double minpos = getMinPos(test);
338  double minvalue = getMin(test);
339  //double maxpos = testB();
340  cout << "maxpos: " << maxpos << endl;
341  cout << "maxvalue: " << maxvalue << endl;
342  cout << "minpos: " << minpos << endl;
343  cout << "minvalue: " << minvalue << endl;
344  exit(0);
345  */
346 
347 
348  /*
349  //This was in ModelData::debug():
350  // ********** START DEBUG CODE....... ************
351  double ddebuga=0; //20080209
352  uint idebuga=0;
353  double ddebugb=0; //20080209
354  uint idebugb=0;
355  double ddebugc=0; //20080209
356  uint idebugc=0;
357  double debugmin = 0;
358  double debugmax = 1000;
359  for (uint q=0;q<10000;q++){
360  ddebuga += debugmin + ( (double)rand() / ((double)(RAND_MAX)+(double)(1)) )*(debugmax-debugmin+1);
361  ddebugb += debugmin + ( (double)rand() / ((double)(RAND_MAX)+(double)(1)) )*(debugmax-debugmin+1);
362  ddebugc += debugmin + ( (double)rand() / ((double)(RAND_MAX)+(double)(1)) )*(debugmax-debugmin+1);
363  }
364  idebuga = ddebuga;
365  idebugb = ddebugb;
366  idebugc = ddebugc;
367  cout << "idebuga: "<<idebuga<<endl;
368  cout << "idebugb: "<<idebugb<<endl;
369  cout << "idebugc: "<<idebugc<<endl;
370  throw 2;
371  // ******** .....END DEBUG CODE *******************
372  */
373 
374  /*
375  // Testing the new iskey class
376  iskey op1(2100,"test");
377  iskey op2(2100,"test");
378  iskey op3(2101,"test");
379  iskey op4(2101,"tgst");
380  iskey op5(2101,"tb");
381  iskey op6(2101,"testa");
382  if(op1 == op2){
383  cout << "op1 and op2 are equal" << endl;
384  }
385  if(op1 == op3){
386  cout << "op1 and op3 are equal" << endl;
387  }
388  if(op6 > op3) cout << "test3 passed" << endl;
389  if(op5 < op3) cout << "test4 passed" << endl;
390  if(op6 >= op3) cout << "test5 passed" << endl;
391  if(op6 != op3) cout << "test6 passed" << endl;
392  if(op4 <= op3) cout << "test7 passed that it shoudn't" << endl;
393  exit(0);
394  */
395 
396  /*
397  // Testing the new changeMapValue(), incrMapValue(), resetMapValues(), incrOrAddMapValue(map, key, value) and vectorToMap() funcions
398  map<int,double> testMap;
399  for (uint i=0;i<5;i++){
400  pair<int,double> mypair(i,i*2.5);
401  testMap.insert(mypair);
402  }
403  double result = findMap(testMap,3,MSG_NO_MSG);
404  double result2 = findMap(testMap,1,MSG_ERROR);
405  double result3 = findMap(testMap,7,MSG_DEBUG);
406  cout << findMap(testMap,3,MSG_NO_MSG)<< endl;
407  changeMapValue(testMap,3,200.0,MSG_ERROR);
408  cout << findMap(testMap,3,MSG_NO_MSG)<< endl;
409  incrMapValue(testMap,3,5.0,MSG_ERROR);
410  cout << findMap(testMap,3,MSG_NO_MSG)<< endl;
411  incrOrAddMapValue(testMap, 3, 200.0);
412  cout << findMap(testMap,3,MSG_NO_MSG)<< endl;
413  incrOrAddMapValue(testMap, 10, 100.0);
414  cout << findMap(testMap,10,MSG_NO_MSG)<< endl;
415  cout << "done" << endl;
416 
417  vector<string> mykeys;
418  mykeys.push_back("andrea");
419  mykeys.push_back("antonello");
420  mykeys.push_back("paolo");
421  map<string,double> mymap = vectorToMap(mykeys,15.0);
422  string searchkey;
423  searchkey = "andrea";
424  cout << findMap(mymap,searchkey,MSG_DEBUG)<< endl;
425  resetMapValues(mymap,32.0);
426  cout << findMap(mymap,searchkey,MSG_DEBUG)<< endl;
427  exit(0);
428  */
429 
430 
431 
432  /*
433  // -------------------------------------------------------------------
434  // Sampling from uniform distribution with local random seed
435  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
436 
437  //this code sample from a uniform distribution. In this case also the seed is reinitialisated, but it it valid only locally: the rest of the program run with the same seed
438 
439  std::random_device rd;
440  std::mt19937 gen(rd());
441  std::uniform_int_distribution<> dis(1, 6);
442 
443  for (int n=0; n<10; ++n)
444  std::cout << dis(gen) << ' ';
445  std::cout << '\n';
446  exit(0);
447  */
448 
449 
450 
451  /*
452  // -------------------------------------------------------------------
453  // Testing how to get all elements in a map by substrings
454  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
455  map <string,double> values;
456  pair <string,double> val1("AAAAAA",1);
457  pair <string,double> val2("AAABBB",2);
458  pair <string,double> val3("BBBAAA",3);
459  pair <string,double> val4("BBBBBB",4);
460  pair <string,double> val5("CCCAAA",5);
461  pair <string,double> val6("C",6);
462  pair <string,double> val7("BBB",7);
463 
464  values.insert(val1);
465  values.insert(val2);
466  values.insert(val3);
467  values.insert(val4);
468  values.insert(val5);
469  values.insert(val6);
470  values.insert(val7);
471 
472  cout << "Printing whole map" << endl;
473  for (std::map<string,double>::iterator it=values.begin(); it!=values.end(); ++it)
474  std::cout << it->first << " => " << it->second << '\n';
475 
476  string search_for = "BBB";
477 
478  cout << "Using lower bound " << endl;
479  for (std::map<string,double>::iterator it=values.lower_bound(search_for); it!=values.end(); ++it)
480  std::cout << it->first << " => " << it->second << '\n';
481  cout << "Using upper bound " << endl;
482  for (std::map<string,double>::iterator it=values.upper_bound(search_for); it!=values.end(); ++it)
483  std::cout << it->first << " => " << it->second << '\n';
484 
485  cout << "Printing only substrings " << endl;
486  for (std::map<string,double>::iterator it=values.lower_bound(search_for); it!=values.end(); ++it){
487  string key = it->first;
488  if (key.compare(0, search_for.size(), search_for) == 0){
489  std::cout << it->first << " => " << it->second << '\n';
490  }
491  }
492 
493 
494  exit(0);
495  */
496 
497  /*
498  // testing findMap
499  map<int,double> testMap;
500  for (uint i=0;i<5;i++){
501  pair<int,double> mypair(i,i*2.5);
502  testMap.insert(mypair);
503  }
504  double result = findMap(testMap,3,MSG_NO_MSG);
505  double result2 = findMap(testMap,1,MSG_ERROR);
506  double result3 = findMap(testMap,7,MSG_DEBUG);
507  cout << "Done" << endl;
508  map<int, vector <double> > testMap2;
509  for (uint i=0;i<5;i++){
510  vector <double> myvector;
511  for(uint j=0;j<10;j++) {
512  myvector.push_back(i*100+j);
513  }
514  pair<int,vector <double> > mypair2(i,myvector);
515  testMap2.insert(mypair2);
516  }
517  vector <double> resultb = findMap(testMap2,3,MSG_NO_MSG);
518  vector <double> resultb2 = findMap(testMap2,1,MSG_ERROR);
519  vector <double> resultb3 = findMap(testMap2,7);
520  cout << "Done2" << endl;
521  exit(1);
522  */
523 
524 
525 
526  /*
527  // Testing vSum
528  vector <int> ivector(5,5);
529  vector <double> dvector(5,1.5);
530  vector < vector <int> > ivector2;
531  vector <vector <double > > dvector2;
532 
533 
534  for(uint i=0;i<5;i++){
535  ivector2.push_back(ivector);
536  dvector2.push_back(dvector);
537  }
538 
539  int iSum = vSum(ivector);
540  int iSum2 = vSum(ivector2[2]);
541  double dSum = vSum(dvector);
542  double dSum2 = vSum(dvector2[1]);
543  int iSum3 = vSum(ivector2);
544  double dSum3 = vSum(dvector2);
545 
546  cout << "hi there" << endl;
547  */
548 
549  /*
550  // Testing Eigen
551  using Eigen::MatrixXd;
552  MatrixXd m(2,2);
553  m(0,0) = 4;
554  m(1,0) = 2.5;
555  m(0,1) = -1;
556  m(1,1) = m(1,0) + m(0,1);
557  std::cout << m << std::endl;
558  exit(0);
559  */
560 
561  /*
562  // Test on two different type of partial matching over map values
563  testPartMatching2();
564  testPartMatching();
565  */
566 
567  /*
568  // -------------------------------------------------------------------
569  // Testing how to erase elements from a vector according to conditions
570  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
571 
572  vector<string> myvector;
573  myvector.push_back("a");
574  myvector.push_back("b");
575  myvector.push_back("c");
576  myvector.push_back("d");
577  myvector.push_back("e");
578 
579  for (uint i=0; i<myvector.size();i++){
580  cout << "i:" << i << " myvector[i]: " << myvector[i] << endl;
581  if(myvector[i]== "c" || myvector[i]=="d"){
582  cout << " -- TBR: " << "i:" << i << " myvector[i]: " << myvector[i] << endl;
583  myvector.erase (myvector.begin()+i);
584  i--;
585  }
586  }
587 
588  cout << "Myvector now contains:" << endl;
589  for (int i=0; i<myvector.size(); i++) {
590  cout << "i: " << i << " myvector[i]: " << myvector[i] << endl;
591  }
592  exit (0);
593  */
594 
595 
596 }

Here is the caller graph for this function:

void fullTest ( )

Tests that require a full sandbox object including MTHREAD. Normally empty.

Definition at line 599 of file Sandbox.cpp.

Referenced by printAString(), and Init::setInitLevel1().

599  {
600 
601  /*
602  // Testing adfditional Mortality..
603  Pixel* px = MTHREAD->GIS->getPixel(8967);
604  double myAddMortality = px->getSTData("additionalMortality", "", 2013, "", 0.0);
605  cout << "Additional mortality: " << myAddMortality <<endl;
606  exit(0);
607  */
608 
609  /*
610  Pixel* px = MTHREAD->GIS->getPixel(8967);
611  double myAddMortality;
612  myAddMortality = px->getSTData("test", "broadL_highF", 2012, "50", 0.0);
613  cout << "test 2012: " << myAddMortality <<endl;
614  myAddMortality = px->getSTData("test", "broadL_highF", 2013, "50", 0.0);
615  cout << "test 2013: " << myAddMortality <<endl;
616  myAddMortality = px->getSTData("test", "broadL_highF", 2014, "50", 0.0);
617  cout << "test 2014: " << myAddMortality <<endl;
618  myAddMortality = px->getSTData("test", "broadL_highF", 2015, "50", 0.0);
619  cout << "test 2015: " << myAddMortality <<endl;
620  myAddMortality = px->getSTData("test", "broadL_highF", 2016, "50", 0.0);
621  cout << "test 2016: " << myAddMortality <<endl;
622  myAddMortality = px->getSTData("test", "broadL_highF", 2017, "50", 0.0);
623  cout << "test 2017: " << myAddMortality <<endl;
624  exit(0);
625  */
626 
627  /*
628  // checking that the overriding works also for secondary dimension
629  // yep, it works!! ;-)
630  //ct 11003 beechRoundW 11001 69.71 100
631  double ct_11003_11002_beech = MTHREAD->MD->getProdData("ct",11003,"beechRoundW",2013,"11002");
632  double ct_11003_11001_beech = MTHREAD->MD->getProdData("ct",11003,"beechRoundW",2013,"11001");
633  double ct_11003_11002_hardW = MTHREAD->MD->getProdData("ct",11003,"hardWRoundW",2013,"11002");
634  double ct_11003_11001_hardW = MTHREAD->MD->getProdData("ct",11003,"hardWRoundW",2013,"11001");
635  exit(1);
636  */
637 
638  /*
639  // getting x,y of the pixel with sawmill in the TIGA project
640  Pixel* px = MTHREAD->GIS->getPixel(8967);
641  int x = px->getX();
642  int y = px->getY();
643  cout << "(X,Y) of pixel 8967: " << x << "\t" << y << endl;
644  px = MTHREAD->GIS->getPixel(0);
645  x = px->getX();
646  y = px->getY();
647  cout << "(X,Y) of pixel 0: " << x << "\t" << y <<endl;
648  exit(1);
649  */
650 
651 /*
652  // Testing overriding of just a product/region if it works
653  // Perfect.. the override works even just setting one specific ft/region value !! :-)
654  double ad = MTHREAD->MD->getProdData("additionalDemand",11000,"fuelW",2014); // this should be 0.004
655  double adt = MTHREAD->MD->getProdData("additionalDemand",11001,"fuelW",2014);
656  double adr = MTHREAD->MD->getProdData("additionalDemand",11002,"fuelW",2014);
657  double adp = MTHREAD->MD->getProdData("additionalDemand",11002,"hardWSawnW",2014);
658  cout << "additional demand test:" << endl;
659  cout << ad << "\t" << adt << "\t" << adr << "\t" << adp << endl;
660  //exit(1);
661  */
662 
663 /*
664  // Testing (again, for the TIGA project) the availalibily coefficient of Hetre
665  Pixel* px = MTHREAD->GIS->getPixel(32,30);
666  double ac = px->getSTData("avalCoef","Fut_Hetre",2013);
667  double act1 = px->getSTData("avalCoef","Fut_Hetre",2010);
668  double act2 = px->getSTData("avalCoef","Fut_Hetre",2014);
669  double act3 = px->getSTData("avalCoef","Fut_Hetre",2020);
670  double acft = px->getSTData("avalCoef","Fut_Feu",2013);
671  cout << "availability coefficient test:" << endl;
672  cout << ac << "\t" << act1 << "\t" << act2 << "\t" << act3 << "\t" << acft << endl;
673  exit(1);
674  */
675 
676  /*
677  // Testing picking up a national level variable defined only at national level. This may raise a segfault ?
678  //double debug = MTHREAD->MD->getProdData("carbonPrice",11000,"",2007);
679  cout << debug << endl;
680  exit(1);
681  */
682 
683  /*
684  // Testing getTableFromFile() function
685  LLData debug = MTHREAD->MD->getTableFromFile("debug", "scenarios/debug.csv");
686  exit(1);
687  */
688 
689 
690  /*
691  // Testing regional overriding in the new getBaseData() function
692  double mr11061 = MTHREAD->MD->getDoubleSetting("mr",DATA_NOW,11061);
693  double mr11042 = MTHREAD->MD->getDoubleSetting("mr",DATA_NOW,11042);
694  double mr = MTHREAD->MD->getDoubleSetting("mr",DATA_NOW);
695  // this should give critical error:
696  double mr5 = MTHREAD->MD->getDoubleSetting("mr",DATA_NOW,5);
697  exit(1);
698  */
699 
700  /*
701  // Testing the new getSTData() function
702  cout << "Starting test" << endl;
703  Pixel* px = MTHREAD->GIS->getPixel(32,30);
704  cout << "got pixel" << endl;
705  //double avalCoef = px->getMultiplier("avalCoefTest", "con_highF", 2007);
706  double avalCoef = px->getSTData("avalCoef","broadL_highF",2008);
707  cout << avalCoef << endl;
708  exit(1);
709  */
710 
711 
712  /*
713  // Testing shareMortalityUsableTimber call for a specific forest type and at the opposite with a null forest type
714  // to see if gfd() expands as expected
715 
716  double test1 = MTHREAD->MD->getForData("shareMortalityUsableTimber",11041,"","",2016);
717  cout << "test1: " << test1 << endl;
718  exit(1);
719  */
720 
721  /*
722  //testing supply_fromForestShare
723  double test = MTHREAD->MD->getProdData("supply_fromForestShare",11042,"hardWRoundW",2006);
724  cout << test << endl;
725  exit(1);
726  */
727 
728  /*
729  // Testing getSiblings() ok
730  ModelRegion* reg1 = MTHREAD->MD->getRegion(11042);
731  vector <ModelRegion*> siblings = reg1->getSiblings();
732  for(uint i=0;i<siblings.size();i++){
733  cout << siblings[i]->getRegId() << endl;
734  }
735  exit(1);
736  */
737 
738  /*
739  // Testing if after not found gpd(.) or gfd(.) we always have a negative tempBool.. yes
740  bool debug = true;
741  MTHREAD->MD->setTempBool(true);
742  double test1 = MTHREAD->MD->getForData("vol",11042,"broadL_highF","15");
743  debug = MTHREAD->MD->getTempBool();
744  double test2 = MTHREAD->MD->getForData("fgdfgdfhdfhdfhuk",11042,"broadL_highF","");
745  debug = MTHREAD->MD->getTempBool();
746  debug = true;
747  exit(1);
748  */
749 
750  /*
751  // Testing if asking a value from freeDim when this is not efined what returns
752  // no, if the freeDim is either null or 11000 I can't ask for e.g. 11042, I didn't developed expansion in the freeDim
753  double debug = MTHREAD->MD->getProdData("pol_ctSub",11042,"fuelW",DATA_NOW);
754  cout << debug << endl;
755  exit(1);
756  */
757 
758  /*
759  // Getting forest area by each forest type
760  vector<int> regIds2 = MTHREAD->MD->getRegionIds(2);
761  for(uint r=0;r<regIds2.size();r++){
762  int rId = regIds2[r];
763  ModelRegion* reg = MTHREAD->MD->getRegion(regIds2[r]);
764  vector <string> fTypes= MTHREAD->MD->getForTypeIds();
765  for(uint f=0;f<fTypes.size();f++){
766  string ft = fTypes[f];
767  forType* FT = MTHREAD->MD->getForType(ft);
768  double totalArea = 0.0;
769  vector <Pixel*> rpx = MTHREAD->GIS->getAllPlotsByRegion(regIds2[r]);
770  for (uint p=0;p<rpx.size();p++){
771  Pixel* px = rpx[p];
772  totalArea += px->getDoubleValue (FT->forLayer, true);
773  }
774  cout << rId << "\t" << ft << "\t" << totalArea << endl;
775  }
776  }
777  exit(1);
778  */
779 
780  /*
781  // Testing the new getForTypeParents()function
782  vector<string> parents = MTHREAD->MD->getForTypeParents();
783  for(uint i=0;i<parents.size();i++){
784  vector <string> childIds = MTHREAD->MD->getForTypeChilds(parents[i]);
785  vector <int> childPos = MTHREAD->MD->getForTypeChilds_pos(parents[i]);
786  double debug = 0.0;
787  }
788  */
789 
790  /*
791  // Testing the reg->getArea() functions
792  // Actually this need to be run further later, as pixels doesn't yet have area information
793  vector <string> dClasses = MTHREAD->MD->getStringVectorSetting("dClasses");
794  vector <string> fTypes= MTHREAD->MD->getForTypeIds();
795  ModelRegion* REG = MTHREAD->MD->getRegion(11041);
796  cout << "Total ft area: "<< REG->getArea()<< endl;
797 
798  for(uint j=0;j<fTypes.size();j++){
799  cout << fTypes[j] << "\t" << REG->getArea(fTypes[j]) << "\t" << REG->getArea(j) << endl;
800  }
801  for(uint j=0;j<fTypes.size();j++){
802  cout << fTypes[j] << "\t" << REG->getArea(fTypes[j]) << "\t";
803  for(uint u=0;u<dClasses.size();u++){
804  cout << REG->getArea(j,u) << " ";
805  }
806  cout << endl;
807  }
808  */
809 
810  /*
811  // Testing getForData() function with no forest id specified
812  double vartest= MTHREAD->MD->getForData("forestChangeAreaIncrementsRel",11061,"","",2009);
813  cout << vartest << endl;
814  exit(0);
815  */
816 
817 
818  /*
819  // Testing the decay model - ok, passed
820  double initialValue = 100;
821  double halfLife = 2;
822  double years = 0;
823  double remStock = MTHREAD->CBAL->getRemainingStock(initialValue, halfLife, years); ///< Apply a single exponential decay model to retrieve the remining stock given the initial stock, the half life and the time passed from stock formation.
824  cout << "Remaining stock: " << remStock << endl;
825  years = 1;
826  remStock = MTHREAD->CBAL->getRemainingStock(initialValue, halfLife, years);
827  cout << "Remaining stock: " << remStock << endl;
828  years = 5;
829  remStock = MTHREAD->CBAL->getRemainingStock(initialValue, halfLife, years);
830  cout << "Remaining stock: " << remStock << endl;
831  years =10;
832  remStock = MTHREAD->CBAL->getRemainingStock(initialValue, halfLife, years);
833  cout << "Remaining stock: " << remStock << endl;
834  years = 200;
835  remStock = MTHREAD->CBAL->getRemainingStock(initialValue, halfLife, years);
836  cout << "Remaining stock: " << remStock << endl;
837  */
838 
839  /*
840  // Testing normSample
841  // template <typename K> K normSample (const K& avg, const K& stdev, const K& minval=NULL, const K& maxval=NULL)
842  // template <typename K> K normSample (const normal_distribution<K>& d, const std::mt19937& gen, const K& minval=NULL, const K& maxval=NULL)
843  double avg = 0.8;
844  double stdev = 0.2;
845  double minval = 0.0;
846  double maxval = 1.0;
847  double result;
848 
849  cout << "Starting first method.." << endl;
850  normal_distribution<double> d(avg,stdev);
851  std::mt19937 gen = *MTHREAD->gen;
852  for (uint i=0;i<1000;i++){
853  result = normSample(d, gen, minval, maxval);
854  cout << "Result1: " << result << endl;
855  }
856  cout << "Finished first method and starting second one.." << endl;
857  for (uint i=0;i<1000;i++){
858  result = normSample(avg, stdev, minval, maxval);
859  cout << "Result2: " << result << endl;
860  }
861  cout << "Finished second method."<< endl;
862 
863  exit(0);
864  */
865 
866 
867  //double disttest = MTHREAD->MD->getProdData("dist",11042,"",DATA_NOW,i2s(11061));
868  //cout << disttest << endl;
869  //exit(0);
870 
871 
872  /*double test = MTHREAD->CBAL->getStock(11061, STOCK_INV);
873  //STOCK_INV -> from inventary source and death trees
874  //STOCK_EXTRA -> from inventary source and death trees
875  //STOCK_PRODUCTS -> from products
876  cout << "DONE" << endl;
877  exit(0);
878  */
879 
880  /*
881  // Testing if forestData can uses other arbitrary elements in the diameter field in order to generalise it
882  double test = MTHREAD->MD->getForData("covar",11082,"con_highF","con_highF");
883  MTHREAD->MD->setForData(0.1,"covar",11082,"con_highF","con_highF");
884  MTHREAD->MD->setForData(0.1,"covar",11061,"con_highF","con_highF",DATA_NOW,true);
885  test = MTHREAD->MD->getForData("covar",11082,"con_highF","con_highF");
886  test = MTHREAD->MD->getForData("covar",11061,"con_highF","con_highF");
887  test = MTHREAD->MD->getForData("covar",11082,"con_highF","");
888  cout << test << endl;
889  exit(0);
890  */
891 
892  /*
893  // Testing getProdData for the freeDimension
894  MTHREAD->MD->setProdData(0.4,"rt",11041,"hardWSawnW",DATA_NOW,true,"11061");
895  MTHREAD->MD->setProdData(0.3,"rt",11041,"hardWSawnW",DATA_NOW,true,"11030");
896  MTHREAD->MD->setProdData(0.2,"rt",11041,"hardWSawnX",DATA_NOW,true,"11030");
897  double debug = MTHREAD->MD->getProdData("rt",11041,"hardWSawnW",DATA_NOW,"11061");
898  double debug2 = MTHREAD->MD->getProdData("rt",11041,"hardWSawnW",DATA_NOW);
899  cout << debug << " " << debug2 << endl;
900  exit(0);
901  */
902 
903  /*
904  // Testing api to call generic forest type data, parent/child
905  cout << "Hello world " << endl;
906  cout << MTHREAD->MD->getForData("freq_norm",11041,"broadL","",2040) << endl;
907  MTHREAD->MD->setForData(100,"freq_norm",11041,"broadL","",2040);
908  cout << MTHREAD->MD->getForData("freq_norm",11041,"broadL","",2040) << endl;
909  cout << MTHREAD->MD->getForTypeParentId("broadL_highF")<< endl;
910  cout << MTHREAD->MD->getForTypeParentId("con_highF")<< endl;
911  exit(0);
912  */
913 
914  /*
915  // Testing for each region how far is the average of the multipliers from 1
916  vector<int> regIds = MTHREAD->MD->getRegionIds(2);
917  vector <string> ftypes = MTHREAD->MD->getForTypeIds();
918 
919  cout << "*** Checking how far is the tpMultiplier far from 1 in each region:" << endl;
920  for (int i=0;i< regIds.size();i++){
921  ModelRegion* region = MTHREAD->MD->getRegion(regIds[i]);
922  vector <Pixel*> regpixels = MTHREAD->GIS->getAllPlotsByRegion(regIds[i]);
923  if(regpixels.size()==0) continue;
924  cout << "*** " << region->getRegLName() << ": "<< endl;
925  for(int ft = 0;ft<ftypes.size();ft++){
926  double tot = 0;
927  double avg = 0;
928  for(int j=0;j<regpixels.size();j++){
929  tot += regpixels[j]->getSpModifier(ftypes[ft]);
930  }
931  avg = tot/regpixels.size();
932  cout << ftypes[ft] << ": " << avg << endl;
933  }
934  }
935  exit(0);
936  */
937 
938  /*
939  // Testing the number of plots in the model
940  vector <ModelRegion*> regions = MTHREAD->MD->getAllRegions();
941  int total = 0;
942  cout << "*** Pixels by region:" << endl;
943  for (int i=0;i< regions.size();i++){
944  vector <Pixel*> regpixels = MTHREAD->GIS->getAllPlotsByRegion(*regions[i]);
945  cout << regions[i]->getRegLName() << ": " << regpixels.size() << endl;
946  total += regpixels.size() ;
947  }
948  cout << "** Total: " << total << endl;
949  exit(0);
950  */
951 
952  /*
953  // Testing the new random distributions. Requires the pointer MTHREAD->gen to be initialised,
954  // so this test can't run in basic test.
955  std::normal_distribution<double> d(100000,3); // default any how to double
956  for(int n=0; n<20; ++n) {
957  double x = d(*MTHREAD->gen);
958  int i = round(d(*MTHREAD->gen));
959  cout << i << ';' << 1 << endl;
960  }
961  exit (0);
962  */
963 
964  /*
965  // Testing I have correctly the info about world price !!!
966  // yes, it seems ok here !!!
967  int firstYear = MTHREAD->MD->getIntSetting("initialYear");
968  int initialOptYear= MTHREAD->MD->getIntSetting("initialOptYear");
969  int simulationYears = MTHREAD->MD->getIntSetting("simulationYears");
970  int WL2 = MTHREAD->MD->getIntSetting("worldCodeLev2");
971  vector <string> priProducts = MTHREAD->MD->getStringVectorSetting("priProducts");
972  vector <string> secProducts = MTHREAD->MD->getStringVectorSetting("secProducts");
973  vector <string> allProducts = priProducts;
974  allProducts.insert( allProducts.end(), secProducts.begin(), secProducts.end() );
975 
976  for(uint i=0;i<allProducts.size();i++){
977  for(int y=firstYear; y<initialOptYear+simulationYears; y++){
978  double pw = MTHREAD->MD->getProdData("pl",WL2,allProducts[i],y);
979  cout << allProducts[i] << " " << y << " " << pw << endl;
980  }
981  }
982  exit (0);
983  */
984 
985  /*
986  // testing Pixel::getMultiplier (const string& multiplierName, const string& forName, int year)
987  Pixel* px = MTHREAD->GIS->getPixel(0);
988  double debug1 = px->getMultiplier("tp_multiplier","broadL_highF",2012);
989  double debug2 = px->getMultiplier("tp_multiplier","broadL_highF",2008);
990  double debug3 = px->getMultiplier("tp_multiplier","broadL_highF",2009);
991  double debug4 = px->getMultiplier("tp_multiplier","broadL_highF",2010);
992  double debug5 = px->getMultiplier("mortCoeff_multiplier","broadL_highF",2012);
993  double debug6 = px->getMultiplier("mortCoeff_multiplier","con_copp",2012);
994  double debug7 = px->getMultiplier("blaaaa","broadL_highF",2012);
995 
996  double debug10 = debug1;
997 */
998 
999  /*
1000  // testing reading a directory
1001  string dir = MTHREAD->MD->getBaseDirectory()+MTHREAD->MD->getStringSetting("spatialDataSubfolder");
1002  vector<string> files = vector<string>();
1003 
1004  MTHREAD->MD->getFilenamesByDir (dir,files, ".grd");
1005 
1006  for (unsigned int i = 0;i < files.size();i++) {
1007  cout << files[i] << endl;
1008  }
1009  */
1010 
1011  /*
1012  // testing ModelData:: ModelData::calculateAnnualisedEquivalent(double amount_h, int years_h)
1013  cout << "Value:" << MTHREAD->MD->calculateAnnualisedEquivalent(500.,4) << endl;
1014  cout << "Value:" << MTHREAD->MD->calculateAnnualisedEquivalent(500.,30) << endl;
1015  cout << "Value:" << MTHREAD->MD->calculateAnnualisedEquivalent(107.035040105,10) << endl;
1016  cout << "Value:" << MTHREAD->MD->calculateAnnualisedEquivalent(8.91507,1) << endl;
1017  cout << "Done" << endl;
1018  exit(0);
1019  */
1020 
1021  /*
1022  // testing snprintf
1023  vector <int> myintegers;
1024  vector <double> mydoubles;
1025  char szResult[24];
1026 
1027  myintegers.push_back(1);
1028  myintegers.push_back(202);
1029  myintegers.push_back(3003);
1030  myintegers.push_back(400004);
1031  myintegers.push_back(50000005);
1032  myintegers.push_back(6000000006);
1033  mydoubles.push_back(1.1234567890);
1034  mydoubles.push_back(12345678.9);
1035  mydoubles.push_back(12345678.90123456);
1036  mydoubles.push_back(6000000006.123456789012);
1037  for(uint i=0;i<myintegers.size();i++){
1038  snprintf ( szResult, sizeof(szResult), "%d", myintegers[i] ); // "safe" version
1039  cout << "int/string: " << myintegers[i] << " / " << szResult << endl;
1040  }
1041  for(uint i=0;i<mydoubles.size();i++){
1042  snprintf ( szResult, sizeof(szResult), "%f", mydoubles[i] ); // "safe" version
1043  cout << "double/string: " << mydoubles[i] << " / " << szResult << endl;
1044  }
1045  exit(0);
1046  */
1047 
1048  /*
1049  // testing stod() ..
1050  // this is giving different results if gui or console mode !!
1051  vector<string> numbers;
1052  numbers.push_back("123.1234567890");
1053  numbers.push_back("123.1234");
1054  numbers.push_back("123,1234567890");
1055  numbers.push_back("123,1234");
1056  double outd;
1057  for(uint i=0;i<numbers.size();i++){
1058  try {
1059  outd = stod(numbers[i]);
1060  cout << "Conversion passed: " << numbers[i] << " - " << outd << endl;
1061  } catch (...) {
1062  cout << "Conversion DID NOT passed: " << numbers[i] << " - " <<endl;
1063  }
1064  }
1065  exit(0);
1066  */
1067 
1068 /*
1069 // ------------------------------------
1070 // Testing makeKeyProdData() and unpackKeyProdData()
1071  string parName = "za";
1072  int regId = 20000;
1073  string prod = "wood";
1074  string freeDim = "";
1075  string key = MTHREAD->MD->makeKeyProdData(parName,i2s(regId),prod,freeDim);
1076  cout << "key: " << key << endl;
1077  MTHREAD->MD->unpackKeyProdData(key,parName,regId,prod,freeDim);
1078  cout << "parName: " << parName << endl;
1079  cout << "regId: " << regId << endl;
1080  cout << "prod: " << prod << endl;
1081  cout << "freeDim: " << freeDim << endl;
1082  exit(0);
1083 */
1084 
1085 /*
1086 // ---------------------------------------------
1087 // checking the functions dataMapCheckExist() and dataMapGetValue() works well
1088 typedef map<string, vector <double> > DataMap;
1089 typedef pair<string, vector <double> > DataPair;
1090 
1091 vector <double> abaa (5, 1.);
1092 vector <double> abcc (5,10);
1093 vector <double> anbb (5,100);
1094 vector <double> andd (5,5);
1095 vector <double> anff (5,3);
1096 vector <double> ag (5,2);
1097 vector <double> agii (5,7);
1098 
1099 
1100 
1101 DataMap dM;
1102 dM.insert(DataPair("abaa", abaa));
1103 dM.insert(DataPair("abcc", abcc));
1104 dM.insert(DataPair("anbb", anbb));
1105 dM.insert(DataPair("andd", andd));
1106 dM.insert(DataPair("anff", anff));
1107 dM.insert(DataPair("ag", ag));
1108 dM.insert(DataPair("agii", agii));
1109 
1110 vector<string> tests;
1111 tests.push_back("ab");
1112 tests.push_back("anbb");
1113 tests.push_back("ane");
1114 tests.push_back("an");
1115 tests.push_back("ac");
1116 tests.push_back("ag");
1117 tests.push_back("agii");
1118 tests.push_back("al");
1119 
1120 
1121 bool found;
1122 double value;
1123 
1124 for(uint i=0;i<tests.size();i++){
1125  found = MTHREAD->MD->dataMapCheckExist(dM, tests[i]);
1126  value = MTHREAD->MD->dataMapGetValue(dM, tests[i],2010);
1127  cout << tests[i] << ": " << b2s(found) << " value: "<< value << endl;
1128 }
1129 
1130 exit(0);
1131 */
1132 
1133 
1134  /*
1135  // testing how to search on a vector using the find algorithm
1136 
1137  vector<string> names;
1138  names.push_back("pippo");
1139  names.push_back("topolino");
1140  names.push_back("minni");
1141  names.push_back("paperino");
1142 
1143  string toSearch1 = "minni";
1144  string toSearch2 = "zio paperone";
1145 
1146  if( find(names.begin(), names.end(), toSearch1)!= names.end() ){
1147  cout << "minni trovata" << endl;
1148  }
1149  if( find(names.begin(), names.end(), toSearch2)!= names.end() ){
1150  cout << "zio paperone trovato" << endl;
1151  }
1152  cout << "test on find ended." << endl;
1153  exit(0);
1154  */
1155 
1156 // ------------------------------------------------------------------
1157 
1158 
1159  /*
1160  int a;
1161  a = getSetting<int>("myIntData", TYPE_INT);
1162 
1163  string b;
1164  b = getSetting<string>("myStringData", TYPE_STRING);
1165 
1166  bool c;
1167  c = getSetting<bool>("myBoolData", TYPE_BOOL);
1168 
1169 
1170  cout << "A is: " << a << endl;
1171 
1172  cout << "B is: " << b << endl;
1173 
1174  cout << "C is: " << c << endl;
1175 
1176  //vector<string> getVectorSetting <string> ("test", TYPE_STRING);
1177  //template <class T> vector <T> getVectorSetting(string name_h, int type);
1178 
1179  //vector <string> myStrings = getVectorSetting <vector<string> > ("test", TYPE_STRING);
1180 
1181  string s = GccTest("test");
1182  int i = GccTest("test");
1183  vector <int> iVector = GccTest("test");
1184 
1185  for (int i=0; i< iVector.size(); i++){
1186  cout << "iVector: " << iVector.at(i) << endl;
1187  }
1188  */
1189 
1190  // ------------------------------------------------------------------
1191 
1192  /* // I learned: how to access elements - both objects and pointers - of a vector using pointers
1193  // testing how to operate with iterators over a pointer element in an array:
1194 
1195  cout << "Starting iterator test..." << endl;
1196 
1197  TestStructure a,b,c,d;
1198  a.i=0; b.i=1; c.i=2; d.i=3;
1199  TestStructure* ap;
1200  TestStructure* bp;
1201  TestStructure* cp;
1202  TestStructure* dp;
1203 
1204  ap = &a;
1205  bp = &b;
1206  cp = &c;
1207  dp = &d;
1208 
1209  vector <TestStructure> objects;
1210  vector <TestStructure*> pointers;
1211 
1212  objects.push_back(a);
1213  objects.push_back(b);
1214  objects.push_back(c);
1215  objects.push_back(d);
1216 
1217  pointers.push_back(ap);
1218  pointers.push_back(bp);
1219  pointers.push_back(cp);
1220  pointers.push_back(dp);
1221 
1222  vector<TestStructure>::iterator pi;
1223  vector<TestStructure*>::iterator pp;
1224 
1225  //ok it works
1226  //for ( pi = objects.begin() ; pi != objects.end();){
1227  // if(pi->i==2){
1228  // objects.erase(pi);
1229  // }
1230  // else {
1231  // ++pi;
1232  // }
1233  //}
1234 
1235  //for (int j=0;j<objects.size();j++){
1236  // cout << j << " object is: " << objects[j].i << endl;
1237  //}
1238 
1239 
1240  // works as well ;-))
1241  for ( pp = pointers.begin() ; pp != pointers.end();){
1242  if( (*pp)->i==2){
1243  //delete (*pp);
1244  pointers.erase(pp);
1245  }
1246  else {
1247  ++pp;
1248  }
1249  }
1250 
1251  for (int j=0;j<pointers.size();j++){
1252  cout << j << " pointers is: " << pointers[j]->i << endl;
1253  }
1254 
1255  // c is not destructed if we don't explicitelly call delete over the pointer...
1256  cout << c.i << endl; // this go in seg-frag if we call delete (*pp)..
1257  */
1258 
1259  // ------------------------------------------------------------------
1260  /* test on how to remove from a map.. deletable
1261  map <int, string> test;
1262  test.insert(pair<int, string>(2, "pippo"));
1263  test.insert(pair<int, string>(1, "pluto"));
1264  test.insert(pair<int, string>(5, "minni"));
1265  test.insert(pair<int, string>(3, "topolino"));
1266 
1267 
1268  map <int, string>::iterator p;
1269  p=test.find(3);
1270  if(p != test.end()){
1271  cout << p->second <<endl;
1272  test.erase(p);
1273  }
1274  else {
1275  cout << "not found " << endl;
1276  }
1277 
1278  map <int, string>::iterator p2;
1279  p2=test.find(3);
1280  if(p2 != test.end()){
1281  cout << p2->second <<endl;
1282  test.erase(p2);
1283  }
1284  else {
1285  cout << "not found " << endl;
1286  }
1287  */
1288 
1289  /*vector<int> test;
1290  for (int i=0;i<5;i++) test.push_back(i);
1291  cout << "test.." << endl;
1292  for (uint i=0;i<test.size();i++){
1293  cout << "Test "<<i<<": "<<test.at(i) << endl;
1294  }
1295  //test.erase(2);
1296 
1297  vector<int>::iterator p;
1298  for ( p = test.begin() ; p != test.end();){
1299  if(*p == 1 || *p == 2 || *p==4){
1300  test.erase(p);
1301  }
1302  else {
1303  ++p;
1304  }
1305  }
1306 
1307 
1308  for (uint i=0;i<test.size();i++){
1309  cout << "Test "<<i<<": "<<test.at(i) << endl;
1310  }
1311 
1312 // test.erase(remove_if(test.begin(), test.end(), FindMatchingString(&fs))
1313 
1314 // for (int i=0;i<test.size();i++) cout << "TEST: "<<i<< " " << test.at(i) << endl;
1315  */
1316 
1317  /*
1318  // On this test I am showing how to "move" one pointer from a vector of pointers to an other one. The real case is used to move Agent_farmer* pointers from the managedAgents vector to the removedVector.
1319 
1320  double* myDouble1 = new double(1);
1321  double* myDouble2 = new double(2);
1322  double* myDouble3 = new double(3);
1323 
1324  vector <double*> origin;
1325  vector <double*> destination;
1326 
1327  origin.push_back(myDouble1);
1328  origin.push_back(myDouble2);
1329  origin.push_back(myDouble3);
1330 
1331  cout << "MyDouble2: "<< *myDouble2 << endl;
1332  vector<double*>::iterator doublePIterator;
1333 
1334  for (int i=0;i<origin.size();i++){
1335  cout << i << " origin is: " << *origin[i] << endl;
1336  }
1337 
1338  for ( doublePIterator = origin.begin() ; doublePIterator !=origin.end();){
1339  if(*doublePIterator == myDouble2){
1340  destination.push_back(myDouble2);
1341  origin.erase(doublePIterator);
1342  }
1343  else {
1344  ++doublePIterator;
1345  }
1346  }
1347 
1348  for (int i=0;i<origin.size();i++){
1349  cout << i << " origin is now: " << *origin[i] << endl;
1350  }
1351 
1352  for (int i=0;i<destination.size();i++){
1353  cout << i << " destination is: " << *destination[i] << endl;
1354  } */
1355 
1356  // ------------------------------------------------------------------
1357  /*
1358  // Test on how to return a vector of pointers from a member vector of data
1359  TestStructure a,b,c,d;
1360  a.i=0; b.i=1; c.i=2; d.i=3;
1361  testVector.push_back(a);
1362  testVector.push_back(b);
1363  testVector.push_back(c);
1364  testVector.push_back(d);
1365 
1366  vector<TestStructure*> myVector=getTestStructure();
1367 
1368  for(uint i=0;i<myVector.size();i++){
1369  msgOut(MSG_DEBUG, i2s(myVector[i]->i));
1370  }
1371  */
1372 
1373  /*
1374  // Deleting an object and inserting a new one on a vector of objects.. it doesn't works.. problems with the last element..
1375  vector<BasicData>::iterator p;
1376  for(p=programSettingsVector.begin();p!=programSettingsVector.end();p++){
1377  if(p->name == SETT.name){
1378  programSettingsVector.erase(p);
1379  programSettingsVector.insert(p,1,SETT);
1380  cout << SETT.name <<endl;
1381  break;
1382  }
1383  }
1384  */
1385 
1386  /*double test = -987654321.987654321;
1387  double result;
1388  result = fabs(test);
1389  cout << "Test: "<< result << endl;*/
1390 
1391 
1392  /*
1393  // Testing the zip library:
1394 
1395  cout <<"Hello world Zip!" << endl;
1396 
1397  QString file = "data/testInput.ods";
1398  QString out = "data/tempInput";
1399  QString pwd = "";
1400  if (!QFile::exists(file))
1401  {
1402  cout << "File does not exist." << endl << endl;
1403  //return false;
1404  }
1405 
1406  UnZip::ErrorCode ec;
1407  UnZip uz;
1408 
1409  if (!pwd.isEmpty())
1410  uz.setPassword(pwd);
1411 
1412  ec = uz.openArchive(file);
1413  if (ec != UnZip::Ok)
1414  {
1415  //cout << "Failed to open archive: " << uz.formatError(ec).toAscii().data() << endl << endl; // Qt4
1416  cout << "Failed to open archive: " << uz.formatError(ec).toLatin1().data() << endl << endl; // Qt5
1417  //return false;
1418  }
1419 
1420  ec = uz.extractAll(out);
1421  if (ec != UnZip::Ok)
1422  {
1423  //cout << "Extraction failed: " << uz.formatError(ec).toAscii().data() << endl << endl; // Qt4
1424  cout << "Extraction failed: " << uz.formatError(ec).toLatin1().data() << endl << endl; // Qt5
1425  uz.closeArchive();
1426  //return false;
1427  }
1428  */
1429 
1430  /*
1431  // How to : delete an element from an array from its position
1432  cout << "How to : delete an element from an array from its position" << endl;
1433 
1434  vector <string> headers;
1435  vector < vector <string> > records;
1436  vector <string> firstrecord;
1437  vector <string> secondrecord;
1438  records.push_back(firstrecord);
1439  records.push_back(secondrecord);
1440 
1441  headers.push_back("a");
1442  headers.push_back("b");
1443  headers.push_back("");
1444  headers.push_back("d");
1445  headers.push_back("e");
1446  headers.push_back("");
1447 
1448  records[0].push_back("0");
1449  records[0].push_back("1");
1450  records[0].push_back("2");
1451  records[0].push_back("3");
1452  records[0].push_back("4");
1453  records[0].push_back("5");
1454  records[1].push_back("00");
1455  records[1].push_back("11");
1456  records[1].push_back("22");
1457  records[1].push_back("33");
1458  records[1].push_back("44");
1459  records[1].push_back("55");
1460 
1461  for (int i=headers.size()-1;i>=0;i--){
1462  if(headers[i] == ""){
1463  headers.erase(headers.begin()+i);
1464  for (int j=0;j<records.size();j++){
1465  records[j].erase(records[j].begin()+i);
1466  }
1467  }
1468  }
1469  for(uint i=0;i<headers.size();i++){
1470  cout << headers.at(i) << " - " << records[0].at(i) << " - " << records[1].at(i) << endl;
1471  }
1472  cout << "done!" << endl;
1473  */
1474 
1475  //testThreads();
1476  /*vector<double> numbers;
1477  double cumNumbers = 0.00;
1478  numbers.push_back(0.40);
1479  numbers.push_back(0.10);
1480  numbers.push_back(0.20);
1481  numbers.push_back(0.08);
1482  numbers.push_back(0.22);
1483 
1484  for (uint i=0;i<numbers.size();i++){
1485  cumNumbers += numbers[i];
1486  }
1487 
1488  if (cumNumbers <= 0.99999999 || cumNumbers >= 1.00000001) {
1489  cout <<"Bastardo!"<<endl;
1490  } else {
1491  cout <<"qui funzia!"<<endl;
1492  }*/
1493 
1494 }

Here is the caller graph for this function:

T getSetting ( string  name_h,
int  type 
)

Definition at line 1518 of file Sandbox.cpp.

1518  {
1519 
1520  string myIntData;
1521  myIntData = "34";
1522  string myStringData;
1523  myStringData = "abcdefg";
1524 
1525  string myBoolData;
1526  myBoolData = "false";
1527 
1528  if(type==TYPE_INT){
1529  istringstream iss(myIntData);
1530  T x;
1531  iss >> x;
1532  return x;
1533  }
1534 
1535  if(type==TYPE_STRING){
1536  istringstream iss(myStringData);
1537  T x;
1538  iss >> x;
1539  return x;
1540  }
1541 
1542  if(type==TYPE_BOOL){
1543  string tempBoolString;
1544  if (myBoolData == "1" || myBoolData == "true" || myBoolData == "True" || myBoolData == "TRUE" || myBoolData == "vero" || myBoolData == "Vero"|| myBoolData == "VERO"){
1545  tempBoolString = "1";
1546  }
1547  else if (myBoolData == "0" || myBoolData == "false" || myBoolData == "False" || myBoolData == "FALSE" || myBoolData == "falso" || myBoolData == "falso"|| myBoolData == "FALSO"){
1548  tempBoolString = "0";
1549  }
1550  else {
1551  msgOut(MSG_CRITICAL_ERROR, "Impossible conversion of "+myBoolData+" to bool!. Aborted.");
1552  }
1553  istringstream iss(tempBoolString);
1554  T x;
1555  iss >> x;
1556  return x;
1557  }
1558 
1559 
1560 }
The required data is a string.
Definition: BaseClass.h:68
The required data is a bool.
Definition: BaseClass.h:69
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
Print an error message and stop the model.
Definition: BaseClass.h:62
The required data is an integer.
Definition: BaseClass.h:66
vector< TestStructure * > getTestStructure ( )

Definition at line 1572 of file Sandbox.cpp.

Referenced by printAString().

1572  {
1573  vector <TestStructure*> toReturn;
1574  for (uint i=0;i<testVector.size();i++){
1575  //TestStructure* tempTest = new TestStructure;
1576  toReturn.push_back(&testVector[i]);
1577  }
1578  return toReturn;
1579 
1580 }
vector< TestStructure > testVector
Definition: Sandbox.h:61

Here is the caller graph for this function:

vector<T> getVectorSetting ( string  name_h,
int  type 
)
void printAString ( string  what)
inline

Definition at line 50 of file Sandbox.h.

50 {cout << "You printed: "<< what << endl;};

Here is the call graph for this function:

T test2 ( const std::string &  s)

Definition at line 1563 of file Sandbox.cpp.

1563  {
1564  std::istringstream iss(s);
1565  T x;
1566  iss >> x;
1567  return x;
1568 }
int testAdolc ( )

Definition at line 1758 of file Sandbox.cpp.

Referenced by printAString().

1758  {
1759 
1760  using namespace Ipopt;
1761  // Create an instance of your nlp...
1762  SmartPtr<TNLP> myadolc_nlp = new MyADOLC_NLP();
1763  //SmartPtr<TNLP> myadolc_nlp = new MyADOLC_sparseNLP();
1764 
1765  // Create an instance of the IpoptApplication
1766  SmartPtr<IpoptApplication> app = new IpoptApplication();
1767 
1768  // Initialize the IpoptApplication and process the options
1769  ApplicationReturnStatus status;
1770  status = app->Initialize();
1771  if (status != Solve_Succeeded) {
1772  printf("\n\n*** Error during initialization!\n");
1773  return (int) status;
1774  }
1775 
1776  status = app->OptimizeTNLP(myadolc_nlp);
1777 
1778  if (status == Solve_Succeeded) {
1779  // Retrieve some statistics about the solve
1780  Index iter_count = app->Statistics()->IterationCount();
1781  printf("\n\n*** The problem solved in %d iterations!\n", iter_count);
1782 
1783  Number final_obj = app->Statistics()->FinalObjective();
1784  printf("\n\n*** The final value of the objective function is %e.\n", final_obj);
1785  }
1786 
1787  return (int) status;
1788 }

Here is the caller graph for this function:

void testIpopt ( )

Definition at line 1707 of file Sandbox.cpp.

Referenced by printAString().

1707  {
1708 
1709 
1710  using namespace Ipopt;
1711 
1712  // Create a new instance of your nlp
1713  // (use a SmartPtr, not raw)
1714  SmartPtr<TNLP> mynlp = new Ipopt_nlp_problem_debugtest();
1715 
1716  // Create a new instance of IpoptApplication
1717  // (use a SmartPtr, not raw)
1718  // We are using the factory, since this allows us to compile this
1719  // example with an Ipopt Windows DLL
1720  SmartPtr<IpoptApplication> app = IpoptApplicationFactory();
1721 
1722  // Change some options
1723  // Note: The following choices are only examples, they might not be
1724  // suitable for your optimization problem.
1725  app->Options()->SetNumericValue("tol", 1e-7);
1726  app->Options()->SetStringValue("mu_strategy", "adaptive");
1727  app->Options()->SetStringValue("output_file", "ipopt.out");
1728  //app->Options()->SetStringValue("hessian_approximation", "limited-memory");
1729  //app->Options()->SetStringValue("derivative_test", "second-order");
1730  //app->Options()->SetStringValue("derivative_test_print_all", "yes");
1731 
1732 
1733  // The following overwrites the default name (ipopt.opt) of the
1734  // options file
1735  // app->Options()->SetStringValue("option_file_name", "hs071.opt");
1736 
1737  // Intialize the IpoptApplication and process the options
1738  ApplicationReturnStatus status;
1739  status = app->Initialize();
1740  if (status != Solve_Succeeded) {
1741  std::cout << std::endl << std::endl << "*** Error during initialization!" << std::endl;
1742  //return (int) status; // here the abort
1743  }
1744 
1745  // Ask Ipopt to solve the problem
1746  status = app->OptimizeTNLP(mynlp);
1747 
1748  if (status == Solve_Succeeded) {
1749  std::cout << std::endl << std::endl << "*** The problem solved!" << std::endl;
1750  }
1751  else {
1752  std::cout << std::endl << std::endl << "*** The problem FAILED!" << std::endl;
1753  }
1754 
1755 }

Here is the caller graph for this function:

void testPartMatching ( )

How to partial matching the key of a map.

Definition at line 1833 of file Sandbox.cpp.

Referenced by printAString().

1833  {
1834 
1835  TStrStrMap tMap;
1836 
1837  tMap.insert(TStrStrPair("John", "AA"));
1838  tMap.insert(TStrStrPair("Mary", "BBB"));
1839  tMap.insert(TStrStrPair("Mother", "A"));
1840  tMap.insert(TStrStrPair("Moliere", "D"));
1841  tMap.insert(TStrStrPair("Marlon", "C"));
1842 
1843  testSearchMap(tMap, "Marl");
1844  testSearchMap(tMap, "Mo");
1845  testSearchMap(tMap, "ther");
1846  testSearchMap(tMap, "Mad");
1847  testSearchMap(tMap, "Mom");
1848  testSearchMap(tMap, "Perr");
1849  testSearchMap(tMap, "Jo");
1850 
1851  exit(0);
1852  return;
1853 }
pair< string, string > TStrStrPair
Definition: Sandbox.cpp:77
map< string, string > TStrStrMap
Definition: Sandbox.cpp:76
void testSearchMap(const map< string, string > &map, const string &search_for)
Definition: Sandbox.cpp:1818

Here is the caller graph for this function:

void testPartMatching2 ( )

How to partial matching the key of a map.

Definition at line 1870 of file Sandbox.cpp.

Referenced by printAString().

1870  {
1871 
1872  TStrStrMap tMap;
1873 
1874 
1875  tMap.insert(TStrStrPair("mortCoeff_multiplier#broadL_highF##2005", "2005"));
1876  tMap.insert(TStrStrPair("regLev_1", "-9999"));
1877  tMap.insert(TStrStrPair("regLev_2", "-9999"));
1878  tMap.insert(TStrStrPair("tp_multiplier#broadL_copp##2005", "-9999"));
1879  tMap.insert(TStrStrPair("tp_multiplier#broadL_highF##2005", "50"));
1880  tMap.insert(TStrStrPair("tp_multiplier#broadL_highF##2010", "2010"));
1881  tMap.insert(TStrStrPair("tp_multiplier#broadL_mixedF##2005", "-9999"));
1882  tMap.insert(TStrStrPair("tp_multiplier#con_copp##2005", "-9999"));
1883  tMap.insert(TStrStrPair("tp_multiplier#con_highF##2005", "-9999"));
1884  tMap.insert(TStrStrPair("tp_multiplier#con_mixedF##2005", "aa"));
1885 
1886  TStrStrMap::const_iterator i;
1887 
1888  for(i=tMap.begin();i!=tMap.end();i++){
1889  cout << i->first << ", " << i->second << endl;
1890  }
1891  cout << endl;
1892 
1893  testSearchMap2(tMap, "mortCoeff_multiplier#broadL_highF##2006");
1894  testSearchMap2(tMap, "tp_multiplier#broadL_highF##2008");
1895  testSearchMap2(tMap, "aaaaaa");
1896  testSearchMap2(tMap, "zzzzzz");
1897 
1898  exit(0);
1899  return;
1900 }
pair< string, string > TStrStrPair
Definition: Sandbox.cpp:77
void testSearchMap2(const map< string, string > &map_h, const string &search_for)
Definition: Sandbox.cpp:1856
map< string, string > TStrStrMap
Definition: Sandbox.cpp:76

Here is the caller graph for this function:

void testSearchMap ( const map< string, string > &  map,
const string &  search_for 
)
private

Definition at line 1818 of file Sandbox.cpp.

1818  {
1819  TStrStrMap::const_iterator i = map.lower_bound(search_for);
1820  for(;i != map.end();i++){
1821  const string& key = i->first;
1822  if (key.compare(0, search_for.size(), search_for) == 0) {// Really a prefix?
1823  cout << i->first << ", " << i->second << endl;
1824  } else {
1825  break;
1826  }
1827  }
1828 
1829 }
void testSearchMap2 ( const map< string, string > &  map_h,
const string &  search_for 
)
private

Definition at line 1856 of file Sandbox.cpp.

1856  {
1857  TStrStrMap::const_iterator i = map_h.upper_bound(search_for);
1858  if(i!= map_h.begin()) i--;
1859  const string& key = i->first;
1860  string search_base = search_for.substr(0,search_for.size()-4);
1861  if (key.compare(0, search_base.size(), search_base) == 0){
1862  cout << "MATCH: " << search_for <<", "<< i->first << ", " << i->second << endl;
1863  } else {
1864  cout << "NOTM: " << search_for <<", "<< i->first << endl;
1865  }
1866 
1867 }
void testThreads ( )

Definition at line 1585 of file Sandbox.cpp.

Referenced by printAString().

1585  {
1586 
1587  /*
1588  PSEUDOCODE
1589  - attivo i vari thread
1590  - per ogni closestAgent itero fra i vari thread e se "è libero" gli assegno il closestAgent
1591  - quando ho finito i closestAgent aspetto che tutti i threads abbiano finito il lavoro
1592  - chiudo i threads
1593  - vado avanti
1594  */
1595  int nAgents= 50;
1596  vector<TestStructure*> myAgents;
1597  vector<double> myResults (nAgents, (double) 0);
1598  //int nThreads = MTHREAD->MD->getIntSetting("nThreads");
1599  int nThreads= 5;
1600 
1601  for (int i=0; i < nAgents; i++){
1602  TestStructure* myAgent = new TestStructure;
1603  myAgent->i = i;
1604  myAgent->random = (0+( (double)rand() / ((double)(RAND_MAX)+(double)(1)) )*(10-0+1))/ (double)100;
1605  myAgents.push_back(myAgent);
1606  }
1607 
1608  vector <testThread*> myThreads ;
1609 
1610  for (int i=0; i < nThreads; i++){
1611  testThread* myThread = new testThread;
1612  myThreads.push_back(myThread);
1613  }
1614 
1615  for (uint i=0;i<myAgents.size();i++){
1616  bool assigned = false;
1617  while(!assigned) {
1618  for (uint j=0;j<myThreads.size();j++){
1619  if (!myThreads[j]->isRunning()){
1620  cout << "Assigning agent " << i << " to thread " << j << endl;
1621  myThreads[j]->assignJob(myAgents[i]);
1622  myThreads[j]->start();
1623  assigned = true;
1624  break;
1625  }
1626  else {
1627  cout << "Thread " << j << " is busy" << endl;
1628  }
1629  }
1630  }
1631  }
1632  /*
1633  volatile bool somethingStopping = true;
1634  while (somethingStopping){
1635  somethingStopping = false;
1636  for (uint i=0;i<myThreads.size();i++){
1637  if(myThreads[i]->isRunning()){
1638  somethingStopping = true;
1639  //cout << "somethingStopping is true" << endl;
1640  }
1641  }
1642  }
1643 
1644  if (somethingStopping) {
1645  cout << "somethingStopping is true" << endl;
1646  }
1647  else {
1648  cout << "somethingStopping is false" << endl;
1649  }
1650  cout << "pinco pallo sono nel mezzo dei threads..."<<endl;
1651  */
1652  for (int i=0; i < nThreads; i++){
1653  myThreads[i]->wait();
1654  }
1655 
1656 
1657  for (int i=0; i < nThreads; i++){
1658  delete myThreads[i];
1659  }
1660 
1661  for (uint i=0;i<myAgents.size();i++){
1662  //cout <<myAgents[i]->cachedOffer<<endl;
1663 
1664  double random = (0+( (double)rand() / ((double)(RAND_MAX)+(double)(1)) )*(10-0+1))/ (double)100;
1665 
1666  // important !
1667  // for random integer see also std::uniform_int_distribution :
1668  // http://stackoverflow.com/questions/7780918/stduniform-int-distributionint-range-in-g-and-msvc
1669  // in regmas:
1670  // int randomRed = int (50+( (double)rand() / ((double)(RAND_MAX)+(double)(1)) )*(255-50+1)); // randomRed is [50,255] Don't use "randomNumber % range" !!
1671 
1672  //cout <<random<<endl;
1673  }
1674 
1675  //thread1.stop();
1676  cout << "FINITO"<<endl;
1677 
1678 
1679 }
double random
Definition: Sandbox.h:73

Here is the caller graph for this function:

Member Data Documentation

vector<TestStructure> testVector
private

Definition at line 61 of file Sandbox.h.


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