EasyLocal++ Documentation


 
Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

EasyLocal.cpp

Go to the documentation of this file.
00001 
00020 #include <ctime>
00021 #include <cstdlib>
00022 #include <iostream>
00023 #include <FlexLexer.h>
00024 
00025 #include "EasyLocal.h"
00026 
00027 namespace easylocal {
00028   
00037   int Random(int i, int j)
00038   { 
00039     static bool init = false;
00040     if (init == false)  // if the random source has not been 
00041       {                 // initialized yet
00042         srand(time(0)); // let's initialize it
00043         init = true;
00044       }
00045     return (rand() % (j - i + 1)) + i; // return the randomly picked value
00046   }
00047 
00056   inline double distance(fvalue x, fvalue y)
00057   {
00058     return x > y ? x-y : y-x;
00059   }
00060 
00066   void AbstractTester::SetSolverTrials(unsigned int t)
00067   { trials = t; }
00068 
00075   void AbstractTester::SetLogFile(std::string s)
00076   { logstream = new std::ofstream(s.c_str()); }
00077 
00085   void AbstractTester::SetOutputPrefix(std::string s)
00086   { output_file_prefix = s; }
00087         
00094   void AbstractTester::SetPlotPrefix(std::string s)
00095   { plot_file_prefix = s; } 
00096         
00097   //
00098   // Actual Runner Parameters Classes related methods
00099   //
00100   
00108   ParameterData::ParameterData(std::string n, std::string t, ValueType v)
00109     : name(n), type(t), value(v)
00110   {}
00111   
00117   std::string ParameterData::Name() const
00118   { return name; }
00119 
00125   std::string ParameterData::Type() const
00126   { return type; }
00127         
00133   ValueType ParameterData::Value() const
00134   { return value; }
00135         
00136   
00144   void ParameterBox::Put(std::string name, std::string type, ValueType value) 
00145   { parameters.push_back(ParameterData(name,type,value)); }
00146         
00153   void ParameterBox::Put(std::string name, unsigned long value)
00154   { 
00155     ValueType tmp;
00156     tmp.natural = value;
00157     parameters.push_back(ParameterData(name,"ulong",tmp)); 
00158   }
00159 
00166   void ParameterBox::Put(std::string name, unsigned int value)
00167   { 
00168     ValueType tmp;
00169     tmp.short_natural = value;
00170     parameters.push_back(ParameterData(name,"uint",tmp)); 
00171   }
00172         
00179   void ParameterBox::Put(std::string name, double value)  
00180   { 
00181     ValueType tmp;
00182     tmp.real = value;
00183     parameters.push_back(ParameterData(name,"double",tmp)); 
00184   }
00185         
00194   void ParameterBox::Get(std::string name, std::string type, ValueType& value) const
00195   {
00196     bool found = false;
00197     for (std::list<ParameterData>::const_iterator i = parameters.begin(); i != parameters.end(); i++)
00198       if (i->Name() == name) {
00199         found = true;
00200         assert(type == i->Type());
00201         value = i->Value();
00202         break;
00203       }
00204     assert(found);
00205   }
00206         
00213   void ParameterBox::Get(std::string name, unsigned long& value) const
00214   {
00215     bool found = false;
00216     for (std::list<ParameterData>::const_iterator i = parameters.begin(); i != parameters.end(); i++)
00217       if (i->Name() == name) {
00218         found = true;
00219         assert("ulong" == i->Type());
00220         value = i->Value().natural;
00221         break;
00222       }
00223     assert(found);
00224   }
00225         
00232   void ParameterBox::Get(std::string name, unsigned int& value) const
00233   {
00234     bool found = false;
00235     for (std::list<ParameterData>::const_iterator i = parameters.begin(); i != parameters.end(); i++)
00236       if (i->Name() == name) {
00237         found = true;
00238         assert("uint" == i->Type());
00239         value = i->Value().short_natural;
00240         break;
00241       }
00242     assert(found);
00243   }
00244         
00251   void ParameterBox::Get(std::string name, double& value) const
00252   {
00253     bool found = false;
00254     for (std::list<ParameterData>::const_iterator i = parameters.begin(); i != parameters.end(); i++)
00255       if (i->Name() == name) {
00256         found = true;
00257         assert("double" == i->Type());
00258         value = i->Value().real;
00259         break;
00260       }
00261     assert(found);
00262   }
00263         
00267   void ParameterBox::Clear()
00268   { parameters.clear(); }               
00269 }; // end of namespace easylocal
 
Go to: the Main Page of the documentation.