Added wonderful test stuff

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@594 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
legrand 2007-09-18 15:45:15 +00:00
commit 31a487ec4a
23 changed files with 307 additions and 312 deletions

View file

@ -18,7 +18,6 @@
#include "moCoolingSchedule.h"
#include "moExponentialCoolingSchedule.h"
#include "moFirstImprSelect.h"
#include "moFitSolContinue.h"
#include "moGenSolContinue.h"
#include "moHC.h"
#include "moHCMoveLoopExpl.h"
@ -34,14 +33,12 @@
#include "moMoveSelect.h"
#include "moNextMove.h"
#include "moNoAspirCrit.h"
#include "moNoFitImprSolContinue.h"
#include "moRandImprSelect.h"
#include "moRandMove.h"
#include "moSA.h"
#include "moSimpleMoveTabuList.h"
#include "moSimpleSolutionTabuList.h"
#include "moSolContinue.h"
#include "moSteadyFitSolContinue.h"
#include "moTabuList.h"
#include "moTS.h"
#include "moTSMoveLoopExpl.h"

View file

@ -37,7 +37,7 @@ public:
//!Function that indicates if the current move has not improved the fitness.
/*!
If the given fitness enables an improvement,
If the given fitness enables an improvment,
the move (moMove) and the fitness linked to this move are saved.
\param __move a move.
@ -46,13 +46,16 @@ public:
*/
bool update (const M & __move, const Fitness & __fit)
{
if ((first_time) || (__fit > best_fit))
if (first_time || __fit > best_fit)
{
best_fit = __fit;
best_move = __move;
first_time = false;
}
return true;
}
@ -84,6 +87,7 @@ private:
//! The best fitness.
Fitness best_fit;
};
#endif

View file

@ -23,7 +23,7 @@ class moExponentialCoolingSchedule: public moCoolingSchedule
{
public:
//! Basic constructor
//! Simple constructor
/*!
\param __threshold the threshold.
\param __ratio the ratio used to descrease the temperature.

View file

@ -17,7 +17,7 @@
//! One possible moMoveSelect.
/*!
The neighborhood is explored until
a move enables an improvement of the
a move enables an improvment of the
current solution.
*/
template < class M > class moFirstImprSelect:public moMoveSelect < M >
@ -42,7 +42,7 @@ public:
//!Function that indicates if the current move has not improved the fitness.
/*!
If the given fitness enables an improvement,
If the given fitness enables an improvment,
the move (moMove) should be applied to the current solution.
\param __move a move.

View file

@ -1,6 +1,6 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "moGenSolContinue.h"
// "eoGenSolContinue.h"
// (c) OPAC Team, LIFL, 2003-2006
@ -14,43 +14,47 @@
#include "moSolContinue.h"
//! One possible stopping criterion for a solution-based heuristic.
//! One possible stop criterion for a solution-based heuristic.
/*!
The stopping 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 >
{
public:
//! Basic constructor.
//! Simple constructor.
/*!
\param __maxNumGen the maximum number of generation.
*/
moGenSolContinue (unsigned int __maxNumGen):maxNumGen (__maxNumGen), numGen (0)
{}
{
}
//! Function that activates the stop criterion.
/*!
Increments the counter and returns true if the
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.
\return TRUE or FALSE according to the current generation number.
*/
bool operator () (const EOT & __sol)
bool operator () (const EOT & __sol)
{
return (++numGen < maxNumGen);
}
//! Procedure which allows to initialise all the stuff needed.
//! Procedure which allows to initialise the generation counter.
/*!
It can be also used to reinitialize the counter all the needed things.
*/
It can also be used to reset the iteration counter.
*/
void init ()
{
numGen=0;
numGen = 0;
}
private:

View file

@ -64,31 +64,31 @@ moHCMoveLoopExpl (moMoveInit < M > &__move_init, moNextMove < M > &__next_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);
}
{
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.

View file

@ -20,7 +20,7 @@
//! One of the possible moMove selector (moMoveSelect)
/*!
All the neighbors are considered.
One of them that enables an improvement of the objective function is choosen.
One of them that enables an improvment of the objective function is choosen.
*/
template < class M > class moRandImprSelect:public moMoveSelect < M >
{

View file

@ -31,10 +31,16 @@ template < class M > class moSA:public moAlgo < typename M::EOType >
{
//! Alias for the type
typedef typename M::EOType EOT;
typedef
typename
M::EOType
EOT;
//! Alias for the fitness
typedef typename EOT::Fitness Fitness;
typedef
typename
EOT::Fitness
Fitness;
public:
@ -85,38 +91,32 @@ public:
EOT best_sol = __sol;
Fitness current_fitness, delta;
double exp1, exp2;
do
{
cont.init ();
do
{
move_rand (move);
current_fitness= incr_eval (move, __sol);
Fitness delta_fit = incr_eval (move, __sol) - __sol.fitness ();
delta = current_fitness - __sol.fitness();
if(((long double)delta) < 0.0)
if (delta_fit > 0 || rng.uniform () < exp (delta_fit / temp))
{
delta=-delta;
}
if ((current_fitness > __sol.fitness()) || ((rng.uniform ()) < (exp (-delta/ temp))))
{
__sol.fitness (current_fitness);
__sol.fitness (incr_eval (move, __sol));
move (__sol);
/* Updating the best solution found until now ? */
/* Updating the best solution found
until now ? */
if (__sol.fitness () > best_sol.fitness ())
{
best_sol = __sol;
}
best_sol = __sol;
}
}
while (cont (__sol));
}
while (cool_sched (temp));

View file

@ -14,7 +14,7 @@
#include <eoFunctor.h>
//! Class that describes a stopping criterion for a solution-based heuristic
//! Class that describes a stop criterion for a solution-based heuristic
/*!
It allows to add an initialisation procedure to an object that is a unary function (eoUF).
@ -23,7 +23,7 @@ template < class EOT > class moSolContinue:public eoUF < const EOT &, bool >
{
public:
//! Procedure which initialises all that the stopping criterion needs
//! Procedure which initialises all that the stop criterion needs
/*!
Generally, it allocates some data structures or initialises some counters.
*/

View file

@ -91,13 +91,13 @@ moTS (moMoveExpl < M > &__move_expl, moSolContinue < EOT > &__cont, eoEvalFunc <
M move;
EOT best_sol, new_sol;
best_sol = __sol;
EOT best_sol = __sol, new_sol;
cont.init ();
do
{
new_sol = __sol;
try
@ -112,7 +112,8 @@ moTS (moMoveExpl < M > &__move_expl, moSolContinue < EOT > &__cont, eoEvalFunc <
break;
}
/* Updating the best solution found until now ? */
/* Updating the best solution
found until now ? */
if (new_sol.fitness () > __sol.fitness ())
{
best_sol = new_sol;