moILS.h

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 // "moILS.h"
00004 
00005 // (c) OPAC Team, LIFL, 2003-2007
00006 
00007 /* LICENCE TEXT
00008    
00009    Contact: paradiseo-help@lists.gforge.inria.fr
00010 */
00011 
00012 #ifndef __moILS_h
00013 #define __moILS_h
00014 
00015 #include <eoEvalFunc.h>
00016 
00017 #include "moHC.h"
00018 #include "moTS.h"
00019 #include "moSA.h"
00020 
00022 
00025 template < class M > class moILS:public moAlgo < typename M::EOType >
00026 {
00027 
00029   typedef typename M::EOType EOT;
00030   
00032   typedef typename EOT::Fitness Fitness;
00033 
00034 public:
00035 
00037 
00046   moILS (moAlgo<EOT> &__algo, moSolContinue <EOT> &__continue, moComparator<EOT> &__acceptance_criterion, eoMonOp<EOT> &__perturbation, 
00047          eoEvalFunc<EOT> &__full_eval):
00048     algo(__algo), cont(__continue), acceptance_criterion(__acceptance_criterion), perturbation(__perturbation), full_eval(__full_eval)
00049   {}
00050 
00052 
00062   moILS (moMoveInit < M > &__move_init, moNextMove < M > &__next_move, moMoveIncrEval < M > &__incr_eval,
00063          moMoveSelect < M > &__move_select, moSolContinue <EOT> &__continue, moComparator<EOT> &__acceptance_criterion, 
00064          eoMonOp<EOT> &__perturbation, eoEvalFunc<EOT> &__full_eval):
00065     algo(*new moHC<M>(__move_init, __next_move, __incr_eval, __move_select, __full_eval)), cont(__continue), 
00066     acceptance_criterion(__acceptance_criterion), perturbation(__perturbation), full_eval(__full_eval)
00067   {}
00068 
00070 
00082   moILS (moMoveInit <M> &__move_init, moNextMove <M> &__next_move, moMoveIncrEval <M> &__incr_eval,
00083          moTabuList <M> &__tabu_list, moAspirCrit <M> &__aspir_crit, moSolContinue <EOT> &__moTS_continue, 
00084          moSolContinue <EOT> &__continue, moComparator<EOT> &__acceptance_criterion, eoMonOp<EOT> &__perturbation, 
00085          eoEvalFunc<EOT> &__full_eval):
00086     algo(*new moTS<M>(__move_init, __next_move, __incr_eval, __tabu_list, __aspir_crit, __moTS_continue, __full_eval)), 
00087     cont(__continue), acceptance_criterion(__acceptance_criterion), perturbation(__perturbation), full_eval(__full_eval)
00088   {}
00089 
00091 
00102   moILS (moRandMove<M> &__move_rand, moMoveIncrEval <M> &__incr_eval, moSolContinue <EOT> &__moSA_continue, double __init_temp,
00103          moCoolingSchedule & __cool_sched, moSolContinue <EOT> &__continue, moComparator<EOT> &__acceptance_criterion, 
00104          eoMonOp<EOT> &__perturbation, eoEvalFunc<EOT> &__full_eval):
00105     algo(*new moSA<M>(__move_rand, __incr_eval, __moSA_continue, __init_temp, __cool_sched, __full_eval)), 
00106     cont(__continue), acceptance_criterion(__acceptance_criterion), perturbation(__perturbation), full_eval(__full_eval)
00107   {}
00108 
00109 
00110 
00112 
00119   bool operator()(EOT & __sol)
00120   {
00121     EOT __sol_saved=__sol;
00122             
00123     cont.init ();
00124 
00125     //some code has been duplicated in order to avoid one perturbation and one evaluation without adding a test in the loop.
00126     // better than a do {} while; with a test in the loop.
00127 
00128     algo(__sol);
00129         
00130     if(acceptance_criterion(__sol, __sol_saved))
00131       {
00132         __sol_saved=__sol;
00133         
00134       }
00135     else
00136       {
00137         __sol=__sol_saved;
00138       }
00139     
00140     while (cont (__sol))
00141     {
00142       perturbation(__sol);
00143       full_eval(__sol);
00144       
00145       algo(__sol);
00146             
00147       if(acceptance_criterion(__sol, __sol_saved))
00148         {
00149           __sol_saved=__sol;
00150         }
00151       else
00152         {
00153           __sol=__sol_saved;
00154         }
00155     }
00156     
00157     return true;
00158   }
00159 
00160 private:
00161 
00163   moAlgo<EOT> &algo;
00164 
00166   moSolContinue<EOT> &cont;
00167 
00169   moComparator<EOT> &acceptance_criterion;
00170 
00172   eoMonOp<EOT> &perturbation;
00173   
00175   eoEvalFunc<EOT> &full_eval;
00176 };
00177 
00178 #endif

Generated on Tue Sep 25 16:25:47 2007 for PARADISEO-MO by  doxygen 1.5.2