00001 #ifndef OPTFRAME_H_
00002 #define OPTFRAME_H_
00003
00007
00008 #include <iostream>
00009 #include <ostream>
00010
00011 #include <vector>
00012 #include <map>
00013
00014 #include "Util/printable.h"
00015 #include "Util/Matrix.hpp"
00016 #include "Util/Scanner++/Scanner.h"
00017 #include "Util/Timer.hpp"
00018
00019 #include "Solution.hpp"
00020 #include "Util/TestSolution.hpp"
00021
00022 #include "Population.hpp"
00023
00024 #include "InitialSolution.h"
00025 #include "InitialPopulation.h"
00026
00027 #include "Move.hpp"
00028
00029 #include "Evaluation.hpp"
00030 #include "Evaluator.hpp"
00031 #include "MultiObjectiveEvaluator.hpp"
00032
00033 #include "Util/TestEvaluation.hpp"
00034
00035
00036
00037
00038
00039 #include "NS.hpp"
00040 #include "NSSeq.hpp"
00041 #include "NSEnum.hpp"
00042
00043
00044
00045
00046
00047 #include "Util/NSSeqUnionAdapter.hpp"
00048
00049 #include "Util/NSSeqkRouteAdapter.hpp"
00050 #include "Util/NSSeqMultiRouteAdapter.hpp"
00051
00052 #include "Util/NSSeqVectorOrOptk.hpp"
00053 #include "Util/NSSeqVectorOrOpt.hpp"
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 #include "Parallel/Parallel.h"
00068
00069
00070
00071
00072
00073 #include "Heuristic.hpp"
00074
00075 #include "HeuristicFactory.hpp"
00076
00077
00078
00079 #include "OptFrameModule.hpp"
00080
00081 #include "RandGen.hpp"
00082 #include "Util/RandGenMersenneTwister.hpp"
00083
00084 #include "Modules/BuildModule.hpp"
00085 #include "Modules/CheckModule.hpp"
00086 #include "Modules/DefineModule.hpp"
00087 #include "Modules/DictionaryModule.hpp"
00088 #include "Modules/EmpiricalModule.hpp"
00089 #include "Modules/EvaluateModule.hpp"
00090 #include "Modules/ExecModule.hpp"
00091 #include "Modules/ExportModule.hpp"
00092 #include "Modules/HelpModule.hpp"
00093 #include "Modules/PrintModule.hpp"
00094 #include "Modules/ReadModule.hpp"
00095 #include "Modules/TestModule.hpp"
00096 #include "Modules/UsageModule.hpp"
00097 #include "Modules/InitServersModule.hpp"
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 template<class R, class M = OPTFRAME_DEFAULT_MEMORY>
00119 class OptFrame
00120 {
00121 private:
00122 vector<OptFrameModule<R, M>*> modules;
00123 map<string, string>* dictionary;
00124
00125 public:
00126
00127 HeuristicFactory<R, M>& factory;
00128
00129 OptFrame(RandGen& _rg) :
00130 factory(*new HeuristicFactory<R, M> (_rg))
00131 {
00132 loadDefaultModules();
00133 dictionary = new map<string, string> ;
00134 }
00135
00136 OptFrame(HeuristicFactory<R, M>& f) :
00137 factory(f)
00138 {
00139 loadDefaultModules();
00140 dictionary = new map<string, string> ;
00141 }
00142
00143 string version()
00144 {
00145 return "OptFrame - Development Version \nhttp://sourceforge.net/projects/optframe/";
00146 }
00147
00148 void loadModule(OptFrameModule<R, M>* module)
00149 {
00150 modules.push_back(module);
00151 }
00152
00153 void loadDefaultModules()
00154 {
00155 modules.clear();
00156 loadModule(new BuildModule<R, M> );
00157 loadModule(new CheckModule<R, M> );
00158 loadModule(new DefineModule<R, M> );
00159 loadModule(new DictionaryModule<R, M> );
00160 loadModule(new EmpiricalModule<R, M> );
00161 loadModule(new EvaluateModule<R, M> );
00162 loadModule(new ExecModule<R, M> );
00163 loadModule(new ExportModule<R, M> );
00164 loadModule(new HelpModule<R, M> );
00165 loadModule(new PrintModule<R, M> );
00166 loadModule(new ReadModule<R, M> );
00167 loadModule(new TestModule<R, M> );
00168 loadModule(new UsageModule<R, M> );
00169 #ifdef MaPI
00170 loadModule(new InitServersModule<R, M> );
00171 #endif
00172 }
00173
00174 OptFrameModule<R, M>* getModule(string module)
00175 {
00176 for (unsigned int i = 0; i < modules.size(); i++)
00177 if (module == modules[i]->id())
00178 return modules[i];
00179 return NULL;
00180 }
00181
00182 void execute()
00183 {
00184 cout << "Welcome to " << version() << endl;
00185
00186 Scanner scanner(&cin);
00187 string line;
00188
00189 while (true)
00190 {
00191 cout << ">";
00192 line = scanner.nextLine();
00193
00194 Scanner s2(line);
00195
00196 string command = s2.next();
00197
00198 if (command == "quit" || command == "q" || command == "exit")
00199 break;
00200
00201 if (command == "version" || command == "v")
00202 {
00203 cout << version() << endl;
00204 continue;
00205 }
00206
00207 bool notfound = true;
00208
00209 for (int i = 0; i < modules.size(); i++)
00210 if (command == modules[i]->id())
00211 {
00212 string r = modules[i]->preprocess(dictionary, s2.rest());
00213
00214 if (r == "INVALID_PARAM")
00215 {
00216 cout << "Population size has to be, at least, equal 2.\n";
00217 notfound = false;
00218 break;
00219 }
00220
00221 modules[i]->run(modules, &factory, dictionary, r);
00222 notfound = false;
00223 break;
00224 }
00225
00226 if (notfound)
00227 cout << "Sorry, i couldn't understand the command '" << command << "'." << endl << "Please, type 'help' or type the command again." << endl;
00228 }
00229
00230 cout << "Goodbye." << endl;
00231 }
00232
00233 void execute(string line)
00234 {
00235
00236
00237 Scanner s2(line);
00238
00239 string command = s2.next();
00240
00241 if (command == "quit" || command == "q" || command == "exit")
00242 return;
00243
00244 if (command == "version" || command == "v")
00245 {
00246 cout << version() << endl;
00247 return;
00248 }
00249
00250 bool notfound = true;
00251
00252 for (int i = 0; i < modules.size(); i++)
00253 if (command == modules[i]->id())
00254 {
00255 string r = modules[i]->preprocess(dictionary, s2.rest());
00256
00257 if (r == "INVALID_PARAM")
00258 {
00259 cout << "Population size has to be, at least, equal 2.\n";
00260 exit(1);
00261 }
00262
00263 modules[i]->run(modules, &factory, dictionary, r);
00264 notfound = false;
00265 break;
00266 }
00267
00268 if (notfound)
00269 cout << "Sorry, i couldn't understand the command '" << command << "'." << endl << "Please, type 'help' or type the command again." << endl;
00270
00271
00272 }
00273
00274 };
00275
00276 #endif