00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef __moHCMoveLoopExpl_h
00037 #define __moHCMoveLoopExpl_h
00038
00039 #include <moMoveLoopExpl.h>
00040 #include <moMoveInit.h>
00041 #include <moNextMove.h>
00042 #include <moMoveIncrEval.h>
00043 #include <moMoveSelect.h>
00044
00046 template < class M >
00047 class moHCMoveLoopExpl:public moMoveLoopExpl < M >
00048 {
00050 typedef typename M::EOType EOT;
00051
00053 typedef typename M::EOType::Fitness Fitness;
00054
00055 public:
00056
00058
00066 moHCMoveLoopExpl (moMoveInit < M > & _move_initializer, moNextMove < M > & _next_move_generator,
00067 moMoveIncrEval < M > & _incremental_evaluation, moMoveSelect < M > & _move_selection) :
00068 move_initializer (_move_initializer), next_move_generator (_next_move_generator),
00069 incremental_evaluation (_incremental_evaluation), move_selection (_move_selection)
00070 {}
00071
00073
00079 void operator () (const EOT & _old_solution, EOT & _new_solution)
00080 {
00081 M move, best_move;
00082 Fitness best_fitness;
00083 bool has_next_move, selection_update_is_ok;
00084
00085 if( _old_solution.invalid() )
00086 {
00087 throw std::runtime_error("[moHCMoveLoopExpl.h]: The current solution has not been evaluated.");
00088 }
00089
00090
00091
00092
00093
00094
00095 best_fitness=_old_solution.fitness();
00096 move=best_move;
00097
00098
00099 _new_solution=(EOT)_old_solution;
00100
00101
00102 move_initializer(move, _old_solution);
00103
00104 move_selection.init(_old_solution.fitness ());
00105
00106 do
00107 {
00108 selection_update_is_ok = move_selection.update (move, incremental_evaluation(move, _old_solution) );
00109 has_next_move = next_move_generator (move, _old_solution);
00110 }
00111 while ( selection_update_is_ok && has_next_move);
00112
00113
00114 move_selection (best_move, best_fitness);
00115
00116
00117 best_move(_new_solution);
00118
00119
00120 _new_solution.fitness (best_fitness);
00121 }
00122
00123 private:
00124
00126 moMoveInit < M > & move_initializer;
00127
00129 moNextMove < M > & next_move_generator;
00130
00132 moMoveIncrEval < M > & incremental_evaluation;
00133
00135 moMoveSelect < M > & move_selection;
00136 };
00137
00138 #endif