New style for MO

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@787 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
canape 2007-11-16 11:25:54 +00:00
commit 7161febf9c
80 changed files with 2014 additions and 2038 deletions

View file

@ -53,7 +53,7 @@ It contains classes for almost any kind of one solution based heuristics.
@section Installation @section Installation
The installation procedure of the package is detailed in the The installation procedure of the package is detailed in the
<a href="../../README">README</a> file in the top-directory of the source-tree. <a href="../../README">README</a> file in the top-directory of the source-tree.
*/ */

View file

@ -1,4 +1,4 @@
/* /*
* <mo.h> * <mo.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007

View file

@ -1,4 +1,4 @@
/* /*
* <moAlgo.h> * <moAlgo.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -44,8 +44,6 @@
moHC, moTS and moSA are 3 examples of algorithm of the paradiseo-mo library. moHC, moTS and moSA are 3 examples of algorithm of the paradiseo-mo library.
*/ */
template < class EOT > class moAlgo:public eoMonOp < EOT > template < class EOT > class moAlgo:public eoMonOp < EOT >
{ {};
};
#endif #endif

View file

@ -1,4 +1,4 @@
/* /*
* <moAspirCrit.h> * <moAspirCrit.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -45,18 +45,18 @@
See moNoAspriCrit for example. See moNoAspriCrit for example.
*/ */
template < class M > class moAspirCrit:public eoBF < const M &, const typename template < class M > class moAspirCrit:public eoBF < const M &, const typename
M::EOType::Fitness &, M::EOType::Fitness &,
bool > bool >
{ {
public: public:
//! Procedure which initialises all that needs a aspiration criterion. //! Procedure which initialises all that needs a aspiration criterion.
/*! /*!
It can be possible that this procedure do nothing... It can be possible that this procedure do nothing...
*/ */
virtual void virtual void
init () = 0; init () = 0;
}; };
#endif #endif

View file

@ -1,4 +1,4 @@
/* /*
* <moBestImprSelect.h> * <moBestImprSelect.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -45,74 +45,74 @@
which enables the best improvement is selected. which enables the best improvement is selected.
*/ */
template < class M > class moBestImprSelect:public moMoveSelect < M > template < class M > class moBestImprSelect:public moMoveSelect < M >
{
public:
//! Alias for the fitness.
typedef typename M::EOType::Fitness Fitness;
//! Procedure which initialise the exploration
void init (const Fitness & __fit)
{ {
first_time = true; public:
}
//! Alias for the fitness.
typedef typename M::EOType::Fitness Fitness;
//! Procedure which initialise the exploration
void init (const Fitness & __fit)
{
first_time = true;
}
//!Function that indicates if the current move has not improved the fitness. //!Function that indicates if the current move has not improved the fitness.
/*! /*!
If the given fitness enables an improvment, If the given fitness enables an improvment,
the move (moMove) and the fitness linked to this move are saved. the move (moMove) and the fitness linked to this move are saved.
\param __move a move. \param __move a move.
\param __fit a fitness linked to the move. \param __fit a fitness linked to the move.
\return TRUE if the move does not improve the fitness. \return TRUE if the move does not improve the fitness.
*/ */
bool update (const M & __move, const Fitness & __fit) bool update (const M & __move, const Fitness & __fit)
{ {
if (first_time || __fit > best_fit) if (first_time || __fit > best_fit)
{ {
best_fit = __fit; best_fit = __fit;
best_move = __move; best_move = __move;
first_time = false; first_time = false;
} }
return true; return true;
} }
//! Procedure which saved the best move and fitness. //! Procedure which saved the best move and fitness.
/*! /*!
\param __move the current move (result of the procedure). \param __move the current move (result of the procedure).
\param __fit the current fitness (result of the procedure). \param __fit the current fitness (result of the procedure).
\throws EmptySelection if no move has improved the fitness. \throws EmptySelection if no move has improved the fitness.
*/ */
void operator () (M & __move, Fitness & __fit) throw (EmptySelection) void operator () (M & __move, Fitness & __fit) throw (EmptySelection)
{ {
if (!first_time) if (!first_time)
{ {
__move = best_move; __move = best_move;
__fit = best_fit; __fit = best_fit;
} }
else else
throw EmptySelection (); throw EmptySelection ();
} }
private: private:
//! Allowing to know if at least one move has been generated. //! Allowing to know if at least one move has been generated.
bool first_time; bool first_time;
//! The best move. //! The best move.
M best_move; M best_move;
//! The best fitness. //! The best fitness.
Fitness best_fit; Fitness best_fit;
}; };
#endif #endif

View file

@ -1,4 +1,4 @@
/* /*
* <moComparator.h> * <moComparator.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -38,13 +38,12 @@
#define __moComparator_h #define __moComparator_h
//! Template for classes which need to compare two EOT and indicate if the first is "better" than the second. //! Template for classes which need to compare two EOT and indicate if the first is "better" than the second.
/*! /*!
The objects that extend this template describe how an EOT is "better" than an other. The objects that extend this template describe how an EOT is "better" than an other.
*/ */
template<class EOT> template<class EOT>
class moComparator: public eoBF<const EOT&, const EOT&, bool> class moComparator: public eoBF<const EOT&, const EOT&, bool>
{ {};
};
#endif #endif

View file

@ -1,4 +1,4 @@
/* /*
* <moCoolingSchedule.h> * <moCoolingSchedule.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -45,8 +45,6 @@
See moExponentialCoolingSchedule or moLinearCoolingSchedule for example. See moExponentialCoolingSchedule or moLinearCoolingSchedule for example.
*/ */
class moCoolingSchedule:public eoUF < double &, bool > class moCoolingSchedule:public eoUF < double &, bool >
{ {};
};
#endif #endif

View file

@ -1,4 +1,4 @@
/* /*
* <moExponentialCoolingSchedule.h> * <moExponentialCoolingSchedule.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -45,36 +45,36 @@
the temperature is greater than a given threshold. the temperature is greater than a given threshold.
*/ */
class moExponentialCoolingSchedule: public moCoolingSchedule class moExponentialCoolingSchedule: public moCoolingSchedule
{
public:
//! Simple constructor
/*!
\param __threshold the threshold.
\param __ratio the ratio used to descrease the temperature.
*/
moExponentialCoolingSchedule (double __threshold, double __ratio):threshold (__threshold), ratio (__ratio)
{}
//! Function which proceeds to the cooling.
/*!
It decreases the temperature and indicates if it is greater than the threshold.
\param __temp the current temperature.
\return if the new temperature (current temperature * ratio) is greater than the threshold.
*/
bool operator() (double &__temp)
{ {
return (__temp *= ratio) > threshold;
}
private: public:
//! Simple constructor
/*!
\param __threshold the threshold.
\param __ratio the ratio used to descrease the temperature.
*/
moExponentialCoolingSchedule (double __threshold, double __ratio):threshold (__threshold), ratio (__ratio)
{}
//! The temperature threhold. //! Function which proceeds to the cooling.
double threshold; /*!
It decreases the temperature and indicates if it is greater than the threshold.
//! The decreasing factor of the temperature. \param __temp the current temperature.
double ratio; \return if the new temperature (current temperature * ratio) is greater than the threshold.
}; */
bool operator() (double &__temp)
{
return (__temp *= ratio) > threshold;
}
private:
//! The temperature threhold.
double threshold;
//! The decreasing factor of the temperature.
double ratio;
};
#endif #endif

View file

@ -1,4 +1,4 @@
/* /*
* <moFirstImprSelect.h> * <moFirstImprSelect.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -46,84 +46,84 @@
current solution. current solution.
*/ */
template < class M > class moFirstImprSelect:public moMoveSelect < M > template < class M > class moFirstImprSelect:public moMoveSelect < M >
{
public:
//! Alias for the fitness.
typedef typename M::EOType::Fitness Fitness;
//! Procedure which initialise the exploration.
/*!
It save the current fitness as the initial value for the fitness.
*/
virtual void init (const Fitness & __fit)
{ {
valid = false; public:
init_fit = __fit;
} //! Alias for the fitness.
typedef typename M::EOType::Fitness Fitness;
//! Procedure which initialise the exploration.
/*!
It save the current fitness as the initial value for the fitness.
*/
virtual void init (const Fitness & __fit)
{
valid = false;
init_fit = __fit;
}
//!Function that indicates if the current move has not improved the fitness. //!Function that indicates if the current move has not improved the fitness.
/*! /*!
If the given fitness enables an improvment, If the given fitness enables an improvment,
the move (moMove) should be applied to the current solution. the move (moMove) should be applied to the current solution.
\param __move a move. \param __move a move.
\param __fit a fitness linked to the move. \param __fit a fitness linked to the move.
\return TRUE if the move does not improve the fitness. \return TRUE if the move does not improve the fitness.
*/ */
bool update (const M & __move, const typename M::EOType::Fitness & __fit) bool update (const M & __move, const typename M::EOType::Fitness & __fit)
{ {
if (__fit > init_fit) if (__fit > init_fit)
{ {
best_fit = __fit; best_fit = __fit;
best_move = __move; best_move = __move;
valid = true; valid = true;
return false; return false;
} }
else else
{ {
return true; return true;
} }
} }
//! Procedure which saved the best move and fitness. //! Procedure which saved the best move and fitness.
/*! /*!
\param __move the current move (result of the procedure). \param __move the current move (result of the procedure).
\param __fit the current fitness (result of the procedure). \param __fit the current fitness (result of the procedure).
\throws EmptySelection if no move has improved the fitness. \throws EmptySelection if no move has improved the fitness.
*/ */
void operator () (M & __move, Fitness & __fit) throw (EmptySelection) void operator () (M & __move, Fitness & __fit) throw (EmptySelection)
{ {
if (valid) if (valid)
{ {
__move = best_move; __move = best_move;
__fit = best_fit; __fit = best_fit;
} }
else else
throw EmptySelection (); throw EmptySelection ();
} }
private: private:
//! Allow to know if at least one move has improved the solution. //! Allow to know if at least one move has improved the solution.
bool valid; bool valid;
//! Best stored movement. //! Best stored movement.
M best_move; M best_move;
//! Initial fitness. //! Initial fitness.
Fitness init_fit; Fitness init_fit;
//! Best stored fitness. //! Best stored fitness.
Fitness best_fit; Fitness best_fit;
}; };
#endif #endif

View file

@ -1,4 +1,4 @@
/* /*
* <moFitComparator.h> * <moFitComparator.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -37,25 +37,25 @@
#ifndef __moFitComparator_h #ifndef __moFitComparator_h
#define __moFitComparator_h #define __moFitComparator_h
//! Comparison according to the fitness. //! Comparison according to the fitness.
/*! /*!
An EOT is better than an other if its fitness is better. An EOT is better than an other if its fitness is better.
*/ */
template<class EOT> template<class EOT>
class moFitComparator: public moComparator<EOT> class moFitComparator: public moComparator<EOT>
{
public:
//! Function which makes the comparison and gives the result.
/*!
\param _solution1 The first solution.
\param _solution2 The second solution.
\return true if the fitness of the first solution is better than the second solution, false else.
*/
bool operator()(const EOT& _solution1, const EOT& _solution2)
{ {
return _solution1.fitness()>_solution2.fitness(); public:
}
}; //! Function which makes the comparison and gives the result.
/*!
\param _solution1 The first solution.
\param _solution2 The second solution.
\return true if the fitness of the first solution is better than the second solution, false else.
*/
bool operator()(const EOT& _solution1, const EOT& _solution2)
{
return _solution1.fitness()>_solution2.fitness();
}
};
#endif #endif

View file

@ -1,4 +1,4 @@
/* /*
* <moFitSolContinue.h> * <moFitSolContinue.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -44,48 +44,48 @@
The stop criterion corresponds to a fitness threshold gained. The stop criterion corresponds to a fitness threshold gained.
*/ */
template < class EOT > class moFitSolContinue:public moSolContinue < EOT > template < class EOT > class moFitSolContinue:public moSolContinue < EOT >
{
public:
//! Alias for the fitness.
typedef typename EOT::Fitness Fitness;
//! Basic constructor.
/*!
\param __fitness The fitness to reach.
*/
moFitSolContinue (Fitness __fitness): fitness (__fitness)
{}
//! Function that activates the stopping criterion.
/*!
Indicates if the fitness threshold has not yet been reached.
\param __sol the current solution.
\return true or false according to the value of the fitness.
*/
bool operator () (const EOT & __sol)
{ {
if(__sol.invalid())
{
return true;
}
return __sol.fitness() < fitness; public:
}
//! Procedure which allows to initialise all the stuff needed. //! Alias for the fitness.
/*! typedef typename EOT::Fitness Fitness;
It can be also used to reinitialize all the needed things.
*/
void init ()
{}
private: //! Basic constructor.
/*!
\param __fitness The fitness to reach.
*/
moFitSolContinue (Fitness __fitness): fitness (__fitness)
{}
//! Fitness target. //! Function that activates the stopping criterion.
Fitness fitness; /*!
}; Indicates if the fitness threshold has not yet been reached.
\param __sol the current solution.
\return true or false according to the value of the fitness.
*/
bool operator () (const EOT & __sol)
{
if (__sol.invalid())
{
return true;
}
return __sol.fitness() < fitness;
}
//! Procedure which allows to initialise all the stuff needed.
/*!
It can be also used to reinitialize all the needed things.
*/
void init ()
{}
private:
//! Fitness target.
Fitness fitness;
};
#endif #endif

View file

@ -1,4 +1,4 @@
/* /*
* <moGenSolContinue.h> * <moGenSolContinue.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -44,51 +44,49 @@
The stop criterion corresponds to a maximum number of iteration. The stop criterion corresponds to a maximum number of iteration.
*/ */
template < class EOT > class moGenSolContinue:public moSolContinue < EOT > template < class EOT > class moGenSolContinue:public moSolContinue < EOT >
{
public:
//! Simple constructor.
/*!
\param __maxNumGen the maximum number of generation.
*/
moGenSolContinue (unsigned int __maxNumGen):maxNumGen (__maxNumGen), numGen (0)
{ {
} public:
//! Function that activates the stop criterion. //! Simple constructor.
/*! /*!
Increments the counter and returns TRUE if the \param __maxNumGen the maximum number of generation.
current number of iteration is lower than the given */
maximum number of iterations. moGenSolContinue (unsigned int __maxNumGen):maxNumGen (__maxNumGen), numGen (0)
{}
\param __sol the current solution. //! Function that activates the stop criterion.
\return TRUE or FALSE according to the current generation number. /*!
*/ Increments the counter and returns TRUE if the
bool operator () (const EOT & __sol) current number of iteration is lower than the given
{ maximum number of iterations.
return (++numGen < maxNumGen); \param __sol the current solution.
} \return TRUE or FALSE according to the current generation number.
*/
bool operator () (const EOT & __sol)
{
//! Procedure which allows to initialise the generation counter. return (++numGen < maxNumGen);
/*! }
It can also be used to reset the iteration counter.
*/
void init ()
{
numGen = 0; //! Procedure which allows to initialise the generation counter.
} /*!
It can also be used to reset the iteration counter.
*/
void init ()
{
private: numGen = 0;
}
//! Iteration maximum number. private:
unsigned int maxNumGen;
//! Iteration current number. //! Iteration maximum number.
unsigned int numGen; unsigned int maxNumGen;
};
//! Iteration current number.
unsigned int numGen;
};
#endif #endif

View file

@ -1,4 +1,4 @@
/* /*
* <moHC.h> * <moHC.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -48,110 +48,106 @@
Class which describes the algorithm for a hill climbing. Class which describes the algorithm for a hill climbing.
*/ */
template < class M > class moHC:public moAlgo < typename M::EOType > template < class M > class moHC:public moAlgo < typename M::EOType >
{ {
//! Alias for the type. //! Alias for the type.
typedef typedef
typename typename
M::EOType M::EOType
EOT; EOT;
//! Alias for the fitness. //! Alias for the fitness.
typedef typedef
typename typename
EOT::Fitness EOT::Fitness
Fitness; Fitness;
public: public:
//! Full constructor. //! Full constructor.
/*! /*!
All the boxes are given in order the HC to use a moHCMoveLoopExpl. All the boxes are given in order the HC to use a moHCMoveLoopExpl.
\param __move_init a move initialiser. \param __move_init a move initialiser.
\param __next_move a neighborhood explorer. \param __next_move a neighborhood explorer.
\param __incr_eval a (generally) efficient evaluation function. \param __incr_eval a (generally) efficient evaluation function.
\param __move_select a move selector. \param __move_select a move selector.
\param __full_eval a full evaluation function. \param __full_eval a full evaluation function.
*/ */
moHC (moMoveInit < M > &__move_init, moNextMove < M > &__next_move, moMoveIncrEval < M > &__incr_eval, moMoveSelect < M > &__move_select, eoEvalFunc < EOT > &__full_eval):move_expl (*new moHCMoveLoopExpl < M > moHC (moMoveInit < M > &__move_init, moNextMove < M > &__next_move, moMoveIncrEval < M > &__incr_eval, moMoveSelect < M > &__move_select, eoEvalFunc < EOT > &__full_eval):move_expl (*new moHCMoveLoopExpl < M >
(__move_init, __next_move, __incr_eval, __move_select)), (__move_init, __next_move, __incr_eval, __move_select)),
full_eval (__full_eval) full_eval (__full_eval)
{ {}
} //! Light constructor.
/*!
This constructor allow to use another moMoveExpl (generally not a moHCMoveLoopExpl).
//! Light constructor. \param __move_expl a complete explorer.
/*! \param __full_eval a full evaluation function.
This constructor allow to use another moMoveExpl (generally not a moHCMoveLoopExpl). */
moHC (moMoveExpl < M > &__move_expl, eoEvalFunc < EOT > &__full_eval):move_expl (__move_expl),
full_eval
(__full_eval)
{}
\param __move_expl a complete explorer. //! Function which launches the HC
\param __full_eval a full evaluation function. /*!
*/ The HC has to improve a current solution.
moHC (moMoveExpl < M > &__move_expl, eoEvalFunc < EOT > &__full_eval):move_expl (__move_expl), As the moSA and the mo TS, it can be used for HYBRIDATION in an evolutionnary algorithm.
full_eval
(__full_eval)
{
} \param __sol a current solution to improve.
\return TRUE.
*/
bool operator ()(EOT & __sol)
{
//! Function which launches the HC if (__sol.invalid ())
/*! {
The HC has to improve a current solution. full_eval (__sol);
As the moSA and the mo TS, it can be used for HYBRIDATION in an evolutionnary algorithm. }
\param __sol a current solution to improve. EOT new_sol;
\return TRUE.
*/
bool operator ()(EOT & __sol)
{
if (__sol.invalid ()) do
{ {
full_eval (__sol);
}
EOT new_sol; new_sol = __sol;
do try
{ {
new_sol = __sol; move_expl (__sol, new_sol);
try }
{ catch (EmptySelection & __ex)
{
move_expl (__sol, new_sol); break;
}
} if (new_sol.fitness () > __sol.fitness ())
catch (EmptySelection & __ex) {
{ __sol = new_sol;
}
else
{
break;
}
break; }
} while (true);
if (new_sol.fitness () > __sol.fitness ()) return true;
{ }
__sol = new_sol;
}
else
{
break;
}
} private:
while (true);
return true; //! Complete exploration of the neighborhood.
} moMoveExpl < M > &move_expl;
private: //! A full evaluation function.
eoEvalFunc < EOT > &full_eval;
//! Complete exploration of the neighborhood. };
moMoveExpl < M > &move_expl;
//! A full evaluation function.
eoEvalFunc < EOT > &full_eval;
};
#endif #endif

View file

@ -1,4 +1,4 @@
/* /*
* <moHCMoveLoopExpl.h> * <moHCMoveLoopExpl.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -46,88 +46,86 @@
//! Iterative explorer used by a moHC. //! Iterative explorer used by a moHC.
template < class M > class moHCMoveLoopExpl:public moMoveLoopExpl < M > template < class M > class moHCMoveLoopExpl:public moMoveLoopExpl < M >
{
//! Alias for the type.
typedef typename M::EOType EOT;
//! Alias for the fitness.
typedef typename M::EOType::Fitness Fitness;
public:
//! Constructor.
/*!
All the boxes have to be specified.
\param __move_init the move initialiser.
\param __next_move the neighborhood explorer.
\param __incr_eval (generally) efficient evaluation function.
\param __move_select the move selector.
*/
moHCMoveLoopExpl (moMoveInit < M > &__move_init, moNextMove < M > &__next_move, moMoveIncrEval < M > &__incr_eval, moMoveSelect < M > &__move_select):
move_init (__move_init),
next_move (__next_move),
incr_eval (__incr_eval), move_select (__move_select)
{ {
} //! Alias for the type.
typedef typename M::EOType EOT;
//! Procedure which launches the explorer. //! Alias for the fitness.
/*! typedef typename M::EOType::Fitness Fitness;
The exploration starts from an old solution and provides a new solution.
\param __old_sol the current solution. public:
\param __new_sol the new_sol (result of the procedure).
*/
void operator () (const EOT & __old_sol, EOT & __new_sol)
{
M move; //! Constructor.
/*!
All the boxes have to be specified.
// \param __move_init the move initialiser.
move_init (move, __old_sol); /* Restarting the exploration of \param __next_move the neighborhood explorer.
of the neighborhood ! */ \param __incr_eval (generally) efficient evaluation function.
\param __move_select the move selector.
*/
moHCMoveLoopExpl (moMoveInit < M > &__move_init, moNextMove < M > &__next_move, moMoveIncrEval < M > &__incr_eval, moMoveSelect < M > &__move_select):
move_select.init (__old_sol.fitness ()); move_init (__move_init),
next_move (__next_move),
incr_eval (__incr_eval), move_select (__move_select)
{}
while (move_select.update (move, incr_eval (move, __old_sol)) //! Procedure which launches the explorer.
&& next_move (move, __old_sol)); /*!
The exploration starts from an old solution and provides a new solution.
try \param __old_sol the current solution.
\param __new_sol the new_sol (result of the procedure).
*/
void operator () (const EOT & __old_sol, EOT & __new_sol)
{ {
M best_move; M move;
Fitness best_move_fit; //
move_init (move, __old_sol); /* Restarting the exploration of
of the neighborhood ! */
move_select (best_move, best_move_fit); move_select.init (__old_sol.fitness ());
__new_sol.fitness (best_move_fit);
best_move (__new_sol);
while (move_select.update (move, incr_eval (move, __old_sol))
&& next_move (move, __old_sol));
try
{
M best_move;
Fitness best_move_fit;
move_select (best_move, best_move_fit);
__new_sol.fitness (best_move_fit);
best_move (__new_sol);
}
catch (EmptySelection & __ex)
{
// ?
}
} }
catch (EmptySelection & __ex)
{
// ? private:
}
}
private: //! Move initialiser.
moMoveInit < M > &move_init;
//! Move initialiser. //! Neighborhood explorer.
moMoveInit < M > &move_init; moNextMove < M > &next_move;
//! Neighborhood explorer. //! (generally) Efficient evaluation.
moNextMove < M > &next_move; moMoveIncrEval < M > &incr_eval;
//! (generally) Efficient evaluation. //! Move selector.
moMoveIncrEval < M > &incr_eval; moMoveSelect < M > &move_select;
//! Move selector. };
moMoveSelect < M > &move_select;
};
#endif #endif

View file

@ -1,4 +1,4 @@
/* /*
* <moILS.h> * <moILS.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -48,156 +48,156 @@
Class which describes the algorithm for a iterated local search. Class which describes the algorithm for a iterated local search.
*/ */
template < class M > class moILS:public moAlgo < typename M::EOType > template < class M > class moILS:public moAlgo < typename M::EOType >
{
//! Alias for the type.
typedef typename M::EOType EOT;
//! Alias for the fitness.
typedef typename EOT::Fitness Fitness;
public:
//! Generic constructor
/*!
Generic constructor using a moAlgo
\param __algo The solution based heuristic to use.
\param __continue The stopping criterion.
\param __acceptance_criterion The acceptance criterion.
\param __perturbation The pertubation generator.
\param __full_eval The evaluation function.
*/
moILS (moAlgo<EOT> &__algo, moSolContinue <EOT> &__continue, moComparator<EOT> &__acceptance_criterion, eoMonOp<EOT> &__perturbation,
eoEvalFunc<EOT> &__full_eval):
algo(__algo), cont(__continue), acceptance_criterion(__acceptance_criterion), perturbation(__perturbation), full_eval(__full_eval)
{}
//! Constructor for using a moHC for the moAlgo
/*!
\param __move_init The move initialisation (for the moHC).
\param __next_move The move generator (for the moHC).
\param __incr_eval The partial evaluation function (for the moHC).
\param __move_select The move selection strategy (for the moHC).
\param __continue The stopping criterion.
\param __acceptance_criterion The acceptance criterion.
\param __perturbation The pertubation generator.
\param __full_eval The evaluation function.
*/
moILS (moMoveInit < M > &__move_init, moNextMove < M > &__next_move, moMoveIncrEval < M > &__incr_eval,
moMoveSelect < M > &__move_select, moSolContinue <EOT> &__continue, moComparator<EOT> &__acceptance_criterion,
eoMonOp<EOT> &__perturbation, eoEvalFunc<EOT> &__full_eval):
algo(*new moHC<M>(__move_init, __next_move, __incr_eval, __move_select, __full_eval)), cont(__continue),
acceptance_criterion(__acceptance_criterion), perturbation(__perturbation), full_eval(__full_eval)
{}
//! Constructor for using a moTS for the moAlgo
/*!
\param __move_init The move initialisation (for the moTS).
\param __next_move The move generator (for the moTS).
\param __incr_eval The partial evaluation function (for the moTS).
\param __tabu_list The tabu list (for the moTS !!!!).
\param __aspir_crit The aspiration criterion (for the moTS).
\param __moTS_continue The stopping criterion (for the moTS).
\param __continue The stopping criterion.
\param __acceptance_criterion The acceptance criterion.
\param __perturbation The pertubation generator.
\param __full_eval The evaluation function.
*/
moILS (moMoveInit <M> &__move_init, moNextMove <M> &__next_move, moMoveIncrEval <M> &__incr_eval,
moTabuList <M> &__tabu_list, moAspirCrit <M> &__aspir_crit, moSolContinue <EOT> &__moTS_continue,
moSolContinue <EOT> &__continue, moComparator<EOT> &__acceptance_criterion, eoMonOp<EOT> &__perturbation,
eoEvalFunc<EOT> &__full_eval):
algo(*new moTS<M>(__move_init, __next_move, __incr_eval, __tabu_list, __aspir_crit, __moTS_continue, __full_eval)),
cont(__continue), acceptance_criterion(__acceptance_criterion), perturbation(__perturbation), full_eval(__full_eval)
{}
//! Constructor for using a moSA for the moAlgo
/*!
\param __move_rand The random move generator (for the moSA).
\param __incr_eval The partial evaluation function (for the moSA).
\param __moSA_continue The stopping criterion (for the moSA).
\param __init_temp The initial temperature (for the moSA).
\param __cool_sched The cooling scheduler (for the moSA).
\param __continue The stopping criterion.
\param __acceptance_criterion The acceptance criterion.
\param __perturbation The pertubation generator.
\param __full_eval The evaluation function.
*/
moILS (moRandMove<M> &__move_rand, moMoveIncrEval <M> &__incr_eval, moSolContinue <EOT> &__moSA_continue, double __init_temp,
moCoolingSchedule & __cool_sched, moSolContinue <EOT> &__continue, moComparator<EOT> &__acceptance_criterion,
eoMonOp<EOT> &__perturbation, eoEvalFunc<EOT> &__full_eval):
algo(*new moSA<M>(__move_rand, __incr_eval, __moSA_continue, __init_temp, __cool_sched, __full_eval)),
cont(__continue), acceptance_criterion(__acceptance_criterion), perturbation(__perturbation), full_eval(__full_eval)
{}
//! Function which launches the ILS
/*!
The ILS has to improve a current solution.
As the moSA, the moTS and the moHC, it can be used for HYBRIDATION in an evolutionnary algorithm.
\param __sol a current solution to improve.
\return TRUE.
*/
bool operator()(EOT & __sol)
{ {
EOT __sol_saved=__sol;
cont.init ();
//some code has been duplicated in order to avoid one perturbation and one evaluation without adding a test in the loop. //! Alias for the type.
// better than a do {} while; with a test in the loop. typedef typename M::EOType EOT;
algo(__sol); //! Alias for the fitness.
typedef typename EOT::Fitness Fitness;
if(acceptance_criterion(__sol, __sol_saved))
{ public:
__sol_saved=__sol;
//! Generic constructor
} /*!
else Generic constructor using a moAlgo
{
__sol=__sol_saved; \param __algo The solution based heuristic to use.
} \param __continue The stopping criterion.
\param __acceptance_criterion The acceptance criterion.
while (cont (__sol)) \param __perturbation The pertubation generator.
\param __full_eval The evaluation function.
*/
moILS (moAlgo<EOT> &__algo, moSolContinue <EOT> &__continue, moComparator<EOT> &__acceptance_criterion, eoMonOp<EOT> &__perturbation,
eoEvalFunc<EOT> &__full_eval):
algo(__algo), cont(__continue), acceptance_criterion(__acceptance_criterion), perturbation(__perturbation), full_eval(__full_eval)
{}
//! Constructor for using a moHC for the moAlgo
/*!
\param __move_init The move initialisation (for the moHC).
\param __next_move The move generator (for the moHC).
\param __incr_eval The partial evaluation function (for the moHC).
\param __move_select The move selection strategy (for the moHC).
\param __continue The stopping criterion.
\param __acceptance_criterion The acceptance criterion.
\param __perturbation The pertubation generator.
\param __full_eval The evaluation function.
*/
moILS (moMoveInit < M > &__move_init, moNextMove < M > &__next_move, moMoveIncrEval < M > &__incr_eval,
moMoveSelect < M > &__move_select, moSolContinue <EOT> &__continue, moComparator<EOT> &__acceptance_criterion,
eoMonOp<EOT> &__perturbation, eoEvalFunc<EOT> &__full_eval):
algo(*new moHC<M>(__move_init, __next_move, __incr_eval, __move_select, __full_eval)), cont(__continue),
acceptance_criterion(__acceptance_criterion), perturbation(__perturbation), full_eval(__full_eval)
{}
//! Constructor for using a moTS for the moAlgo
/*!
\param __move_init The move initialisation (for the moTS).
\param __next_move The move generator (for the moTS).
\param __incr_eval The partial evaluation function (for the moTS).
\param __tabu_list The tabu list (for the moTS !!!!).
\param __aspir_crit The aspiration criterion (for the moTS).
\param __moTS_continue The stopping criterion (for the moTS).
\param __continue The stopping criterion.
\param __acceptance_criterion The acceptance criterion.
\param __perturbation The pertubation generator.
\param __full_eval The evaluation function.
*/
moILS (moMoveInit <M> &__move_init, moNextMove <M> &__next_move, moMoveIncrEval <M> &__incr_eval,
moTabuList <M> &__tabu_list, moAspirCrit <M> &__aspir_crit, moSolContinue <EOT> &__moTS_continue,
moSolContinue <EOT> &__continue, moComparator<EOT> &__acceptance_criterion, eoMonOp<EOT> &__perturbation,
eoEvalFunc<EOT> &__full_eval):
algo(*new moTS<M>(__move_init, __next_move, __incr_eval, __tabu_list, __aspir_crit, __moTS_continue, __full_eval)),
cont(__continue), acceptance_criterion(__acceptance_criterion), perturbation(__perturbation), full_eval(__full_eval)
{}
//! Constructor for using a moSA for the moAlgo
/*!
\param __move_rand The random move generator (for the moSA).
\param __incr_eval The partial evaluation function (for the moSA).
\param __moSA_continue The stopping criterion (for the moSA).
\param __init_temp The initial temperature (for the moSA).
\param __cool_sched The cooling scheduler (for the moSA).
\param __continue The stopping criterion.
\param __acceptance_criterion The acceptance criterion.
\param __perturbation The pertubation generator.
\param __full_eval The evaluation function.
*/
moILS (moRandMove<M> &__move_rand, moMoveIncrEval <M> &__incr_eval, moSolContinue <EOT> &__moSA_continue, double __init_temp,
moCoolingSchedule & __cool_sched, moSolContinue <EOT> &__continue, moComparator<EOT> &__acceptance_criterion,
eoMonOp<EOT> &__perturbation, eoEvalFunc<EOT> &__full_eval):
algo(*new moSA<M>(__move_rand, __incr_eval, __moSA_continue, __init_temp, __cool_sched, __full_eval)),
cont(__continue), acceptance_criterion(__acceptance_criterion), perturbation(__perturbation), full_eval(__full_eval)
{}
//! Function which launches the ILS
/*!
The ILS has to improve a current solution.
As the moSA, the moTS and the moHC, it can be used for HYBRIDATION in an evolutionnary algorithm.
\param __sol a current solution to improve.
\return TRUE.
*/
bool operator()(EOT & __sol)
{ {
perturbation(__sol); EOT __sol_saved=__sol;
full_eval(__sol);
cont.init ();
//some code has been duplicated in order to avoid one perturbation and one evaluation without adding a test in the loop.
// better than a do {} while; with a test in the loop.
algo(__sol); algo(__sol);
if(acceptance_criterion(__sol, __sol_saved)) if (acceptance_criterion(__sol, __sol_saved))
{ {
__sol_saved=__sol; __sol_saved=__sol;
}
}
else else
{ {
__sol=__sol_saved; __sol=__sol_saved;
} }
while (cont (__sol))
{
perturbation(__sol);
full_eval(__sol);
algo(__sol);
if (acceptance_criterion(__sol, __sol_saved))
{
__sol_saved=__sol;
}
else
{
__sol=__sol_saved;
}
}
return true;
} }
return true;
}
private: private:
//! The solution based heuristic. //! The solution based heuristic.
moAlgo<EOT> &algo; moAlgo<EOT> &algo;
//! The stopping criterion. //! The stopping criterion.
moSolContinue<EOT> &cont; moSolContinue<EOT> &cont;
//! The acceptance criterion. //! The acceptance criterion.
moComparator<EOT> &acceptance_criterion; moComparator<EOT> &acceptance_criterion;
//! The perturbation generator //! The perturbation generator
eoMonOp<EOT> &perturbation; eoMonOp<EOT> &perturbation;
//! The full evaluation function //! The full evaluation function
eoEvalFunc<EOT> &full_eval; eoEvalFunc<EOT> &full_eval;
}; };
#endif #endif

View file

@ -1,4 +1,4 @@
/* /*
* <moImprBestFitAspirCrit.h> * <moImprBestFitAspirCrit.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -45,65 +45,65 @@
is the best ever considered. is the best ever considered.
*/ */
template < class M > class moImprBestFitAspirCrit:public moAspirCrit < M > template < class M > class moImprBestFitAspirCrit:public moAspirCrit < M >
{
public:
//! Alias for the fitness
typedef typename M::EOType::Fitness Fitness;
//! Contructor
moImprBestFitAspirCrit ()
{ {
first_time = true; public:
}
//! Initialisation procedure //! Alias for the fitness
void init () typedef typename M::EOType::Fitness Fitness;
{
first_time = true; //! Contructor
} moImprBestFitAspirCrit ()
{
//! Function that indicates if the fit is better that the already saved fit first_time = true;
/*! }
The first time, the function only saved the current move and fitness.
\param __move a move. //! Initialisation procedure
\param __fit a fitnes linked to the move. void init ()
\return TRUE the first time and if __fit > best_fit, else FALSE. {
*/
bool operator () (const M & __move, const Fitness & __fit)
{
if (first_time) first_time = true;
{ }
best_fit = __fit; //! Function that indicates if the fit is better that the already saved fit
first_time = false; /*!
The first time, the function only saved the current move and fitness.
return true; \param __move a move.
} \param __fit a fitnes linked to the move.
else if (__fit < best_fit) \return TRUE the first time and if __fit > best_fit, else FALSE.
return false; */
bool operator () (const M & __move, const Fitness & __fit)
{
else if (first_time)
{ {
best_fit = __fit; best_fit = __fit;
first_time = false;
return true; return true;
} }
} else if (__fit < best_fit)
return false;
private: else
{
//! Best fitness found until now best_fit = __fit;
Fitness best_fit;
//! Indicates that a fitness has been already saved or not return true;
bool first_time; }
}; }
private:
//! Best fitness found until now
Fitness best_fit;
//! Indicates that a fitness has been already saved or not
bool first_time;
};
#endif #endif

View file

@ -1,4 +1,4 @@
/* /*
* <moItRandNextMove.h> * <moItRandNextMove.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -45,65 +45,63 @@
This class is a move (moMove) generator with a bound for the maximum number of iterations. This class is a move (moMove) generator with a bound for the maximum number of iterations.
*/ */
template < class M > class moItRandNextMove:public moNextMove < M > template < class M > class moItRandNextMove:public moNextMove < M >
{
//! Alias for the type.
typedef typename M::EOType EOT;
public:
//! The constructor.
/*!
Parameters only for initialising the attributes.
\param __rand_move the random move generator.
\param __max_iter the iteration maximum number.
*/
moItRandNextMove (moRandMove < M > &__rand_move,
unsigned int __max_iter):rand_move (__rand_move),
max_iter (__max_iter), num_iter (0)
{ {
} //! Alias for the type.
typedef typename M::EOType EOT;
//! Generation of a new move public:
/*!
If the maximum number is not already reached, the current move is forgotten and remplaced by another one.
\param __move the current move. //! The constructor.
\param __sol the current solution. /*!
\return FALSE if the maximum number of iteration is reached, else TRUE. Parameters only for initialising the attributes.
*/
bool operator () (M & __move, const EOT & __sol)
{
if (num_iter++ > max_iter) \param __rand_move the random move generator.
{ \param __max_iter the iteration maximum number.
*/
moItRandNextMove (moRandMove < M > &__rand_move,
unsigned int __max_iter):rand_move (__rand_move),
max_iter (__max_iter), num_iter (0)
{}
num_iter = 0; //! Generation of a new move
return false; /*!
} If the maximum number is not already reached, the current move is forgotten and remplaced by another one.
else
{
/* The given solution is discarded here */ \param __move the current move.
rand_move (__move); \param __sol the current solution.
num_iter++; \return FALSE if the maximum number of iteration is reached, else TRUE.
return true; */
} bool operator () (M & __move, const EOT & __sol)
} {
private: if (num_iter++ > max_iter)
{
//! A move generator (generally randomly). num_iter = 0;
moRandMove < M > &rand_move; return false;
}
else
{
//! Iteration maximum number. /* The given solution is discarded here */
unsigned int max_iter; rand_move (__move);
num_iter++;
return true;
}
}
//! Iteration current number. private:
unsigned int num_iter;
}; //! A move generator (generally randomly).
moRandMove < M > &rand_move;
//! Iteration maximum number.
unsigned int max_iter;
//! Iteration current number.
unsigned int num_iter;
};
#endif #endif

View file

@ -1,4 +1,4 @@
/* /*
* <moLSCheckPoint.h> * <moLSCheckPoint.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -44,48 +44,48 @@
Thanks to this class, at each iteration, additionnal function can be used (and not only one). Thanks to this class, at each iteration, additionnal function can be used (and not only one).
*/ */
template < class M > class moLSCheckPoint:public eoBF < const M &, const typename template < class M > class moLSCheckPoint:public eoBF < const M &, const typename
M::EOType &, void > M::EOType &, void >
{
public:
//! Function which launches the checkpointing
/*!
Each saved function is used on the current move and the current solution.
\param __move a move.
\param __sol a solution.
*/
void
operator () (const M & __move, const typename M::EOType & __sol)
{ {
for (unsigned int i = 0; i < func.size (); i++) public:
//! Function which launches the checkpointing
/*!
Each saved function is used on the current move and the current solution.
\param __move a move.
\param __sol a solution.
*/
void
operator () (const M & __move, const typename M::EOType & __sol)
{
for (unsigned int i = 0; i < func.size (); i++)
{
func[i]->operator ()(__move, __sol);
}
}
//! Procedure which add a new function to the function vector
/*!
The new function is added at the end of the vector.
\param __f a new function to add.
*/
void
add (eoBF < const M &, const typename M::EOType &, void >&__f)
{ {
func[i]->operator ()(__move, __sol);
func.push_back (&__f);
} }
}
//! Procedure which add a new function to the function vector private:
/*!
The new function is added at the end of the vector.
\param __f a new function to add.
*/
void
add (eoBF < const M &, const typename M::EOType &, void >&__f)
{
func.push_back (&__f); //! vector of function
} std::vector < eoBF < const
private:
//! vector of function
std::vector < eoBF < const
M &, const M &, const
typename typename
M::EOType &, void >*> M::EOType &, void >*>
func; func;
}; };
#endif #endif

View file

@ -1,4 +1,4 @@
/* /*
* <moLinearCoolingSchedule.h> * <moLinearCoolingSchedule.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -45,36 +45,36 @@
the temperature is greater than a threshold. the temperature is greater than a threshold.
*/ */
class moLinearCoolingSchedule: public moCoolingSchedule class moLinearCoolingSchedule: public moCoolingSchedule
{
public:
//! Simple constructor
/*!
\param __threshold the threshold.
\param __quantity the quantity used to descrease the temperature.
*/
moLinearCoolingSchedule (double __threshold, double __quantity):threshold (__threshold), quantity (__quantity)
{}
//! Function which proceeds to the cooling.
/*!
It decreases the temperature and indicates if it is greater than the threshold.
\param __temp the current temperature.
\return if the new temperature (current temperature - quantity) is greater than the threshold.
*/
bool operator() (double &__temp)
{ {
return (__temp -= quantity) > threshold;
}
private: public:
//! Simple constructor
/*!
\param __threshold the threshold.
\param __quantity the quantity used to descrease the temperature.
*/
moLinearCoolingSchedule (double __threshold, double __quantity):threshold (__threshold), quantity (__quantity)
{}
//! The temperature threhold. //! Function which proceeds to the cooling.
double threshold; /*!
It decreases the temperature and indicates if it is greater than the threshold.
//! The quantity that allows the temperature to decrease. \param __temp the current temperature.
double quantity; \return if the new temperature (current temperature - quantity) is greater than the threshold.
}; */
bool operator() (double &__temp)
{
return (__temp -= quantity) > threshold;
}
private:
//! The temperature threhold.
double threshold;
//! The quantity that allows the temperature to decrease.
double quantity;
};
#endif #endif

View file

@ -1,4 +1,4 @@
/* /*
* <moMove.h> * <moMove.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -46,12 +46,12 @@
It describes how a solution can be modified to another one. It describes how a solution can be modified to another one.
*/ */
template < class EOT > class moMove:public eoUF < EOT &, void > template < class EOT > class moMove:public eoUF < EOT &, void >
{ {
public: public:
//! Alias for the type //! Alias for the type
typedef EOT EOType; typedef EOT EOType;
}; };
#endif #endif

Some files were not shown because too many files have changed in this diff Show more