00001 #ifndef HEURISTICFACTORY_HPP_
00002 #define HEURISTICFACTORY_HPP_
00003
00004 #include <iostream>
00005
00006 using namespace std;
00007
00008 #include "./Util/Scanner++/Scanner.h"
00009
00010 #include "RandGen.hpp"
00011
00012 #include "Heuristic.hpp"
00013
00014 #include "Heuristic/Empty.hpp"
00015
00016
00017 #include "Heuristic/RandomDescentMethod.hpp"
00018 #include "Heuristic/HillClimbing.hpp"
00019 #include "Heuristic/BestImprovement.hpp"
00020 #include "Heuristic/FirstImprovement.hpp"
00021 #include "Heuristic/VariableNeighborhoodDescent.hpp"
00022 #include "Heuristic/RVND.hpp"
00023
00024
00025 #include "Heuristic/IteratedLocalSearch.hpp"
00026 #include "Heuristic/IteratedLocalSearchLevels.hpp"
00027 #include "Heuristic/IntensifiedIteratedLocalSearchLevels.hpp"
00028 #include "Heuristic/Intensification.hpp"
00029 #include "Heuristic/MultiHeuristic.hpp"
00030 #include "Heuristic/GRASP.hpp"
00031 #include "Heuristic/TabuSearch.hpp"
00032 #include "Heuristic/EvolutionaryAlgorithms/GeneticAlgorithm.hpp"
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 template<class R, class M = OPTFRAME_DEFAULT_MEMORY>
00061 class HeuristicFactory
00062 {
00063 private:
00064 vector<InitialSolution<R>*> initsol;
00065 vector<NS<R, M>*> ns;
00066 vector<Evaluator<R, M>*> ev;
00067 vector<ILSLPerturbation<R, M>*> ilsl_pert;
00068 vector<Intensification<R, M>*> ils_int;
00069
00070 vector<Solution<R>*> loadsol;
00071 vector<Heuristic<R, M>*> method;
00072
00073 vector<InitialPopulation<R>*> initpop;
00074 vector<Selection<R, M>*> ga_sel;
00075 vector<Mutation<R, M>*> ga_mut;
00076 vector<Crossover<R, M>*> ga_cross;
00077 vector<Elitism<R, M>*> ga_elt;
00078
00079
00080
00081
00082 vector<Population<R>*> loadpop;
00083
00084 RandGen& rg;
00085
00086 public:
00087
00088 #ifdef MaPI
00089 MyMaPISerializer<R, M> * serializer;
00090 MaPI_MapReduce<R, RankAndStop, int, pair<R, double> , R> * mapReduce;
00091 MyMaPIMapper<R, M> * mapper;
00092 MyMaPIReducer<R, M> * reducer;
00093 int argc;
00094 char **argv;
00095
00096 void setMapReduce(MyMaPISerializer<R, M> * serializer, MaPI_MapReduce<R, RankAndStop, int, pair<R, double> , R> * mapReduce,
00097 MyMaPIMapper<R, M> * mapper,MyMaPIReducer<R, M> * reducer,int argc, char **argv)
00098 {
00099 this->serializer = serializer;
00100 this->mapReduce = mapReduce;
00101 this->mapper = mapper;
00102 this->reducer = reducer;
00103 this->argc = argc;
00104 this->argv = argv;
00105 }
00106 #endif
00107
00108 Solution<R>* read_loadsol(Scanner* scanner)
00109 {
00110
00111
00112 string tmp = scanner->next();
00113
00114 if (tmp != "loadsol")
00115 cout << "Warning: expected 'loadsol' and found '" << tmp << "'." << endl;
00116
00117 int loadsol_id = scanner->nextInt();
00118
00119 if (loadsol.size() <= loadsol_id)
00120 {
00121 cout << "Error: solution number " << loadsol_id << " doesn't exist!" << endl;
00122 exit(1);
00123 }
00124
00125 return loadsol[loadsol_id];
00126 }
00127
00128 InitialSolution<R>* read_initsol(Scanner* scanner)
00129 {
00130 string tmp = scanner->next();
00131
00132 if (tmp != "initsol")
00133 cout << "Warning: expected 'initsol' and found '" << tmp << "'." << endl;
00134
00135 int initsol_id = scanner->nextInt();
00136
00137 if (initsol.size() <= initsol_id)
00138 {
00139 cout << "Error: init number " << initsol_id << " doesn't exist!" << endl;
00140 exit(1);
00141 }
00142
00143 return initsol[initsol_id];
00144 }
00145
00146 Population<R>* read_loadpop(Scanner* scanner)
00147 {
00148 string tmp = scanner->next();
00149
00150 if (tmp != "loadpop")
00151 cout << "Warning: expected 'loadpop' and found '" << tmp << "'." << endl;
00152
00153 int loadpop_id = scanner->nextInt();
00154
00155 if (loadpop.size() <= loadpop_id)
00156 {
00157 cout << "Error: solution number " << loadpop_id << " doesn't exist!" << endl;
00158 exit(1);
00159 }
00160
00161 return loadpop[loadpop_id];
00162 }
00163
00164 InitialPopulation<R>* read_initpop(Scanner* scanner)
00165 {
00166 string tmp = scanner->next();
00167
00168 if (tmp != "initpop")
00169 cout << "Warning: expected 'initpop' and found '" << tmp << "'." << endl;
00170
00171 int initpop_id = scanner->nextInt();
00172
00173 if (initpop.size() <= initpop_id)
00174 {
00175 cout << "Error: init number " << initpop_id << " doesn't exist!" << endl;
00176 exit(1);
00177 }
00178
00179 return initpop[initpop_id];
00180 }
00181
00182 NS<R, M>* read_ns(Scanner* scanner)
00183 {
00184 string tmp = scanner->next();
00185
00186 if (tmp != "ns")
00187 cout << "Warning: expected 'ns' and found '" << tmp << "'." << endl;
00188
00189 int ns_id = scanner->nextInt();
00190
00191 if (ns.size() <= ns_id)
00192 {
00193 cout << "Error: ns number " << ns_id << " doesn't exist!" << endl;
00194 exit(1);
00195 }
00196
00197 return ns[ns_id];
00198 }
00199
00200 int read_np(Scanner* scanner)
00201 {
00202 string tmp = scanner->next();
00203
00204 if (tmp != "np")
00205 cout << "Warning: expected 'np' and found '" << tmp << "'." << endl;
00206
00207 int np = scanner->nextInt();
00208
00209 if (np <= 1)
00210 {
00211 cout << "Error: number or processes " << np << " must be greater than or equal 2" << endl;
00212 exit(1);
00213 }
00214
00215 return np;
00216 }
00217
00218 vector<NS<R, M>*> read_ns_list(Scanner* scanner)
00219 {
00220 string tmp = scanner->next();
00221
00222 vector<NS<R, M>*> v_ns;
00223
00224 if (tmp != "[")
00225 {
00226 cout << "Error: expected '[' and found '" << tmp << "'!" << endl;
00227
00228 if (tmp == "ns")
00229 {
00230 int ns_id = scanner->nextInt();
00231
00232 if (ns.size() <= ns_id)
00233 {
00234 cout << "Error: ns number " << ns_id << " doesn't exist!" << endl;
00235 exit(1);
00236 }
00237
00238 v_ns.push_back(ns[ns_id]);
00239 }
00240
00241 return v_ns;
00242 }
00243
00244 tmp = scanner->next();
00245
00246 while (tmp != "]")
00247 {
00248 if (tmp != "ns")
00249 cout << "Warning: expected 'ns' and found '" << tmp << "'." << endl;
00250
00251 int ns_id = scanner->nextInt();
00252
00253 if (ns.size() <= ns_id)
00254 {
00255 cout << "Error: ns number " << ns_id << " doesn't exist!" << endl;
00256 exit(1);
00257 }
00258
00259 v_ns.push_back(ns[ns_id]);
00260
00261 tmp = scanner->next();
00262 }
00263
00264 if (v_ns.size() == 0)
00265 {
00266 cout << "Error: empty ns list." << endl;
00267 exit(1);
00268 }
00269
00270 return v_ns;
00271 }
00272
00273 vector<Evaluator<R, M> *> read_ev_list(Scanner* scanner)
00274 {
00275 string tmp = scanner->next();
00276
00277 vector<Evaluator<R, M> *> v_ev;
00278
00279 if (tmp != "[")
00280 {
00281 cout << "Error: expected '[' and found '" << tmp << "'." << endl;
00282 exit(1);
00283 }
00284
00285 tmp = scanner->next();
00286
00287 while (tmp != "]")
00288 {
00289 if (tmp != "ev")
00290 cout << "Warning: expected 'ev' and found '" << tmp << "'." << endl;
00291
00292 int ev_id = scanner->nextInt();
00293
00294 if (ev.size() <= ev_id)
00295 {
00296 cout << "Error: ev number " << ev_id << " doesn't exist!" << endl;
00297 exit(1);
00298 }
00299
00300 v_ev.push_back(ev[ev_id]);
00301
00302 tmp = scanner->next();
00303 }
00304
00305 if (v_ev.size() == 0)
00306 {
00307 cout << "Error: empty ev list." << endl;
00308 exit(1);
00309 }
00310
00311 return v_ev;
00312 }
00313
00314 vector<Heuristic<R, M>*> read_heuristic_list(Scanner* scanner)
00315 {
00316 string tmp = scanner->next();
00317
00318 vector<Heuristic<R, M>*> v_heuristics;
00319
00320 if (tmp != "[")
00321 {
00322 cout << "Error: expected '[' and found '" << tmp << "'!" << endl;
00323
00324 return v_heuristics;
00325 }
00326
00327 pair<Heuristic<R, M>*, string> method;
00328
00329 string rest = scanner->rest();
00330
00331 while (rest[1] != ']')
00332 {
00333
00334 if (rest.empty())
00335 break;
00336
00337 method = createHeuristic(rest);
00338
00339 v_heuristics.push_back(method.first);
00340
00341 rest = method.second;
00342
00343 }
00344
00345 if (v_heuristics.size() == 0)
00346 {
00347 cout << "Error: empty heuristic list." << endl;
00348 return v_heuristics;
00349 }
00350
00351 (*scanner) = Scanner(rest);
00352
00353 if (scanner->next() != "]")
00354 cout << "Warning: expected ']'." << endl;
00355
00356 return v_heuristics;
00357 }
00358
00359 Evaluator<R, M>* read_ev(Scanner* scanner)
00360 {
00361 string tmp = scanner->next();
00362
00363 if (tmp == "moev")
00364 {
00365 vector<Evaluator<R, M> *> evs = read_ev_list(scanner);
00366
00367 MultiObjectiveEvaluator<R, M>* moev = new MultiObjectiveEvaluator<R, M> (*evs[0]);
00368
00369 for (int i = 1; i < evs.size(); i++)
00370 moev->add(*evs[i]);
00371
00372 return moev;
00373 }
00374 else if (tmp != "ev")
00375 cout << "Warning: expected 'ev' and found '" << tmp << "'." << endl;
00376
00377 int ev_id = scanner->nextInt();
00378
00379 if (ev.size() <= ev_id)
00380 {
00381 cout << "Error: ev number " << ev_id << " doesn't exist!" << endl;
00382 exit(1);
00383 }
00384
00385 return ev[ev_id];
00386 }
00387
00388 ILSLPerturbation<R, M>* read_ilsl_pert(Scanner* scanner)
00389 {
00390 string tmp = scanner->next();
00391
00392 if (tmp != "ilsl_pert")
00393 cout << "Warning: expected 'ilsl_pert' and found '" << tmp << "'." << endl;
00394
00395 int ilsl_pert_id = scanner->nextInt();
00396
00397 if (ilsl_pert.size() <= ilsl_pert_id)
00398 {
00399 cout << "Error: 'perturbation levels' number " << ilsl_pert_id << " doesn't exist!" << endl;
00400 exit(1);
00401 }
00402
00403 return ilsl_pert[ilsl_pert_id];
00404 }
00405
00406 Intensification<R, M> * read_ils_int(Scanner* scanner)
00407 {
00408 string tmp = scanner->next();
00409
00410 if (tmp != "ils_int")
00411 cout << "Warning: expected 'ils_int' and found '" << tmp << "'." << endl;
00412
00413 int ils_int_id = scanner->nextInt();
00414
00415 if (ils_int.size() <= ils_int_id)
00416 {
00417 cout << "Error: 'intensification' number " << ils_int_id << " doesn't exist!" << endl;
00418 exit(1);
00419 }
00420
00421 return ils_int[ils_int_id];
00422 }
00423
00424 Selection<R, M>* read_ga_sel(Scanner* scanner)
00425 {
00426 string tmp = scanner->next();
00427
00428 if (tmp != "ga_sel")
00429 cout << "Warning: expected 'ga_sel' and found '" << tmp << "'." << endl;
00430
00431 int ga_sel_id = scanner->nextInt();
00432
00433 if (ga_sel.size() <= ga_sel_id)
00434 {
00435 cout << "Error: 'genetic selection' number " << ga_sel_id << " doesn't exist!" << endl;
00436 exit(1);
00437 }
00438
00439 return ga_sel[ga_sel_id];
00440 }
00441
00442 Mutation<R, M>* read_ga_mut(Scanner* scanner)
00443 {
00444 string tmp = scanner->next();
00445
00446 if (tmp != "ga_mut")
00447 cout << "Warning: expected 'ga_mut' and found '" << tmp << "'." << endl;
00448
00449 int ga_mut_id = scanner->nextInt();
00450
00451 if (ga_mut.size() <= ga_mut_id)
00452 {
00453 cout << "Error: 'genetic mutation' number " << ga_mut_id << " doesn't exist!" << endl;
00454 exit(1);
00455 }
00456
00457 return ga_mut[ga_mut_id];
00458 }
00459
00460 Elitism<R, M>* read_ga_elt(Scanner* scanner)
00461 {
00462 string tmp = scanner->next();
00463
00464 if (tmp != "ga_elt")
00465 cout << "Warning: expected 'ga_elt' and found '" << tmp << "'." << endl;
00466
00467 int ga_elt_id = scanner->nextInt();
00468
00469 if (ga_elt.size() <= ga_elt_id)
00470 {
00471 cout << "Error: 'genetic elitism' number " << ga_elt_id << " doesn't exist!" << endl;
00472 exit(1);
00473 }
00474
00475 return ga_elt[ga_elt_id];
00476 }
00477
00478 Crossover<R, M>* read_ga_cross(Scanner* scanner)
00479 {
00480 string tmp = scanner->next();
00481
00482 if (tmp != "ga_cross")
00483 cout << "Warning: expected 'ga_cross' and found '" << tmp << "'." << endl;
00484
00485 int ga_cross_id = scanner->nextInt();
00486
00487 if (ga_cross.size() <= ga_cross_id)
00488 {
00489 cout << "Error: 'genetic crossover' number " << ga_cross_id << " doesn't exist!" << endl;
00490 exit(1);
00491 }
00492
00493 return ga_cross[ga_cross_id];
00494 }
00495
00496
00497
00498
00499 HeuristicFactory(RandGen& _rg) :
00500 rg(_rg)
00501 {
00502 }
00503
00504 ~HeuristicFactory()
00505 {
00506 }
00507
00508 int add_method(Heuristic<R, M>* _method)
00509 {
00510 method.push_back(_method);
00511 return method.size() - 1;
00512 }
00513
00514 int add_methods(vector<Heuristic<R, M>*>& _methods)
00515 {
00516 for (int i = 0; i < _methods.size(); ++i)
00517 {
00518 cout << "\'method " << i << "\' added." << endl;
00519 method.push_back(_methods.at(i));
00520 }
00521 return method.size() - 1;
00522
00523 }
00524
00525 Heuristic<R, M>* get_method(int index)
00526 {
00527 return method[index];
00528 }
00529
00530 int add_loadsol(Solution<R>* _loadsol)
00531 {
00532 loadsol.push_back(_loadsol);
00533 return loadsol.size() - 1;
00534 }
00535
00536 Solution<R>* get_loadsol(int index)
00537 {
00538 return loadsol[index];
00539 }
00540
00541 int add_initsol(InitialSolution<R>* _initsol)
00542 {
00543 initsol.push_back(_initsol);
00544 return initsol.size() - 1;
00545 }
00546
00547 int add_loadpop(Population<R>* _loadpop)
00548 {
00549 loadpop.push_back(_loadpop);
00550 return loadpop.size() - 1;
00551 }
00552
00553 Population<R>* get_loadpop(int index)
00554 {
00555 return loadpop[index];
00556 }
00557
00558 int add_initpop(InitialPopulation<R>* _initpop)
00559 {
00560 initpop.push_back(_initpop);
00561 return initpop.size() - 1;
00562 }
00563
00564 InitialSolution<R>* get_initsol(int index)
00565 {
00566 return initsol[index];
00567 }
00568
00569 Population<R>* get_initpop(int index)
00570 {
00571 return initpop[index];
00572 }
00573
00574 int add_ns(NS<R, M>* _ns)
00575 {
00576 ns.push_back(_ns);
00577 return ns.size() - 1;
00578 }
00579
00580 NS<R, M>* get_ns(int index)
00581 {
00582 return ns[index];
00583 }
00584
00585 int add_ev(Evaluator<R, M>* _ev)
00586 {
00587 ev.push_back(_ev);
00588 return ev.size() - 1;
00589 }
00590
00591 Evaluator<R, M>* get_ev(int index)
00592 {
00593 return ev[index];
00594 }
00595
00596 int add_ilsl_pert(ILSLPerturbation<R, M>* _ilsl_pert)
00597 {
00598 ilsl_pert.push_back(_ilsl_pert);
00599 return ilsl_pert.size() - 1;
00600 }
00601
00602 void add_ils_int(Intensification<R, M>* _ils_int)
00603 {
00604 ils_int.push_back(_ils_int);
00605 }
00606
00607 ILSLPerturbation<R, M>* get_ilsl_pert(int index)
00608 {
00609 return ilsl_pert[index];
00610 }
00611
00612 int add_ga_mut(Mutation<R, M>* _ga_mut)
00613 {
00614 ga_mut.push_back(_ga_mut);
00615 return ga_mut.size() - 1;
00616 }
00617
00618 Mutation<R, M>* get_ga_mut(int index)
00619 {
00620 return ga_mut[index];
00621 }
00622
00623 int add_ga_sel(Selection<R, M>* _ga_sel)
00624 {
00625 ga_sel.push_back(_ga_sel);
00626 return ga_sel.size() - 1;
00627 }
00628
00629 int add_ga_elt(Elitism<R, M>* _ga_elt)
00630 {
00631 ga_elt.push_back(_ga_elt);
00632 return ga_elt.size() - 1;
00633 }
00634
00635 Selection<R, M>* get_ga_sel(int index)
00636 {
00637 return ga_sel[index];
00638 }
00639
00640 Elitism<R, M>* get_ga_elt(int index)
00641 {
00642 return ga_elt[index];
00643 }
00644
00645 int add_ga_cross(Crossover<R, M>* _ga_cross)
00646 {
00647 ga_cross.push_back(_ga_cross);
00648 return ga_cross.size() - 1;
00649 }
00650
00651 Crossover<R, M>* get_ga_cross(int index)
00652 {
00653 return ga_cross[index];
00654 }
00655
00656 int initsol_size()
00657 {
00658 return initsol.size();
00659 }
00660
00661 int initpop_size()
00662 {
00663 return initpop.size();
00664 }
00665
00666 int ns_size()
00667 {
00668 return ns.size();
00669 }
00670
00671 int ev_size()
00672 {
00673 return ev.size();
00674 }
00675
00676 int loadsol_size()
00677 {
00678 return loadsol.size();
00679 }
00680
00681 int loadpop_size()
00682 {
00683 return loadpop.size();
00684 }
00685
00686 int method_size()
00687 {
00688 return method.size();
00689 }
00690
00691 pair<Heuristic<R, M>*, string> createHeuristic(string str)
00692 {
00693 Scanner scanner(str);
00694
00695
00696 if (!scanner.hasNext())
00697 return make_pair(new Empty<R, M> , "");
00698
00699 string h = scanner.next();
00700
00701 if (h == "method")
00702 {
00703 int id = scanner.nextInt();
00704 return make_pair(method[id], scanner.rest());
00705 }
00706
00707 if (h == "Empty")
00708 return make_pair(new Empty<R, M> , scanner.rest());
00709
00710 if (h == "BI")
00711 {
00712 cout << "Heuristic: Best Improvement" << endl;
00713
00714 Evaluator<R, M>* evaluator = read_ev(&scanner);
00715 NSSeq<R, M>* ns_seq = (NSSeq<R, M>*) read_ns(&scanner);
00716
00717 return make_pair(new BestImprovement<R, M> (*evaluator, *ns_seq), scanner.rest());
00718 }
00719
00720 if (h == "FI")
00721 {
00722 cout << "Heuristic: First Improvement" << endl;
00723
00724 Evaluator<R, M>* evaluator = read_ev(&scanner);
00725 NSSeq<R, M>* ns_seq = (NSSeq<R, M>*) read_ns(&scanner);
00726
00727 return make_pair(new FirstImprovement<R, M> (*evaluator, *ns_seq), scanner.rest());
00728 }
00729
00730 if (h == "HC")
00731 {
00732 cout << "Heuristic: Hill Climbing" << endl;
00733
00734 Evaluator<R, M>* evaluator = read_ev(&scanner);
00735
00736 string rest = scanner.rest();
00737
00738 pair<Heuristic<R, M>*, string> method;
00739 method = createHeuristic(rest);
00740
00741 Heuristic<R, M>* h = method.first;
00742
00743 scanner = Scanner(method.second);
00744
00745 return make_pair(new HillClimbing<R, M> (*evaluator, *h), scanner.rest());
00746 }
00747
00748 if (h == "RDM")
00749 {
00750 cout << "Heuristic: Random Descent Method" << endl;
00751
00752 Evaluator<R, M>* evaluator = read_ev(&scanner);
00753 NS<R, M>* ns = (NS<R, M>*) read_ns(&scanner);
00754 int iter = scanner.nextInt();
00755
00756 return make_pair(new RandomDescentMethod<R, M> (*evaluator, *ns, iter), scanner.rest());
00757 }
00758
00759 if (h == "GRASP")
00760 {
00761 cout << "Heuristic: GRASP" << endl;
00762
00763 Evaluator<R, M>* evaluator = read_ev(&scanner);
00764 InitialSolution<R>* initsol = read_initsol(&scanner);
00765
00766 string rest = scanner.rest();
00767
00768 pair<Heuristic<R, M>*, string> method;
00769 method = createHeuristic(rest);
00770
00771 Heuristic<R, M>* h = method.first;
00772
00773 scanner = Scanner(method.second);
00774
00775 int iter = scanner.nextInt();
00776
00777 return make_pair(new GRASP<R, M> (*evaluator, *initsol, *h, iter), scanner.rest());
00778 }
00779
00780 if (h == "TS")
00781 {
00782 cout << "Heuristic: Tabu Search" << endl;
00783
00784 Evaluator<R, M>* evaluator = read_ev(&scanner);
00785 NSSeq<R, M>* ns = (NSSeq<R, M>*) read_ns(&scanner);
00786 int tamT = scanner.nextInt();
00787 int BTmax = scanner.nextInt();
00788
00789 return make_pair(new TabuSearch<R, M> (*evaluator, *ns, tamT, BTmax), scanner.rest());
00790 }
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824 if (h == "ILSL")
00825 {
00826 cout << "Heuristic: Iterated Local Search (Levels)" << endl;
00827
00828 Evaluator<R, M>* evaluator = read_ev(&scanner);
00829
00830
00831
00832
00833
00834 string rest = scanner.rest();
00835
00836 pair<Heuristic<R, M>*, string> method;
00837 method = createHeuristic(rest);
00838
00839 Heuristic<R, M>* localSearch = method.first;
00840
00841 scanner = Scanner(method.second);
00842
00843
00844
00845 ILSLPerturbation<R, M>* ilsl_pert = read_ilsl_pert(&scanner);
00846
00847 int iterMax = scanner.nextInt();
00848 int levelMax = scanner.nextInt();
00849
00850 return make_pair(new IteratedLocalSearchLevels<R, M> (*evaluator, *localSearch, *ilsl_pert, iterMax, levelMax), scanner.rest());
00851 }
00852
00853 if (h == "IILSL")
00854 {
00855 cout << "Heuristic: Intensified Iterated Local Search (Levels)" << endl;
00856
00857 Evaluator<R, M>* evaluator = read_ev(&scanner);
00858
00859
00860
00861
00862
00863 string rest = scanner.rest();
00864
00865 pair<Heuristic<R, M>*, string> method;
00866 method = createHeuristic(rest);
00867
00868 Heuristic<R, M>* localSearch = method.first;
00869
00870 scanner = Scanner(method.second);
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883 Intensification<R, M> * intensification = read_ils_int(&scanner);
00884
00885
00886
00887 ILSLPerturbation<R, M>* ilsl_pert = read_ilsl_pert(&scanner);
00888
00889 int iterMax = scanner.nextInt();
00890 int levelMax = scanner.nextInt();
00891
00892
00893 return make_pair(new IntensifiedIteratedLocalSearchLevels<R, M> (*evaluator, *localSearch, *intensification, *ilsl_pert, iterMax, levelMax), scanner.rest());
00894 }
00895
00896 if (h == "VND")
00897 {
00898 cout << "Heuristic: Variable Neighborhood Descent" << endl;
00899
00900 Evaluator<R, M>* evaluator = read_ev(&scanner);
00901 vector<Heuristic<R, M>*> hlist = read_heuristic_list(&scanner);
00902 add_methods(hlist);
00903
00904 return make_pair(new VariableNeighborhoodDescent<R, M> (*evaluator, hlist), scanner.rest());
00905
00906 }
00907
00908 if (h == "RVND")
00909 {
00910 cout << "Heuristic: RVND" << endl;
00911
00912 Evaluator<R, M>* evaluator = read_ev(&scanner);
00913 vector<Heuristic<R, M>*> hlist = read_heuristic_list(&scanner);
00914 add_methods(hlist);
00915
00916 return make_pair(new RVND<R, M> (*evaluator, hlist, rg), scanner.rest());
00917 }
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968 if (h == "MH")
00969 {
00970 cout << "Heuristic: MultiHeuristic" << endl;
00971
00972 Evaluator<R, M>* evaluator = read_ev(&scanner);
00973 vector<Heuristic<R, M>*> hlist = read_heuristic_list(&scanner);
00974 add_methods(hlist);
00975
00976 return make_pair(new MultiHeuristic<R, M> (*evaluator, hlist), scanner.rest());
00977 }
00978
00979 #ifdef MaPI
00980 if (h == "MapReduce")
00981 {
00982 cout << "Heuristic: MapReduce" << endl;
00983
00984 Evaluator<R, M>* evaluator = read_ev(&scanner);
00985
00986
00987
00988
00989
00990 string rest = scanner.rest();
00991
00992 pair<Heuristic<R, M>*, string> method;
00993 method = createHeuristic(rest);
00994
00995 Heuristic<R, M>* hmap = method.first;
00996
00997 scanner = Scanner(method.second);
00998
00999
01000
01001
01002
01003 rest = scanner.rest();
01004
01005 method = createHeuristic(rest);
01006
01007 Heuristic<R, M>* hreduce = method.first;
01008
01009 scanner = Scanner(method.second);
01010
01011
01012 mapper->setHeuristic(hmap);
01013 reducer->setHeuristic(hreduce);
01014
01015 return make_pair(new OptFrameMapReduce<R, M> (*serializer,*mapReduce,*mapper,*reducer,*evaluator), scanner.rest());
01016 }
01017
01018 if (h == "Map")
01019 {
01020 cout << "Heuristic: Map" << endl;
01021
01022 Evaluator<R, M>* evaluator = read_ev(&scanner);
01023
01024
01025
01026
01027
01028 string rest = scanner.rest();
01029
01030 pair<Heuristic<R, M>*, string> method;
01031 method = createHeuristic(rest);
01032
01033 Heuristic<R, M>* hmap = method.first;
01034
01035 scanner = Scanner(method.second);
01036
01037
01038 mapper->setHeuristic(hmap);
01039
01040
01041
01042 return make_pair(new OptFrameMapReduce<R, M> (*serializer,*mapReduce,*mapper,*reducer,*evaluator), scanner.rest());
01043 }
01044 #endif
01045
01046 cout << "Warning: no heuristic '" << h << "' found! ignoring..." << endl;
01047
01048 return make_pair(new Empty<R, M> , scanner.rest());
01049 }
01050
01051 };
01052
01053 #endif