MO full import

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@25 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
legrand 2006-12-06 12:56:53 +00:00
commit bbad098cba
31 changed files with 46407 additions and 0 deletions

View file

@ -0,0 +1 @@
# Nothing to compile !

View file

@ -0,0 +1,26 @@
/** @mainpage Welcome to PARADISEO-Moving Objects
@section intro Introduction
MO is an extension of the ANSI-C++ compliant evolutionary computation library EO.
<br>
It contains classes for almost any kind of one solution based heuristics.
@section tutorial Tutorial
@section install Installation
The installation procedure of the package is detailed in the
<a href="../../README">README</a> file in the top-directory of the source-tree.
@section design Overall Design
*/
// coding: iso-8859-1
// mode: C++
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

6
trunk/paradiseo-mo/src/mo Executable file
View file

@ -0,0 +1,6 @@
#ifndef __mo
#define __mo
#include "mo.h"
#endif

43
trunk/paradiseo-mo/src/mo.h Executable file
View file

@ -0,0 +1,43 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "mo.h"
// (c) OPAC Team, LIFL, 2003-2006
/* TEXT LICENCE
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __mo_h
#define __mo_h
#include "moAspirCrit.h"
#include "moAlgo.h"
#include "moBestImprSelect.h"
#include "moCoolSched.h"
#include "moEasyCoolSched.h"
#include "moFirstImprSelect.h"
#include "moGenSolContinue.h"
#include "moHC.h"
#include "moHCMoveLoopExpl.h"
#include "moImprBestFitAspirCrit.h"
#include "moItRandNextMove.h"
#include "moLSCheckPoint.h"
#include "moMoveExpl.h"
#include "moMove.h"
#include "moMoveIncrEval.h"
#include "moMoveInit.h"
#include "moMoveLoopExpl.h"
#include "moMoveSelect.h"
#include "moNextMove.h"
#include "moNoAspirCrit.h"
#include "moRandImprSelect.h"
#include "moRandMove.h"
#include "moSA.h"
#include "moSolContinue.h"
#include "moTabuList.h"
#include "moTS.h"
#include "moTSMoveLoopExpl.h"
#endif

26
trunk/paradiseo-mo/src/moAlgo.h Executable file
View file

@ -0,0 +1,26 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "moAlgo.h"
// (c) OPAC Team, LIFL, 2003-2006
/* TEXT LICENCE
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __moAlgo_h
#define __moAlgo_h
#include <eoOp.h>
//! Description of an algorithm of the mo library
/*!
moHC, moTS and moSA are 3 examples of algorithm of the mo library.
*/
template < class EOT > class moAlgo:public eoMonOp < EOT >
{
};
#endif

View file

@ -0,0 +1,37 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "moAspirCrit.h"
// (c) OPAC Team, LIFL, 2003-2006
/* TEXT LICENCE
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __moAspirCrit_h
#define __moAspirCrit_h
#include <eoFunctor.h>
//! Description of the conditions in which a tabu move could be accepted
/*!
It is only a description... An object that herits from this class is needed to be used in a moTS.
See moNoAspriCrit for example.
*/
template < class M > class moAspirCrit:public eoBF < const M &, const typename
M::EOType::Fitness &,
bool >
{
public:
//! Procedure which initialises all that needs a aspiration criterion.
/*!
It can be possible that this procedure do nothing...
*/
virtual void
init () = 0;
};
#endif

View file

@ -0,0 +1,93 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "moBestImprSelect.h"
// (c) OPAC Team, LIFL, 2003-2006
/* LICENCE TEXT
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __moBestImprSelect_h
#define __moBestImprSelect_h
#include "moMoveSelect.h"
//! One of the possible moMoveSelect.
/*!
All neighbors are considered, and the movement
which enables the best improvement is selected.
*/
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;
}
//!Function that indicates if the current move has not improved the fitness.
/*!
If the given fitness enables an improvment,
the move (moMove) and the fitness linked to this move are saved.
\param __move a move.
\param __fit a fitness linked to the move.
\return TRUE if the move does not improve the fitness.
*/
bool update (const M & __move, const Fitness & __fit)
{
if (first_time || __fit > best_fit)
{
best_fit = __fit;
best_move = __move;
first_time = false;
}
return true;
}
//! Procedure which saved the best move and fitness.
/*!
\param __move the current move (result of the procedure).
\param __fit the current fitness (result of the procedure).
\throws EmptySelection if no move has improved the fitness.
*/
void operator () (M & __move, Fitness & __fit) throw (EmptySelection)
{
if (!first_time)
{
__move = best_move;
__fit = best_fit;
}
else
throw EmptySelection ();
}
private:
//! Allowing to know if at least one move has been generated.
bool first_time;
//! The best move.
M best_move;
//! The best fitness.
Fitness best_fit;
};
#endif

View file

@ -0,0 +1,27 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "moCoolSched.h"
// (c) OPAC Team, LIFL, 2003-2006
/* LICENCE TEXT
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __moCoolSched_h
#define __moCoolSched_h
#include <eoFunctor.h>
//! This class gives the description of a cooling schedule.
/*!
It is only a description... An object that herits from this class is needed to be used in a moSA.
See moEasyCoolSched for example.
*/
class moCoolSched:public eoUF < double &, bool >
{
};
#endif

View file

@ -0,0 +1,60 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "moEasyCoolSched.h"
// (c) OPAC Team, LIFL, 2003-2006
/* LICENCE TEXT
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __moEasyCoolSched_h
#define __moEasyCoolSched_h
#include "moCoolSched.h"
//! One of the possible moCoolSched
/*!
The simpliest, the temperature decrease according to a ratio until
it greater than a threshold.
*/
class moEasyCoolSched:public moCoolSched
{
public:
//! Simple constructor
/*!
\param __threshold the threshold.
\param __ratio the ratio used to descrease the temperature.
*/
moEasyCoolSched (double __threshold,
double __ratio):threshold (__threshold), ratio (__ratio)
{
}
//! Function which proceeds to the cooling.
/*!
Decrease 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:
//! The temperature threhold.
double threshold;
//! The decreasing factor of the temperature.
double ratio;
};
#endif

View file

@ -0,0 +1,104 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "moFirstImprSelect.h"
// (c) OPAC Team, LIFL, 2003-2006
/* LICENCE TEXT
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __moFirstImprSelect_h
#define __moFirstImprSelect_h
#include "moMoveSelect.h"
//! One possible moMoveSelect.
/*!
The neighborhood is explored until
a move enables an improvment of the
current solution.
*/
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;
init_fit = __fit;
}
//!Function that indicates if the current move has not improved the fitness.
/*!
If the given fitness enables an improvment,
the move (moMove) should be applied to the current solution.
\param __move a move.
\param __fit a fitness linked to the move.
\return TRUE if the move does not improve the fitness.
*/
bool update (const M & __move, const typename M::EOType::Fitness & __fit)
{
if (__fit > init_fit)
{
best_fit = __fit;
best_move = __move;
valid = true;
return false;
}
else
{
return true;
}
}
//! Procedure which saved the best move and fitness.
/*!
\param __move the current move (result of the procedure).
\param __fit the current fitness (result of the procedure).
\throws EmptySelection if no move has improved the fitness.
*/
void operator () (M & __move, Fitness & __fit) throw (EmptySelection)
{
if (valid)
{
__move = best_move;
__fit = best_fit;
}
else
throw EmptySelection ();
}
private:
//! Allow to know if at least one move has improved the solution.
bool valid;
//! Best stored movement.
M best_move;
//! Initial fitness.
Fitness init_fit;
//! Best stored fitness.
Fitness best_fit;
};
#endif

View file

@ -0,0 +1,69 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "eoGenSolContinue.h"
// (c) OPAC Team, LIFL, 2003-2006
/* LICENCE TEXT
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __moGenSolContinue_h
#define __moGenSolContinue_h
#include "moSolContinue.h"
//! One possible stop criterion for a solution-based heuristic.
/*!
The stop criterion corresponds to a maximum number of iteration.
*/
template < class EOT > class moGenSolContinue:public moSolContinue < EOT >
{
public:
//! Simple constructor.
/*!
\param __maxNumGen the maximum number of generation.
*/
moGenSolContinue (unsigned __maxNumGen):maxNumGen (__maxNumGen), numGen (0)
{
}
//! Function that activates the stop criterion.
/*!
Increments the counter and returns TRUE if the
current number of iteration is lower than the given
maximum number of iterations.
\param __sol the current solution.
\return TRUE or FALSE according to the current generation number.
*/
bool operator () (const EOT & __sol)
{
return (++numGen < maxNumGen);
}
//! Procedure which allows to initialise the generation counter.
/*!
It can also be used to reset the iteration counter.
*/
void init ()
{
numGen = 0;
}
private:
//! Iteration maximum number.
unsigned maxNumGen;
//! Iteration current number.
unsigned numGen;
};
#endif

133
trunk/paradiseo-mo/src/moHC.h Executable file
View file

@ -0,0 +1,133 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "moHC.h"
// (c) OPAC Team, LIFL, 2003-2006
/* LICENCE TEXT
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __moHC_h
#define __moHC_h
#include <eoOp.h>
#include <eoEvalFunc.h>
#include "moAlgo.h"
#include "moMoveExpl.h"
#include "moHCMoveLoopExpl.h"
//! Hill Climbing (HC)
/*!
Class which describes the algorithm for a hill climbing.
*/
template < class M > class moHC:public moAlgo < typename M::EOType >
{
//! Alias for the type.
typedef
typename
M::EOType
EOT;
//! Alias for the fitness.
typedef
typename
EOT::Fitness
Fitness;
public:
//! Full constructor.
/*!
All the boxes are given in order the HC to use a moHCMoveLoopExpl.
\param __move_init a move initialiser.
\param __next_move a neighborhood explorer.
\param __incr_eval a (generally) efficient evaluation function.
\param __move_select a move selector.
\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 >
(__move_init, __next_move, __incr_eval, __move_select)),
full_eval (__full_eval)
{
}
//! Light constructor.
/*!
This constructor allow to use another moMoveExpl (generally not a moHCMoveLoopExpl).
\param __move_expl a complete explorer.
\param __full_eval a full evaluation function.
*/
moHC (moMoveExpl < M > &__move_expl, eoEvalFunc < EOT > &__full_eval):move_expl (__move_expl),
full_eval
(__full_eval)
{
}
//! Function which launches the HC
/*!
The HC has to improve a current solution.
As the moSA and the mo TS, it can be used for HYBRIDATION in an evolutionnary algorithm.
\param __sol a current solution to improve.
\return TRUE.
*/
bool operator ()(EOT & __sol)
{
if (__sol.invalid ())
{
full_eval (__sol);
}
EOT new_sol;
do
{
new_sol = __sol;
try
{
move_expl (__sol, new_sol);
}
catch (EmptySelection & __ex)
{
break;
}
if (new_sol.fitness () > __sol.fitness ())
{
__sol = new_sol;
}
else
{
break;
}
}
while (true);
return true;
}
private:
//! Complete exploration of the neighborhood.
moMoveExpl < M > &move_expl;
//! A full evaluation function.
eoEvalFunc < EOT > &full_eval;
};
#endif

View file

@ -0,0 +1,108 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "moHCMoveLoopExpl.h"
// (c) OPAC Team, LIFL, 2003-2006
/* LICENCE TEXT
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __moHCMoveLoopExpl_h
#define __moHCMoveLoopExpl_h
#include "moMoveLoopExpl.h"
#include "moMoveInit.h"
#include "moNextMove.h"
#include "moMoveIncrEval.h"
#include "moMoveSelect.h"
//! Iterative explorer used by a moHC.
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)
{
}
//! Procedure which launches the explorer.
/*!
The exploration starts from an old solution and provides a new solution.
\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 move;
//
move_init (move, __old_sol); /* Restarting the exploration of
of the neighborhood ! */
move_select.init (__old_sol.fitness ());
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)
{
// ?
}
}
private:
//! Move initialiser.
moMoveInit < M > &move_init;
//! Neighborhood explorer.
moNextMove < M > &next_move;
//! (generally) Efficient evaluation.
moMoveIncrEval < M > &incr_eval;
//! Move selector.
moMoveSelect < M > &move_select;
};
#endif

View file

@ -0,0 +1,84 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "moImprAspirCrit.h"
// (c) OPAC Team, LIFL, 2003-2006
/* LICENCE TEXT
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __moImprBestFitAspirCrit_h
#define __moImprBestFitAspirCrit_h
#include "moAspirCrit.h"
//! One of the possible moAspirCrit
/*!
This criterion is satisfied when a given fitness
is the best ever considered.
*/
template < class M > class moImprBestFitAspirCrit:public moAspirCrit < M >
{
public:
//! Alias for the fitness
typedef typename M::EOType::Fitness Fitness;
//! Contructor
moImprBestFitAspirCrit ()
{
first_time = true;
}
//! Initialisation procedure
void init ()
{
first_time = true;
}
//! Function that indicates if the fit is better that the already saved fit
/*!
The first time, the function only saved the current move and fitness.
\param __move a move.
\param __fit a fitnes linked to the move.
\return TRUE the first time and if __fit > best_fit, else FALSE.
*/
bool operator () (const M & __move, const Fitness & __fit)
{
if (first_time)
{
best_fit = __fit;
first_time = false;
return true;
}
else if (__fit < best_fit)
return false;
else
{
best_fit = __fit;
return true;
}
}
private:
//! Best fitness found until now
Fitness best_fit;
//! Indicates that a fitness has been already saved or not
bool first_time;
};
#endif

View file

@ -0,0 +1,84 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "moNextMove.h"
// (c) OPAC Team, LIFL, 2003-2006
/* LICENCE TEXT
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __moItRandNextMove_h
#define __moItRandNextMove_h
#include "moNextMove.h"
#include "moRandMove.h"
//! One of the possible moNextMove.
/*!
This class is a move (moMove) generator with a bound for the maximum number of iterations.
*/
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 __max_iter):rand_move (__rand_move),
max_iter (__max_iter), num_iter (0)
{
}
//! Generation of a new move
/*!
If the maximum number is not already reached, the current move is forgotten and remplaced by another one.
\param __move the current move.
\param __sol the current solution.
\return FALSE if the maximum number of iteration is reached, else TRUE.
*/
bool operator () (M & __move, const EOT & __sol)
{
if (num_iter++ > max_iter)
{
num_iter = 0;
return false;
}
else
{
/* The given solution is discarded here */
rand_move (__move);
num_iter++;
return true;
}
}
private:
//! A move generator (generally randomly).
moRandMove < M > &rand_move;
//! Iteration maximum number.
unsigned max_iter;
//! Iteration current number.
unsigned num_iter;
};
#endif

View file

@ -0,0 +1,66 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "moLSCheckPoint.h"
// (c) OPAC Team, LIFL, 2003
/* TEXT LICENCE
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __moSolUpdater_h
#define __moSolUpdater_h
#include <eoFunctor.h>
//! Class which allows a checkpointing system.
/*!
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
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 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.push_back (&__f);
}
private:
//! vector of function
std::vector < eoBF < const
M &, const
typename
M::EOType &, void >*>
func;
};
#endif

32
trunk/paradiseo-mo/src/moMove.h Executable file
View file

@ -0,0 +1,32 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "moMove.h"
// (c) OPAC Team, LIFL, 2003-2006
/* TEXT LICENCE
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __moMove_h
#define __moMove_h
#include <eoFunctor.h>
//! Definition of a move.
/*!
A move transforms a solution to another close solution.
It describes how a solution can be modified to another one.
*/
template < class EOT > class moMove:public eoUF < EOT &, void >
{
public:
//! Alias for the type
typedef EOT EOType;
};
#endif

View file

@ -0,0 +1,29 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "eoMoveExpl.h"
// (c) OPAC Team, LIFL, 2003-2006
/* LICENCE TEXT
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __moMoveExpl_h
#define __moMoveExpl_h
#include <eoFunctor.h>
//! Description of a move (moMove) explorer
/*!
Only a description...See moMoveLoopExpl.
*/
template < class M > class moMoveExpl:public eoBF < const typename
M::EOType &,
typename
M::EOType &, void >
{
};
#endif

View file

@ -0,0 +1,32 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "eoMoveIncrEval.h"
// (c) OPAC Team, LIFL, 2003-2006
/* LICENCE TEXT
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __moMoveIncrEval_h
#define __moMoveIncrEval_h
#include <eoFunctor.h>
//! (generally) Efficient evaluation function based a move and a solution.
/*!
From a move and a solution, it computes
a new fitness that could be associated to
the solution if this one is updated.
*/
template < class M > class moMoveIncrEval:public eoBF < const M &, const typename
M::EOType &,
typename
M::EOType::Fitness >
{
};
#endif

View file

@ -0,0 +1,28 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "moMoveInit.h"
// (c) OPAC Team, LIFL, 2003-2006
/* LICENCE TEXT
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __moMoveInit_h
#define __moMoveInit_h
#include <eoFunctor.h>
//! Move (moMove) initializer
/*!
Class which allows to initiase a move.
Only a description... An object that herits from this class needs to be designed to be used.
*/
template < class M > class moMoveInit:public eoBF < M &, const typename
M::EOType &, void >
{
};
#endif

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