00001 #ifndef BUILDMODULE_HPP_
00002 #define BUILDMODULE_HPP_
00003
00004 #include "../OptFrameModule.hpp"
00005
00006 template<class R, class M>
00007 class BuildModule: public OptFrameModule<R, M>
00008 {
00009 public:
00010 string id()
00011 {
00012 return "build";
00013 }
00014 string usage()
00015 {
00016 string u = "build method [my_method_name]\n";
00017 u += " eg.\n";
00018 u += "\tbuild BI ev id ns id my_Best_Improvement\n";
00019 u += "\tbuild FI ev id ns id my_First_Improvement\n";
00020 u += "\tbuild HC ev id BI ev id ns id my_HillClimbing_BI\n";
00021 u += "\tbuild HC ev id my_First_Improvement my_HillClimbing_FI\n";
00022 u += "\tbuild GA ev id initpop id <crossover rate> <mutation rate> <population size> <number of generations> ga_sel id ga_cross id ga_mut id my_GA\n";
00023
00024 return u;
00025 }
00026
00027 void run(vector<OptFrameModule<R, M>*> all_modules, HeuristicFactory<R, M>* factory, map<string, string>* dictionary, string input)
00028 {
00029 cout << "build: " << input << endl;
00030 Scanner scanner(input);
00031
00032 if (!scanner.hasNext())
00033 {
00034 cout << "Usage: " << usage() << endl;
00035 return;
00036 }
00037
00038 pair<Heuristic<R, M>*, string> method = factory->createHeuristic(scanner.rest());
00039
00040 scanner = Scanner(method.second);
00041
00042 int new_id = factory->add_method(method.first);
00043
00044 stringstream str;
00045 str << "method " << new_id;
00046 string s_new_id = str.str();
00047
00048 cout << "'" << s_new_id << "' added." << endl;
00049
00050 if (scanner.hasNext())
00051 {
00052 string new_name = scanner.next();
00053 run_module("define", all_modules, factory, dictionary, new_name + " " + s_new_id);
00054 }
00055
00056 }
00057
00058 };
00059
00060 #endif