- Main Page
- Namespaces
- Classes
- Files

- Search for |

# moSA.h

    00001 /*
    00002 * <moSA.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 __moSA_h
    00038 #define __moSA_h
    00039
    00040 #include <eoOp.h>
    00041 #include <eoEvalFunc.h>
    00042
    00043 #include "moAlgo.h"
    00044 #include "moRandMove.h"
    00045 #include "moMoveIncrEval.h"
    00046 #include "moCoolingSchedule.h"
    00047 #include "moSolContinue.h"
    00048
    00049 #include <math.h>
    00050
    00052
    00055 template < class M > class moSA:public moAlgo < typename M::EOType >
    00056 {
    00057
    00059   typedef
    00060     typename
    00061     M::EOType
    00062     EOT;
    00063
    00065   typedef
    00066     typename
    00067     EOT::Fitness
    00068     Fitness;
    00069
    00070 public:
    00071
    00073
    00083   moSA (moRandMove < M > &__move_rand,
    00084         moMoveIncrEval < M > &__incr_eval,
    00085         moSolContinue < EOT > &__cont,
    00086         double __init_temp,
    00087         moCoolingSchedule & __cool_sched, eoEvalFunc < EOT > &__full_eval):
    00088   move_rand (__move_rand),
    00089   incr_eval (__incr_eval),
    00090   cont (__cont),
    00091   init_temp (__init_temp),
    00092   cool_sched (__cool_sched),
    00093   full_eval (__full_eval)
    00094   {
    00095
    00096   }
    00097
    00099
    00105   bool operator   ()(EOT & __sol)
    00106   {
    00107
    00108     if (__sol.invalid ())
    00109       {
    00110         full_eval (__sol);
    00111       }
    00112
    00113     double temp = init_temp;
    00114
    00115     M move;
    00116
    00117     EOT best_sol = __sol;
    00118
    00119     do
    00120       {
    00121
    00122         cont.init ();
    00123         do
    00124           {
    00125
    00126             move_rand (move);
    00127
    00128             Fitness delta_fit = incr_eval (move, __sol) - __sol.fitness ();
    00129
    00130             if (delta_fit > 0 || rng.uniform () < exp (delta_fit / temp))
    00131               {
    00132
    00133                 __sol.fitness (incr_eval (move, __sol));
    00134                 move (__sol);
    00135
    00136                 /* Updating the best solution found
    00137                    until now ? */
    00138                 if (__sol.fitness () > best_sol.fitness ())
    00139                   best_sol = __sol;
    00140               }
    00141
    00142           }
    00143         while (cont (__sol));
    00144
    00145       }
    00146     while (cool_sched (temp));
    00147
    00148     __sol = best_sol;
    00149
    00150     return true;
    00151   }
    00152
    00153 private:
    00154
    00156   moRandMove < M > &move_rand;
    00157
    00159   moMoveIncrEval < M > &incr_eval;
    00160
    00162   moSolContinue < EOT > &cont;
    00163
    00165   double  init_temp;
    00166
    00168   moCoolingSchedule & cool_sched;
    00169
    00171   eoEvalFunc < EOT > &full_eval;        // Full evaluator.
    00172 };
    00173
    00174 #endif