In the TSP, the fitness has to be minimized ... with all the needed modification (for example, moSA.h)
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@587 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
f38dde99a5
commit
1d94071693
170 changed files with 748 additions and 837 deletions
|
|
@ -46,16 +46,13 @@ 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;
|
||||
}
|
||||
|
||||
|
|
@ -87,7 +84,6 @@ private:
|
|||
|
||||
//! The best fitness.
|
||||
Fitness best_fit;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class moExponentialCoolingSchedule: public moCoolingSchedule
|
|||
{
|
||||
|
||||
public:
|
||||
//! Simple constructor
|
||||
//! Basic constructor
|
||||
/*!
|
||||
\param __threshold the threshold.
|
||||
\param __ratio the ratio used to descrease the temperature.
|
||||
|
|
|
|||
|
|
@ -29,9 +29,8 @@ public:
|
|||
//! Basic constructor.
|
||||
/*!
|
||||
\param __fitness The fitness to reach.
|
||||
\param __minimization Indicate if the the aim is to maximize or minimize the fitness.
|
||||
*/
|
||||
moFitSolContinue (Fitness __fitness, bool __minimization=true): fitness (__fitness), minimization(__minimization)
|
||||
moFitSolContinue (Fitness __fitness): fitness (__fitness)
|
||||
{}
|
||||
|
||||
//! Function that activates the stopping criterion.
|
||||
|
|
@ -48,11 +47,7 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
if(minimization)
|
||||
{
|
||||
return __sol.fitness()>fitness;
|
||||
}
|
||||
return __sol.fitness()<=fitness;
|
||||
return __sol.fitness() < fitness;
|
||||
}
|
||||
|
||||
//! Procedure which allows to initialise all the stuff needed.
|
||||
|
|
@ -63,13 +58,6 @@ private:
|
|||
|
||||
//! Fitness target.
|
||||
Fitness fitness;
|
||||
|
||||
//! Flag that indicate if there is a minimization (true) or a maximization (false) of the fitness value.
|
||||
/*!
|
||||
It can be interesting to know this information because some solution-based metaheuristics can generate solution with a fitness that
|
||||
is worse that the best known fitness (in this case, the counter is not reinitialized).
|
||||
*/
|
||||
bool minimization;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -45,8 +45,13 @@ public:
|
|||
}
|
||||
|
||||
//! Procedure which allows to initialise all the stuff needed.
|
||||
/*!
|
||||
It can be also used to reinitialize the counter all the needed things.
|
||||
*/
|
||||
void init ()
|
||||
{}
|
||||
{
|
||||
numGen=0;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -29,11 +29,9 @@ public:
|
|||
//! Basic constructor.
|
||||
/*!
|
||||
\param __maxNumberOfIterationWithoutImprovement The number of iterations without fitness improvement to reach for stop.
|
||||
\param __minimization Indicate if the the aim is to maximize or minimize the fitness.
|
||||
*/
|
||||
moNoFitImprSolContinue (unsigned int __maxNumberOfIterationWithoutImprovement, bool __minimization=true)
|
||||
: maxNumberOfIterationsWithoutImprovement(__maxNumberOfIterationWithoutImprovement),minimization(__minimization),
|
||||
firstFitnessSaved(true), counter(0)
|
||||
moNoFitImprSolContinue (unsigned int __maxNumberOfIterationWithoutImprovement)
|
||||
: maxNumberOfIterationsWithoutImprovement(__maxNumberOfIterationWithoutImprovement), firstFitnessSaved(true), counter(0)
|
||||
{}
|
||||
|
||||
//! Function that activates the stopping criterion.
|
||||
|
|
@ -59,8 +57,7 @@ public:
|
|||
|
||||
counter++;
|
||||
|
||||
if( ((minimization) && (__sol.fitness() < fitness)) ||
|
||||
((!minimization) && (__sol.fitness() > fitness)) )
|
||||
if( __sol.fitness() > fitness)
|
||||
{
|
||||
fitness=__sol.fitness();
|
||||
counter=0;
|
||||
|
|
@ -74,8 +71,14 @@ public:
|
|||
}
|
||||
|
||||
//! Procedure which allows to initialise all the stuff needed.
|
||||
/*!
|
||||
It can be also used to reinitialize the counter all the needed things.
|
||||
*/
|
||||
void init ()
|
||||
{}
|
||||
{
|
||||
firstFitnessSaved=true;
|
||||
counter=0;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
|
|
@ -88,13 +91,6 @@ private:
|
|||
//! Current Fitness.
|
||||
Fitness fitness;
|
||||
|
||||
//! Flag that indicate if there is a minimization (true) or a maximization (false) of the fitness value.
|
||||
/*!
|
||||
It can be interesting to know this information because some solution-based metaheuristics can generate solutions wiht a fitness that
|
||||
is worse that the best known fitness (in this case, the counter is not reinitialized).
|
||||
*/
|
||||
bool minimization;
|
||||
|
||||
//! The iteration couter.
|
||||
unsigned int counter;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -31,16 +31,10 @@ 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:
|
||||
|
||||
|
|
@ -91,32 +85,38 @@ public:
|
|||
|
||||
EOT best_sol = __sol;
|
||||
|
||||
Fitness current_fitness, delta;
|
||||
double exp1, exp2;
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
cont.init ();
|
||||
do
|
||||
{
|
||||
|
||||
move_rand (move);
|
||||
|
||||
Fitness delta_fit = incr_eval (move, __sol) - __sol.fitness ();
|
||||
current_fitness= incr_eval (move, __sol);
|
||||
|
||||
if (delta_fit > 0 || rng.uniform () < exp (delta_fit / temp))
|
||||
delta = current_fitness - __sol.fitness();
|
||||
|
||||
if(((long double)delta) < 0.0)
|
||||
{
|
||||
|
||||
__sol.fitness (incr_eval (move, __sol));
|
||||
move (__sol);
|
||||
|
||||
/* Updating the best solution found
|
||||
until now ? */
|
||||
if (__sol.fitness () > best_sol.fitness ())
|
||||
best_sol = __sol;
|
||||
delta=-delta;
|
||||
}
|
||||
|
||||
if ((current_fitness > __sol.fitness()) || ((rng.uniform ()) < (exp (-delta/ temp))))
|
||||
{
|
||||
__sol.fitness (current_fitness);
|
||||
move (__sol);
|
||||
|
||||
/* Updating the best solution found until now ? */
|
||||
if (__sol.fitness () > best_sol.fitness ())
|
||||
{
|
||||
best_sol = __sol;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (cont (__sol));
|
||||
|
||||
}
|
||||
while (cool_sched (temp));
|
||||
|
||||
|
|
|
|||
|
|
@ -30,11 +30,10 @@ public:
|
|||
/*!
|
||||
\param __maxNumberOfIterations The number of iterations to reach before looking for the fitness.
|
||||
\param __maxNumberOfIterationWithoutImprovement The number of iterations without fitness improvement to reach for stop.
|
||||
\param __minimization Indicate if the the aim is to maximize or minimize the fitness.
|
||||
*/
|
||||
moSteadyFitSolContinue (unsigned int __maxNumberOfIterations, unsigned int __maxNumberOfIterationWithoutImprovement, bool __minimization=true)
|
||||
moSteadyFitSolContinue (unsigned int __maxNumberOfIterations, unsigned int __maxNumberOfIterationWithoutImprovement)
|
||||
: maxNumberOfIterations (__maxNumberOfIterations), maxNumberOfIterationsWithoutImprovement(__maxNumberOfIterationWithoutImprovement),
|
||||
minimization(__minimization), maxNumberOfIterationsReached(false), firstFitnessSaved(true), counter(0)
|
||||
maxNumberOfIterationsReached(false), firstFitnessSaved(true), counter(0)
|
||||
{}
|
||||
|
||||
//! Function that activates the stopping criterion.
|
||||
|
|
@ -71,8 +70,7 @@ public:
|
|||
|
||||
counter++;
|
||||
|
||||
if( ((minimization) && (__sol.fitness() < fitness)) ||
|
||||
((!minimization) && (__sol.fitness() > fitness)) )
|
||||
if( __sol.fitness() > fitness )
|
||||
{
|
||||
fitness=__sol.fitness();
|
||||
counter=0;
|
||||
|
|
@ -86,8 +84,15 @@ public:
|
|||
}
|
||||
|
||||
//! Procedure which allows to initialise the stuff needed.
|
||||
/*!
|
||||
It can be also used to reinitialize the counter all the needed things.
|
||||
*/
|
||||
void init ()
|
||||
{}
|
||||
{
|
||||
maxNumberOfIterationsReached=false;
|
||||
counter=0;
|
||||
firstFitnessSaved=true;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
|
|
@ -106,13 +111,6 @@ private:
|
|||
//! Current Fitness.
|
||||
Fitness fitness;
|
||||
|
||||
//! Flag that indicate if there is a minimization (true) or a maximization (false) of the fitness value.
|
||||
/*!
|
||||
It can be interesting to know this information because some solution-based metaheuristics can generate solution with a fitness that
|
||||
is worse that the best known fitness (in this case, the counter is not reinitialized).
|
||||
*/
|
||||
bool minimization;
|
||||
|
||||
//! The iteration couter.
|
||||
unsigned int counter;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -91,13 +91,13 @@ moTS (moMoveExpl < M > &__move_expl, moSolContinue < EOT > &__cont, eoEvalFunc <
|
|||
|
||||
M move;
|
||||
|
||||
EOT best_sol = __sol, new_sol;
|
||||
EOT best_sol, new_sol;
|
||||
best_sol = __sol;
|
||||
|
||||
cont.init ();
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
new_sol = __sol;
|
||||
|
||||
try
|
||||
|
|
@ -112,8 +112,7 @@ 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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue