00001 #ifndef MULTIHEURISTIC_HPP_
00002 #define MULTIHEURISTIC_HPP_
00003
00004 #include <math.h>
00005 #include <vector>
00006
00007 #include "../Heuristic.hpp"
00008 #include "../NS.hpp"
00009 #include "../Evaluator.hpp"
00010 #include "../Solution.hpp"
00011
00012
00013
00014 #ifdef METHOD_DEBUG
00015 #define MULTIHEURISTIC_DEBUG
00016 #endif
00017
00018
00019 template<class R, class M>
00020 class MultiHeuristic : public Heuristic<R,M>
00021 {
00022 public:
00023 using Heuristic<R, M>::exec;
00024
00025 MultiHeuristic(Evaluator<R, M>& _ev, vector<Heuristic<R, M>*> _heuristics) :
00026 ev(_ev), heuristics(_heuristics)
00027 {
00028 }
00029
00030 virtual void exec(Solution<R>& s, double timelimit, double target_f)
00031 {
00032 Evaluation<M>& e = ev.evaluate(s.getR());
00033 exec(s, e, timelimit, target_f);
00034 delete &e;
00035 }
00036
00037 virtual void exec(Solution<R>& s, Evaluation<M>& e, double timelimit, double target_f)
00038 {
00039 cerr << "MultiHeuristic exec("<<target_f<<","<<timelimit<<")" << endl;
00040
00041 cout << "MultiHeuristic Initial Solution: " ; e.print();
00042 cout << heuristics.size() << endl;
00043
00044 long tatual;
00045
00046 for (int h = 0; h < heuristics.size(); h++)
00047 {
00048 cerr << "MultiHeuristic iter "<<h<<":"<<endl;
00049 (heuristics)[h]->exec(s,timelimit, target_f);
00050 }
00051 }
00052
00053 private:
00054 Evaluator<R,M>& ev;
00055 vector< Heuristic<R,M>* > heuristics;
00056 };
00057
00058 #endif