- Main Page
- Classes
- Files

- Search for |

# moHCMoveLoopExpl.h

    00001 /*
    00002   <moHCMoveLoopExpl.h>
    00003   Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008
    00004   (C) OPAC Team, LIFL, 2002-2008
    00005
    00006   Sébastien Cahon, Jean-Charles Boisson (Jean-Charles.Boisson@lifl.fr)
    00007
    00008   This software is governed by the CeCILL license under French law and
    00009   abiding by the rules of distribution of free software.  You can  use,
    00010   modify and/ or redistribute the software under the terms of the CeCILL
    00011   license as circulated by CEA, CNRS and INRIA at the following URL
    00012   "http://www.cecill.info".
    00013
    00014   As a counterpart to the access to the source code and  rights to copy,
    00015   modify and redistribute granted by the license, users are provided only
    00016   with a limited warranty  and the software's author,  the holder of the
    00017   economic rights,  and the successive licensors  have only  limited liability.
    00018
    00019   In this respect, the user's attention is drawn to the risks associated
    00020   with loading,  using,  modifying and/or developing or reproducing the
    00021   software by the user in light of its specific status of free software,
    00022   that may mean  that it is complicated to manipulate,  and  that  also
    00023   therefore means  that it is reserved for developers  and  experienced
    00024   professionals having in-depth computer knowledge. Users are therefore
    00025   encouraged to load and test the software's suitability as regards their
    00026   requirements in conditions enabling the security of their systems and/or
    00027   data to be ensured and,  more generally, to use and operate it in the
    00028   same conditions as regards security.
    00029   The fact that you are presently reading this means that you have had
    00030   knowledge of the CeCILL license and that you accept its terms.
    00031
    00032   ParadisEO WebSite : http://paradiseo.gforge.inria.fr
    00033   Contact: paradiseo-help@lists.gforge.inria.fr
    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       The two following lines are added to avoid compilation warning.
    00092       <=> current best move fitness is the current fitness.
    00093       <=> move and best move are empty for the moment.
    00094     */
    00095     best_fitness=_old_solution.fitness();
    00096     move=best_move;
    00097
    00098     //At the begining, the new sol is equivalent to the old one.
    00099     _new_solution=(EOT)_old_solution;
    00100
    00101     // Restarting the exploration of the neighbourhood
    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     //The selecter gives the value of the best move and the corresponding best fitness.
    00114     move_selection (best_move, best_fitness);
    00115
    00116     //The best move is applied on the new solution.
    00117     best_move(_new_solution);
    00118
    00119     //The fitness is set (avoid an additional fitness compuation).
    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