moTSMoveLoopExpl.h

00001 /*
00002   <moTSMoveLoopExpl.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 _moTSMoveLoopExpl_h
00037 #define _moTSMoveLoopExpl_h
00038 
00039 #include <moMoveLoopExpl.h>
00040 #include <moMoveInit.h>
00041 #include <moNextMove.h>
00042 #include <moMoveIncrEval.h>
00043 #include <moMoveSelect.h>
00044 #include <moTabuList.h>
00045 #include <moAspirCrit.h>
00046 #include <moBestImprSelect.h>
00047 
00049 
00052 template < class M >
00053 class moTSMoveLoopExpl:public moMoveLoopExpl < M >
00054 {
00056   typedef typename M::EOType EOT;
00057 
00059   typedef typename M::EOType::Fitness Fitness;
00060 
00061  public:
00062 
00064 
00071   moTSMoveLoopExpl (moMoveInit < M > & _move_initializer, moNextMove < M > & _next_move_generator,
00072                     moMoveIncrEval < M > & _incremental_evaluation, moTabuList < M > & _tabu_list, 
00073                     moAspirCrit < M > & _aspiration_criterion):
00074   move_initializer(_move_initializer), next_move_generator(_next_move_generator), incremental_evaluation(_incremental_evaluation),
00075     tabu_list(_tabu_list), aspiration_criterion(_aspiration_criterion)
00076   {
00077     tabu_list.init ();
00078     aspiration_criterion.init ();
00079   }
00080   
00082 
00090   void operator () (const EOT & _old_solution, EOT & _new_solution)
00091   {
00092     M move, best_move;
00093     Fitness fitness, best_move_fitness;
00094 
00095     bool move_is_tabu, aspiration_criterion_is_verified, selection_update_is_ok, has_next_move;
00096     
00097     //At the begining, the new solution is equivalent to the old one.
00098     _new_solution=(EOT)_old_solution;
00099 
00100     // Restarting the exploration of  of the neighborhood !
00101     move_initializer (move, _old_solution);     
00102 
00103     move_selection.init( _old_solution.fitness() );
00104 
00105     do
00106       {
00107         fitness = incremental_evaluation(move, _old_solution);
00108 
00109         move_is_tabu = tabu_list(move, _old_solution);
00110 
00111         aspiration_criterion_is_verified = aspiration_criterion(move, fitness);
00112 
00113         if( !move_is_tabu || aspiration_criterion_is_verified )
00114           {
00115             selection_update_is_ok = move_selection.update(move, fitness);
00116           }
00117 
00118         has_next_move = next_move_generator(move, _old_solution);
00119       }
00120     while( has_next_move && selection_update_is_ok );
00121 
00122     move_selection(best_move, best_move_fitness);
00123 
00124     // Apply the best move.
00125     best_move(_new_solution);
00126     
00127     // The fitness is set to avoid an additionnal fitness computation.
00128     _new_solution.fitness(best_move_fitness);
00129       
00130     // Removing moves that are no more tabu.
00131     tabu_list.update ();
00132     
00133     // Updating the tabu list
00134     tabu_list.add(best_move, _new_solution);
00135   }
00136 
00137  private:
00138 
00140   moMoveInit < M > & move_initializer;
00141 
00143   moNextMove < M > & next_move_generator;
00144 
00146   moMoveIncrEval < M > & incremental_evaluation;
00147 
00149   moBestImprSelect < M > move_selection;
00150 
00152   moTabuList < M > & tabu_list;
00153 
00155   moAspirCrit < M > & aspiration_criterion;
00156 };
00157 
00158 #endif

Generated on Tue Jan 15 16:46:12 2008 for ParadisEO-MOMovingObjects by  doxygen 1.5.4