moILS.h

00001 /* 
00002 * <moILS.h>
00003 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
00004 * (C) OPAC Team, LIFL, 2002-2007
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 
00037 #ifndef __moILS_h
00038 #define __moILS_h
00039 
00040 #include <eoEvalFunc.h>
00041 
00042 #include "moHC.h"
00043 #include "moTS.h"
00044 #include "moSA.h"
00045 
00047 
00050 template < class M > class moILS:public moAlgo < typename M::EOType >
00051 {
00052 
00054   typedef typename M::EOType EOT;
00055   
00057   typedef typename EOT::Fitness Fitness;
00058 
00059 public:
00060 
00062 
00071   moILS (moAlgo<EOT> &__algo, moSolContinue <EOT> &__continue, moComparator<EOT> &__acceptance_criterion, eoMonOp<EOT> &__perturbation, 
00072          eoEvalFunc<EOT> &__full_eval):
00073     algo(__algo), cont(__continue), acceptance_criterion(__acceptance_criterion), perturbation(__perturbation), full_eval(__full_eval)
00074   {}
00075 
00077 
00087   moILS (moMoveInit < M > &__move_init, moNextMove < M > &__next_move, moMoveIncrEval < M > &__incr_eval,
00088          moMoveSelect < M > &__move_select, moSolContinue <EOT> &__continue, moComparator<EOT> &__acceptance_criterion, 
00089          eoMonOp<EOT> &__perturbation, eoEvalFunc<EOT> &__full_eval):
00090     algo(*new moHC<M>(__move_init, __next_move, __incr_eval, __move_select, __full_eval)), cont(__continue), 
00091     acceptance_criterion(__acceptance_criterion), perturbation(__perturbation), full_eval(__full_eval)
00092   {}
00093 
00095 
00107   moILS (moMoveInit <M> &__move_init, moNextMove <M> &__next_move, moMoveIncrEval <M> &__incr_eval,
00108          moTabuList <M> &__tabu_list, moAspirCrit <M> &__aspir_crit, moSolContinue <EOT> &__moTS_continue, 
00109          moSolContinue <EOT> &__continue, moComparator<EOT> &__acceptance_criterion, eoMonOp<EOT> &__perturbation, 
00110          eoEvalFunc<EOT> &__full_eval):
00111     algo(*new moTS<M>(__move_init, __next_move, __incr_eval, __tabu_list, __aspir_crit, __moTS_continue, __full_eval)), 
00112     cont(__continue), acceptance_criterion(__acceptance_criterion), perturbation(__perturbation), full_eval(__full_eval)
00113   {}
00114 
00116 
00127   moILS (moRandMove<M> &__move_rand, moMoveIncrEval <M> &__incr_eval, moSolContinue <EOT> &__moSA_continue, double __init_temp,
00128          moCoolingSchedule & __cool_sched, moSolContinue <EOT> &__continue, moComparator<EOT> &__acceptance_criterion, 
00129          eoMonOp<EOT> &__perturbation, eoEvalFunc<EOT> &__full_eval):
00130     algo(*new moSA<M>(__move_rand, __incr_eval, __moSA_continue, __init_temp, __cool_sched, __full_eval)), 
00131     cont(__continue), acceptance_criterion(__acceptance_criterion), perturbation(__perturbation), full_eval(__full_eval)
00132   {}
00133 
00134 
00135 
00137 
00144   bool operator()(EOT & __sol)
00145   {
00146     EOT __sol_saved=__sol;
00147             
00148     cont.init ();
00149 
00150     //some code has been duplicated in order to avoid one perturbation and one evaluation without adding a test in the loop.
00151     // better than a do {} while; with a test in the loop.
00152 
00153     algo(__sol);
00154         
00155     if(acceptance_criterion(__sol, __sol_saved))
00156       {
00157         __sol_saved=__sol;
00158         
00159       }
00160     else
00161       {
00162         __sol=__sol_saved;
00163       }
00164     
00165     while (cont (__sol))
00166     {
00167       perturbation(__sol);
00168       full_eval(__sol);
00169       
00170       algo(__sol);
00171             
00172       if(acceptance_criterion(__sol, __sol_saved))
00173         {
00174           __sol_saved=__sol;
00175         }
00176       else
00177         {
00178           __sol=__sol_saved;
00179         }
00180     }
00181     
00182     return true;
00183   }
00184 
00185 private:
00186 
00188   moAlgo<EOT> &algo;
00189 
00191   moSolContinue<EOT> &cont;
00192 
00194   moComparator<EOT> &acceptance_criterion;
00195 
00197   eoMonOp<EOT> &perturbation;
00198   
00200   eoEvalFunc<EOT> &full_eval;
00201 };
00202 
00203 #endif

Generated on Tue Oct 23 15:29:27 2007 for ParadisEO-MOMovingObjects by  doxygen 1.5.2