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:
parent
47298125ec
commit
7161febf9c
80 changed files with 2014 additions and 2038 deletions
|
|
@ -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.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <moMoveExpl.h>
|
* <moMoveExpl.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,11 +44,9 @@
|
||||||
Only a description...See moMoveLoopExpl.
|
Only a description...See moMoveLoopExpl.
|
||||||
*/
|
*/
|
||||||
template < class M > class moMoveExpl:public eoBF < const typename
|
template < class M > class moMoveExpl:public eoBF < const typename
|
||||||
M::EOType &,
|
M::EOType &,
|
||||||
typename
|
typename
|
||||||
M::EOType &, void >
|
M::EOType &, void >
|
||||||
{
|
{};
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <moMoveIncrEval.h>
|
* <moMoveIncrEval.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
|
||||||
|
|
@ -47,11 +47,9 @@
|
||||||
the solution if this one is updated.
|
the solution if this one is updated.
|
||||||
*/
|
*/
|
||||||
template < class M > class moMoveIncrEval:public eoBF < const M &, const typename
|
template < class M > class moMoveIncrEval:public eoBF < const M &, const typename
|
||||||
M::EOType &,
|
M::EOType &,
|
||||||
typename
|
typename
|
||||||
M::EOType::Fitness >
|
M::EOType::Fitness >
|
||||||
{
|
{};
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <moMoveInit.h>
|
* <moMoveInit.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,9 +45,7 @@
|
||||||
Only a description... An object that herits from this class needs to be designed to be used.
|
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
|
template < class M > class moMoveInit:public eoBF < M &, const typename
|
||||||
M::EOType &, void >
|
M::EOType &, void >
|
||||||
{
|
{};
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <moMoveLoopExpl.h>
|
* <moMoveLoopExpl.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 @@
|
||||||
Only a description... moHCMoveLoopExpl and moTSMoveLoopExpl are exemples of class that are a moMoveLoopExpl.
|
Only a description... moHCMoveLoopExpl and moTSMoveLoopExpl are exemples of class that are a moMoveLoopExpl.
|
||||||
*/
|
*/
|
||||||
template < class M > class moMoveLoopExpl:public moMoveExpl < M >
|
template < class M > class moMoveLoopExpl:public moMoveExpl < M >
|
||||||
{
|
{};
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <moMoveSelect.h>
|
* <moMoveSelect.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,47 +44,45 @@
|
||||||
This class is used as an exception that can be thrown if a solution selector has completly failed.
|
This class is used as an exception that can be thrown if a solution selector has completly failed.
|
||||||
*/
|
*/
|
||||||
class EmptySelection
|
class EmptySelection
|
||||||
{
|
{};
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
//! Class that describes a move selector (moMove).
|
//! Class that describes a move selector (moMove).
|
||||||
/*!
|
/*!
|
||||||
It iteratively considers some moves (moMove) and their
|
It iteratively considers some moves (moMove) and their
|
||||||
associated fitnesses. The best move is so regularly updated.
|
associated fitnesses. The best move is so regularly updated.
|
||||||
At any time, it could be accessed.
|
At any time, it could be accessed.
|
||||||
*/
|
*/
|
||||||
template < class M > class moMoveSelect:public eoBF < M &, typename M::EOType::Fitness &,
|
template < class M > class moMoveSelect:public eoBF < M &, typename M::EOType::Fitness &,
|
||||||
void >
|
void >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! Alias for the fitness
|
//! Alias for the fitness
|
||||||
typedef
|
typedef
|
||||||
typename
|
typename
|
||||||
M::EOType::Fitness
|
M::EOType::Fitness
|
||||||
Fitness;
|
Fitness;
|
||||||
|
|
||||||
//! Procedure which initialises all that the move selector needs including the initial fitness.
|
//! Procedure which initialises all that the move selector needs including the initial fitness.
|
||||||
/*!
|
/*!
|
||||||
In order to know the fitness of the solution,
|
In order to know the fitness of the solution,
|
||||||
for which the neighborhood will
|
for which the neighborhood will
|
||||||
be soon explored
|
be soon explored
|
||||||
|
|
||||||
\param __fit the current fitness.
|
\param __fit the current fitness.
|
||||||
*/
|
*/
|
||||||
virtual void
|
virtual void
|
||||||
init (const Fitness & __fit) = 0;
|
init (const Fitness & __fit) = 0;
|
||||||
|
|
||||||
//! Function which updates the best solutions.
|
//! Function which updates the best solutions.
|
||||||
/*!
|
/*!
|
||||||
\param __move a new move.
|
\param __move a new move.
|
||||||
\param __fit a fitness linked to the new move.
|
\param __fit a fitness linked to the new move.
|
||||||
\return a boolean that expresses the need to resume the exploration.
|
\return a boolean that expresses the need to resume the exploration.
|
||||||
*/
|
*/
|
||||||
virtual
|
virtual
|
||||||
bool
|
bool
|
||||||
update (const M & __move, const Fitness & __fit) = 0;
|
update (const M & __move, const Fitness & __fit) = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <moNextMove.h>
|
* <moNextMove.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,10 +45,8 @@
|
||||||
Does nothing... An object that herits from this class needs to be designed for being used.
|
Does nothing... An object that herits from this class needs to be designed for being used.
|
||||||
*/
|
*/
|
||||||
template < class M > class moNextMove:public eoBF < M &, const typename
|
template < class M > class moNextMove:public eoBF < M &, const typename
|
||||||
M::EOType &,
|
M::EOType &,
|
||||||
bool >
|
bool >
|
||||||
{
|
{};
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <moNoAspirCrit.h>
|
* <moNoAspirCrit.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,30 +44,29 @@
|
||||||
The simplest : never satisfied.
|
The simplest : never satisfied.
|
||||||
*/
|
*/
|
||||||
template < class M > class moNoAspirCrit:public moAspirCrit < M >
|
template < class M > class moNoAspirCrit:public moAspirCrit < M >
|
||||||
{
|
|
||||||
|
|
||||||
//! Function which describes the aspiration criterion behaviour
|
|
||||||
/*!
|
|
||||||
Does nothing.
|
|
||||||
|
|
||||||
\param __move a move.
|
|
||||||
\param __sol a fitness.
|
|
||||||
\return FALSE.
|
|
||||||
*/
|
|
||||||
bool operator () (const M & __move,
|
|
||||||
const typename M::EOType::Fitness & __sol)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
return false;
|
//! Function which describes the aspiration criterion behaviour
|
||||||
}
|
/*!
|
||||||
|
Does nothing.
|
||||||
|
|
||||||
//! Procedure which initialises all that needs a moNoAspirCrit
|
\param __move a move.
|
||||||
/*!
|
\param __sol a fitness.
|
||||||
Nothing...
|
\return FALSE.
|
||||||
*/
|
*/
|
||||||
void init ()
|
bool operator () (const M & __move,
|
||||||
{
|
const typename M::EOType::Fitness & __sol)
|
||||||
}
|
{
|
||||||
};
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Procedure which initialises all that needs a moNoAspirCrit
|
||||||
|
/*!
|
||||||
|
Nothing...
|
||||||
|
*/
|
||||||
|
void init ()
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <moNoFitImprSolContinue.h>
|
* <moNoFitImprSolContinue.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,80 +44,80 @@
|
||||||
The stop criterion corresponds to a maximum number of iterations without improvement.
|
The stop criterion corresponds to a maximum number of iterations without improvement.
|
||||||
*/
|
*/
|
||||||
template < class EOT > class moNoFitImprSolContinue:public moSolContinue < EOT >
|
template < class EOT > class moNoFitImprSolContinue:public moSolContinue < EOT >
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
//! Alias for the fitness.
|
|
||||||
typedef typename EOT::Fitness Fitness;
|
|
||||||
|
|
||||||
//! Basic constructor.
|
|
||||||
/*!
|
|
||||||
\param __maxNumberOfIterationWithoutImprovement The number of iterations without fitness improvement to reach for stop.
|
|
||||||
*/
|
|
||||||
moNoFitImprSolContinue (unsigned int __maxNumberOfIterationWithoutImprovement)
|
|
||||||
: maxNumberOfIterationsWithoutImprovement(__maxNumberOfIterationWithoutImprovement), firstFitnessSaved(true), counter(0)
|
|
||||||
{}
|
|
||||||
|
|
||||||
//! Function that activates the stopping criterion.
|
|
||||||
/*!
|
|
||||||
Indicates if the fitness has not been improved since a given number of iterations (after a minimum of iterations).
|
|
||||||
\param __sol the current solution.
|
|
||||||
\return true or false.
|
|
||||||
*/
|
|
||||||
bool operator () (const EOT & __sol)
|
|
||||||
{
|
{
|
||||||
if(__sol.invalid())
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(firstFitnessSaved)
|
public:
|
||||||
{
|
|
||||||
fitness=__sol.fitness();
|
|
||||||
counter=0;
|
|
||||||
firstFitnessSaved=false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
counter++;
|
|
||||||
|
|
||||||
if( __sol.fitness() > fitness)
|
//! Alias for the fitness.
|
||||||
{
|
typedef typename EOT::Fitness Fitness;
|
||||||
fitness=__sol.fitness();
|
|
||||||
counter=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(counter==maxNumberOfIterationsWithoutImprovement)
|
|
||||||
{
|
|
||||||
std::cout << "moNoFitImrpSolContinue: Done [" << counter << "] iterations without improvement." << std::endl;
|
|
||||||
}
|
|
||||||
return counter!=maxNumberOfIterationsWithoutImprovement;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Procedure which allows to initialise all the stuff needed.
|
//! Basic constructor.
|
||||||
/*!
|
/*!
|
||||||
It can be also used to reinitialize all the needed things.
|
\param __maxNumberOfIterationWithoutImprovement The number of iterations without fitness improvement to reach for stop.
|
||||||
*/
|
*/
|
||||||
void init ()
|
moNoFitImprSolContinue (unsigned int __maxNumberOfIterationWithoutImprovement)
|
||||||
{
|
: maxNumberOfIterationsWithoutImprovement(__maxNumberOfIterationWithoutImprovement), firstFitnessSaved(true), counter(0)
|
||||||
firstFitnessSaved=true;
|
{}
|
||||||
counter=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
//! Function that activates the stopping criterion.
|
||||||
|
/*!
|
||||||
|
Indicates if the fitness has not been improved since a given number of iterations (after a minimum of iterations).
|
||||||
|
\param __sol the current solution.
|
||||||
|
\return true or false.
|
||||||
|
*/
|
||||||
|
bool operator () (const EOT & __sol)
|
||||||
|
{
|
||||||
|
if (__sol.invalid())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//! Maximum number of iterations without improvement allowed.
|
if (firstFitnessSaved)
|
||||||
unsigned int maxNumberOfIterationsWithoutImprovement;
|
{
|
||||||
|
fitness=__sol.fitness();
|
||||||
|
counter=0;
|
||||||
|
firstFitnessSaved=false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//! Flag that this is the first time that the fitness is used.
|
counter++;
|
||||||
bool firstFitnessSaved;
|
|
||||||
|
|
||||||
//! Current Fitness.
|
if ( __sol.fitness() > fitness)
|
||||||
Fitness fitness;
|
{
|
||||||
|
fitness=__sol.fitness();
|
||||||
|
counter=0;
|
||||||
|
}
|
||||||
|
|
||||||
//! The iteration couter.
|
if (counter==maxNumberOfIterationsWithoutImprovement)
|
||||||
unsigned int counter;
|
{
|
||||||
};
|
std::cout << "moNoFitImrpSolContinue: Done [" << counter << "] iterations without improvement." << std::endl;
|
||||||
|
}
|
||||||
|
return counter!=maxNumberOfIterationsWithoutImprovement;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Procedure which allows to initialise all the stuff needed.
|
||||||
|
/*!
|
||||||
|
It can be also used to reinitialize all the needed things.
|
||||||
|
*/
|
||||||
|
void init ()
|
||||||
|
{
|
||||||
|
firstFitnessSaved=true;
|
||||||
|
counter=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
//! Maximum number of iterations without improvement allowed.
|
||||||
|
unsigned int maxNumberOfIterationsWithoutImprovement;
|
||||||
|
|
||||||
|
//! Flag that this is the first time that the fitness is used.
|
||||||
|
bool firstFitnessSaved;
|
||||||
|
|
||||||
|
//! Current Fitness.
|
||||||
|
Fitness fitness;
|
||||||
|
|
||||||
|
//! The iteration couter.
|
||||||
|
unsigned int counter;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <moRandImprSelect.h>
|
* <moRandImprSelect.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,86 +44,86 @@
|
||||||
|
|
||||||
//! One of the possible moMove selector (moMoveSelect)
|
//! One of the possible moMove selector (moMoveSelect)
|
||||||
/*!
|
/*!
|
||||||
All the neighbors are considered.
|
All the neighbors are considered.
|
||||||
One of them that enables an improvment 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 >
|
template < class M > class moRandImprSelect:public moMoveSelect < M >
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
//! Alias for the fitness
|
|
||||||
typedef typename M::EOType::Fitness Fitness;
|
|
||||||
|
|
||||||
//!Procedure which all that needs a moRandImprSelect
|
|
||||||
/*!
|
|
||||||
Give a value to the initialise fitness.
|
|
||||||
Clean the move and fitness vectors.
|
|
||||||
|
|
||||||
\param __fit the current best fitness
|
|
||||||
*/
|
|
||||||
void init (const Fitness & __fit)
|
|
||||||
{
|
|
||||||
init_fit = __fit;
|
|
||||||
vect_better_fit.clear ();
|
|
||||||
vect_better_moves.clear ();
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Function that updates the fitness and move vectors
|
|
||||||
/*!
|
|
||||||
if a move give a better fitness than the initial fitness,
|
|
||||||
it is saved and the fitness too.
|
|
||||||
|
|
||||||
\param __move a new move.
|
|
||||||
\param __fit a new fitness associated to the new move.
|
|
||||||
\return TRUE.
|
|
||||||
*/
|
|
||||||
bool update (const M & __move, const Fitness & __fit)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
if (__fit > init_fit)
|
public:
|
||||||
{
|
|
||||||
|
|
||||||
vect_better_fit.push_back (__fit);
|
//! Alias for the fitness
|
||||||
vect_better_moves.push_back (__move);
|
typedef typename M::EOType::Fitness Fitness;
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
//!Procedure which all that needs a moRandImprSelect
|
||||||
}
|
/*!
|
||||||
|
Give a value to the initialise fitness.
|
||||||
|
Clean the move and fitness vectors.
|
||||||
|
|
||||||
//! The move selection
|
\param __fit the current best fitness
|
||||||
/*!
|
*/
|
||||||
One the saved move is randomly chosen.
|
void init (const Fitness & __fit)
|
||||||
|
{
|
||||||
|
init_fit = __fit;
|
||||||
|
vect_better_fit.clear ();
|
||||||
|
vect_better_moves.clear ();
|
||||||
|
}
|
||||||
|
|
||||||
\param __move the reference of the move that can be initialised by the function.
|
//! Function that updates the fitness and move vectors
|
||||||
\param __fit the reference of the fitness that can be initialised by the function.
|
/*!
|
||||||
\throws EmptySelection If no move which improves the current fitness are found.
|
if a move give a better fitness than the initial fitness,
|
||||||
*/
|
it is saved and the fitness too.
|
||||||
void operator () (M & __move, Fitness & __fit) throw (EmptySelection)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (!vect_better_fit.empty ())
|
\param __move a new move.
|
||||||
{
|
\param __fit a new fitness associated to the new move.
|
||||||
|
\return TRUE.
|
||||||
|
*/
|
||||||
|
bool update (const M & __move, const Fitness & __fit)
|
||||||
|
{
|
||||||
|
|
||||||
unsigned n = rng.random (vect_better_fit.size ());
|
if (__fit > init_fit)
|
||||||
|
{
|
||||||
|
|
||||||
__move = vect_better_moves[n];
|
vect_better_fit.push_back (__fit);
|
||||||
__fit = vect_better_fit[n];
|
vect_better_moves.push_back (__move);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
throw EmptySelection ();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//! Fitness of the current solution.
|
//! The move selection
|
||||||
Fitness init_fit;
|
/*!
|
||||||
|
One the saved move is randomly chosen.
|
||||||
|
|
||||||
//! Candidate fitnesse vector.
|
\param __move the reference of the move that can be initialised by the function.
|
||||||
std::vector < Fitness > vect_better_fit;
|
\param __fit the reference of the fitness that can be initialised by the function.
|
||||||
|
\throws EmptySelection If no move which improves the current fitness are found.
|
||||||
|
*/
|
||||||
|
void operator () (M & __move, Fitness & __fit) throw (EmptySelection)
|
||||||
|
{
|
||||||
|
|
||||||
//! Candidate move vector.
|
if (!vect_better_fit.empty ())
|
||||||
std::vector < M > vect_better_moves;
|
{
|
||||||
};
|
|
||||||
|
unsigned n = rng.random (vect_better_fit.size ());
|
||||||
|
|
||||||
|
__move = vect_better_moves[n];
|
||||||
|
__fit = vect_better_fit[n];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw EmptySelection ();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
//! Fitness of the current solution.
|
||||||
|
Fitness init_fit;
|
||||||
|
|
||||||
|
//! Candidate fitnesse vector.
|
||||||
|
std::vector < Fitness > vect_better_fit;
|
||||||
|
|
||||||
|
//! Candidate move vector.
|
||||||
|
std::vector < M > vect_better_moves;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <moRandMove.h>
|
* <moRandMove.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
|
||||||
|
|
@ -41,11 +41,9 @@
|
||||||
|
|
||||||
//! Random move generator
|
//! Random move generator
|
||||||
/*!
|
/*!
|
||||||
Only a description... An object that herits from this class needs to be designed in order to use a moSA.
|
Only a description... An object that herits from this class needs to be designed in order to use a moSA.
|
||||||
*/
|
*/
|
||||||
template < class M > class moRandMove:public eoUF < M &, void >
|
template < class M > class moRandMove:public eoUF < M &, void >
|
||||||
{
|
{};
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <moSA.h>
|
* <moSA.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
|
||||||
|
|
@ -53,122 +53,120 @@
|
||||||
Class that describes a Simulated Annealing algorithm.
|
Class that describes a Simulated Annealing algorithm.
|
||||||
*/
|
*/
|
||||||
template < class M > class moSA:public moAlgo < typename M::EOType >
|
template < class M > class moSA: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:
|
||||||
|
|
||||||
//! SA constructor
|
//! SA constructor
|
||||||
/*!
|
/*!
|
||||||
All the boxes used by a SA need to be given.
|
All the boxes used by a SA need to be given.
|
||||||
|
|
||||||
\param __move_rand a move generator (generally randomly).
|
\param __move_rand a move generator (generally randomly).
|
||||||
\param __incr_eval a (generaly) efficient evaluation function
|
\param __incr_eval a (generaly) efficient evaluation function
|
||||||
\param __cont a stopping criterion.
|
\param __cont a stopping criterion.
|
||||||
\param __init_temp the initial temperature.
|
\param __init_temp the initial temperature.
|
||||||
\param __cool_sched a cooling schedule, describes how the temperature is modified.
|
\param __cool_sched a cooling schedule, describes how the temperature is modified.
|
||||||
\param __full_eval a full evaluation function.
|
\param __full_eval a full evaluation function.
|
||||||
*/
|
*/
|
||||||
moSA (moRandMove < M > &__move_rand,
|
moSA (moRandMove < M > &__move_rand,
|
||||||
moMoveIncrEval < M > &__incr_eval,
|
moMoveIncrEval < M > &__incr_eval,
|
||||||
moSolContinue < EOT > &__cont,
|
moSolContinue < EOT > &__cont,
|
||||||
double __init_temp,
|
double __init_temp,
|
||||||
moCoolingSchedule & __cool_sched, eoEvalFunc < EOT > &__full_eval):
|
moCoolingSchedule & __cool_sched, eoEvalFunc < EOT > &__full_eval):
|
||||||
move_rand (__move_rand),
|
move_rand (__move_rand),
|
||||||
incr_eval (__incr_eval),
|
incr_eval (__incr_eval),
|
||||||
cont (__cont),
|
cont (__cont),
|
||||||
init_temp (__init_temp),
|
init_temp (__init_temp),
|
||||||
cool_sched (__cool_sched),
|
cool_sched (__cool_sched),
|
||||||
full_eval (__full_eval)
|
full_eval (__full_eval)
|
||||||
{
|
{}
|
||||||
|
|
||||||
}
|
//! function that launches the SA algorithm.
|
||||||
|
/*!
|
||||||
|
As a moTS or a moHC, the SA can be used for HYBRIDATION in an evolutionary algorithm.
|
||||||
|
|
||||||
//! function that launches the SA algorithm.
|
\param __sol a solution to improve.
|
||||||
/*!
|
\return TRUE.
|
||||||
As a moTS or a moHC, the SA can be used for HYBRIDATION in an evolutionary algorithm.
|
*/
|
||||||
|
bool operator ()(EOT & __sol)
|
||||||
|
{
|
||||||
|
|
||||||
\param __sol a solution to improve.
|
if (__sol.invalid ())
|
||||||
\return TRUE.
|
{
|
||||||
*/
|
full_eval (__sol);
|
||||||
bool operator ()(EOT & __sol)
|
}
|
||||||
{
|
|
||||||
|
|
||||||
if (__sol.invalid ())
|
double temp = init_temp;
|
||||||
{
|
|
||||||
full_eval (__sol);
|
|
||||||
}
|
|
||||||
|
|
||||||
double temp = init_temp;
|
M move;
|
||||||
|
|
||||||
M move;
|
EOT best_sol = __sol;
|
||||||
|
|
||||||
EOT best_sol = __sol;
|
do
|
||||||
|
{
|
||||||
|
|
||||||
do
|
cont.init ();
|
||||||
{
|
do
|
||||||
|
{
|
||||||
|
|
||||||
cont.init ();
|
move_rand (move);
|
||||||
do
|
|
||||||
{
|
|
||||||
|
|
||||||
move_rand (move);
|
Fitness delta_fit = incr_eval (move, __sol) - __sol.fitness ();
|
||||||
|
|
||||||
Fitness delta_fit = incr_eval (move, __sol) - __sol.fitness ();
|
if (delta_fit > 0 || rng.uniform () < exp (delta_fit / temp))
|
||||||
|
{
|
||||||
|
|
||||||
if (delta_fit > 0 || rng.uniform () < exp (delta_fit / temp))
|
__sol.fitness (incr_eval (move, __sol));
|
||||||
{
|
move (__sol);
|
||||||
|
|
||||||
__sol.fitness (incr_eval (move, __sol));
|
/* Updating the best solution found
|
||||||
move (__sol);
|
until now ? */
|
||||||
|
if (__sol.fitness () > best_sol.fitness ())
|
||||||
|
best_sol = __sol;
|
||||||
|
}
|
||||||
|
|
||||||
/* Updating the best solution found
|
}
|
||||||
until now ? */
|
while (cont (__sol));
|
||||||
if (__sol.fitness () > best_sol.fitness ())
|
|
||||||
best_sol = __sol;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
while (cont (__sol));
|
while (cool_sched (temp));
|
||||||
|
|
||||||
}
|
__sol = best_sol;
|
||||||
while (cool_sched (temp));
|
|
||||||
|
|
||||||
__sol = best_sol;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
private:
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
//! A move generator (generally randomly)
|
||||||
|
moRandMove < M > &move_rand;
|
||||||
|
|
||||||
//! A move generator (generally randomly)
|
//! A (generally) efficient evaluation function.
|
||||||
moRandMove < M > &move_rand;
|
moMoveIncrEval < M > &incr_eval;
|
||||||
|
|
||||||
//! A (generally) efficient evaluation function.
|
//! Stopping criterion before temperature update
|
||||||
moMoveIncrEval < M > &incr_eval;
|
moSolContinue < EOT > &cont;
|
||||||
|
|
||||||
//! Stopping criterion before temperature update
|
//! Initial temperature
|
||||||
moSolContinue < EOT > &cont;
|
double init_temp;
|
||||||
|
|
||||||
//! Initial temperature
|
//! The cooling schedule
|
||||||
double init_temp;
|
moCoolingSchedule & cool_sched;
|
||||||
|
|
||||||
//! The cooling schedule
|
//! A full evaluation function.
|
||||||
moCoolingSchedule & cool_sched;
|
eoEvalFunc < EOT > &full_eval; // Full evaluator.
|
||||||
|
};
|
||||||
//! A full evaluation function.
|
|
||||||
eoEvalFunc < EOT > &full_eval; // Full evaluator.
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <moSimpleMoveTabuList.h>
|
* <moSimpleMoveTabuList.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,107 +45,107 @@
|
||||||
//! Class describing a move tabu list with a limited memory.
|
//! Class describing a move tabu list with a limited memory.
|
||||||
template <class M>
|
template <class M>
|
||||||
class moSimpleMoveTabuList: public moTabuList < M >
|
class moSimpleMoveTabuList: public moTabuList < M >
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
//! Alias for the type
|
|
||||||
typedef typename M::EOType EOT;
|
|
||||||
|
|
||||||
//! Constructor
|
public:
|
||||||
/*
|
|
||||||
\param __size The maximum size of the move tabu list.
|
|
||||||
*/
|
|
||||||
moSimpleMoveTabuList(unsigned int __size): maxSize(__size)
|
|
||||||
{
|
|
||||||
currentSize=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Function that indicates if, in a given state, the _move is tabu or not.
|
//! Alias for the type
|
||||||
/*!
|
typedef typename M::EOType EOT;
|
||||||
\param __move A given moMove.
|
|
||||||
\param __sol A solution.
|
//! Constructor
|
||||||
\return true or false.
|
/*
|
||||||
*/
|
\param __size The maximum size of the move tabu list.
|
||||||
bool
|
*/
|
||||||
operator () (const M & __move, const EOT & __sol)
|
moSimpleMoveTabuList(unsigned int __size): maxSize(__size)
|
||||||
{
|
{
|
||||||
typename std::list<M>::iterator it;
|
currentSize=0;
|
||||||
|
}
|
||||||
it=tabuList.begin();
|
|
||||||
while(it!=tabuList.end()&&(!((*it)==__move)))
|
//! Function that indicates if, in a given state, the _move is tabu or not.
|
||||||
|
/*!
|
||||||
|
\param __move A given moMove.
|
||||||
|
\param __sol A solution.
|
||||||
|
\return true or false.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
operator () (const M & __move, const EOT & __sol)
|
||||||
|
{
|
||||||
|
typename std::list<M>::iterator it;
|
||||||
|
|
||||||
|
it=tabuList.begin();
|
||||||
|
while (it!=tabuList.end()&&(!((*it)==__move)))
|
||||||
|
{
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return it!=tabuList.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
add (const M & __move, const EOT & __sol)
|
||||||
{
|
{
|
||||||
it++;
|
if (currentSize!=0)
|
||||||
}
|
{
|
||||||
|
// Useful in the case of a move has been kept thanks to the moAspirCrit.
|
||||||
return it!=tabuList.end();
|
// In this case, the move can already be in the tabuList.
|
||||||
}
|
removeMove(__move);
|
||||||
|
}
|
||||||
void
|
|
||||||
add (const M & __move, const EOT & __sol)
|
tabuList.push_back(__move);
|
||||||
{
|
|
||||||
if(currentSize!=0)
|
if (currentSize==maxSize)
|
||||||
{
|
{
|
||||||
// Useful in the case of a move has been kept thanks to the moAspirCrit.
|
tabuList.erase(tabuList.begin());
|
||||||
// In this case, the move can already be in the tabuList.
|
}
|
||||||
removeMove(__move);
|
else
|
||||||
|
{
|
||||||
|
currentSize++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tabuList.push_back(__move);
|
void
|
||||||
|
update ()
|
||||||
if(currentSize==maxSize)
|
{
|
||||||
{
|
//nothing to do
|
||||||
tabuList.erase(tabuList.begin());
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
currentSize++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
update ()
|
|
||||||
{
|
|
||||||
//nothing to do
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
init ()
|
init ()
|
||||||
{
|
{
|
||||||
//nothing to do
|
//nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
//! Procedure that removes a given move from the tabu list (if it is into, else do nothing).
|
|
||||||
/*!
|
|
||||||
\param __move A given moMove.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
removeMove(const M & __move)
|
|
||||||
{
|
|
||||||
typename std::list<M>::iterator it;
|
|
||||||
|
|
||||||
it=tabuList.begin();
|
|
||||||
while(it!=tabuList.end()&&(!((*it)==__move)))
|
|
||||||
{
|
|
||||||
it++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(it!=tabuList.end())
|
//! Procedure that removes a given move from the tabu list (if it is into, else do nothing).
|
||||||
{
|
/*!
|
||||||
tabuList.erase(it);
|
\param __move A given moMove.
|
||||||
}
|
*/
|
||||||
}
|
void
|
||||||
|
removeMove(const M & __move)
|
||||||
|
{
|
||||||
|
typename std::list<M>::iterator it;
|
||||||
|
|
||||||
//! The maximum size of the tabu list.
|
it=tabuList.begin();
|
||||||
unsigned int maxSize;
|
while (it!=tabuList.end()&&(!((*it)==__move)))
|
||||||
|
{
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
|
||||||
//! The current size of the tabu list.
|
if (it!=tabuList.end())
|
||||||
unsigned int currentSize;
|
{
|
||||||
|
tabuList.erase(it);
|
||||||
//! The move tabu list.
|
}
|
||||||
std::list<M> tabuList;
|
}
|
||||||
};
|
|
||||||
|
//! The maximum size of the tabu list.
|
||||||
|
unsigned int maxSize;
|
||||||
|
|
||||||
|
//! The current size of the tabu list.
|
||||||
|
unsigned int currentSize;
|
||||||
|
|
||||||
|
//! The move tabu list.
|
||||||
|
std::list<M> tabuList;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <moSimpleSolutionTabuList.h>
|
* <moSimpleSolutionTabuList.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,116 +45,116 @@
|
||||||
//! Class describing a solution tabu list with limited length.
|
//! Class describing a solution tabu list with limited length.
|
||||||
template <class M>
|
template <class M>
|
||||||
class moSimpleSolutionTabuList: public moTabuList < M >
|
class moSimpleSolutionTabuList: public moTabuList < M >
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
//! Alias for the type
|
|
||||||
typedef typename M::EOType EOT;
|
|
||||||
|
|
||||||
//! Constructor
|
|
||||||
/*!
|
|
||||||
\param __size The maximum size of the solution tabu list.
|
|
||||||
*/
|
|
||||||
moSimpleSolutionTabuList(unsigned int __size): maxSize(__size)
|
|
||||||
{
|
{
|
||||||
currentSize=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Function that indicates if, in a given state, the _move is tabu or not.
|
|
||||||
/*!
|
|
||||||
\param __move A given moMove.
|
|
||||||
\param __sol A solution.
|
|
||||||
\return true or false.
|
|
||||||
*/
|
|
||||||
bool operator () (const M & __move, const EOT & __sol)
|
|
||||||
{
|
|
||||||
typename std::list<EOT>::iterator it;
|
|
||||||
|
|
||||||
M _move=(M)__move;
|
|
||||||
EOT _sol=(EOT) __sol;
|
|
||||||
|
|
||||||
_move(_sol);
|
public:
|
||||||
|
|
||||||
it=tabuList.begin();
|
//! Alias for the type
|
||||||
while(it!=tabuList.end()&&(!((*it)==_sol)))
|
typedef typename M::EOType EOT;
|
||||||
|
|
||||||
|
//! Constructor
|
||||||
|
/*!
|
||||||
|
\param __size The maximum size of the solution tabu list.
|
||||||
|
*/
|
||||||
|
moSimpleSolutionTabuList(unsigned int __size): maxSize(__size)
|
||||||
|
{
|
||||||
|
currentSize=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Function that indicates if, in a given state, the _move is tabu or not.
|
||||||
|
/*!
|
||||||
|
\param __move A given moMove.
|
||||||
|
\param __sol A solution.
|
||||||
|
\return true or false.
|
||||||
|
*/
|
||||||
|
bool operator () (const M & __move, const EOT & __sol)
|
||||||
|
{
|
||||||
|
typename std::list<EOT>::iterator it;
|
||||||
|
|
||||||
|
M _move=(M)__move;
|
||||||
|
EOT _sol=(EOT) __sol;
|
||||||
|
|
||||||
|
_move(_sol);
|
||||||
|
|
||||||
|
it=tabuList.begin();
|
||||||
|
while (it!=tabuList.end()&&(!((*it)==_sol)))
|
||||||
|
{
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return it!=tabuList.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
add (const M & __move, const EOT & __sol)
|
||||||
{
|
{
|
||||||
it++;
|
M _move=(M)__move;
|
||||||
}
|
EOT _sol=(EOT) _sol;
|
||||||
|
|
||||||
return it!=tabuList.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
add (const M & __move, const EOT & __sol)
|
|
||||||
{
|
|
||||||
M _move=(M)__move;
|
|
||||||
EOT _sol=(EOT) _sol;
|
|
||||||
|
|
||||||
_move(_sol);
|
|
||||||
|
|
||||||
if(currentSize!=0)
|
_move(_sol);
|
||||||
{
|
|
||||||
// Useful in the case of a solution has been kept thanks to the moAspirCrit.
|
|
||||||
// In this case, the solution can already be in the tabuList.
|
|
||||||
removeSolution(_sol);
|
|
||||||
}
|
|
||||||
|
|
||||||
tabuList.push_back(_sol);
|
|
||||||
|
|
||||||
if(currentSize==maxSize)
|
|
||||||
{
|
|
||||||
tabuList.erase(tabuList.begin());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
currentSize++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
if (currentSize!=0)
|
||||||
update ()
|
{
|
||||||
{
|
// Useful in the case of a solution has been kept thanks to the moAspirCrit.
|
||||||
//nothing to do
|
// In this case, the solution can already be in the tabuList.
|
||||||
}
|
removeSolution(_sol);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
tabuList.push_back(_sol);
|
||||||
init ()
|
|
||||||
{
|
|
||||||
//nothing to do
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
if (currentSize==maxSize)
|
||||||
|
{
|
||||||
//! Procedure that removes a given solution from the tabu list (if it is into, else does nothing).
|
tabuList.erase(tabuList.begin());
|
||||||
/*!
|
}
|
||||||
\param __sol A given solution.
|
else
|
||||||
*/
|
{
|
||||||
void
|
currentSize++;
|
||||||
removeSolution(const EOT & __sol)
|
}
|
||||||
{
|
|
||||||
typename std::list<EOT>::iterator it;
|
|
||||||
|
|
||||||
it=tabuList.begin();
|
|
||||||
while(it!=tabuList.end()&&(!((*it)==__sol)))
|
|
||||||
{
|
|
||||||
it++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(it!=tabuList.end())
|
void
|
||||||
{
|
update ()
|
||||||
tabuList.erase(it);
|
{
|
||||||
}
|
//nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
//! The maximum size of the tabu list.
|
|
||||||
unsigned int maxSize;
|
|
||||||
|
|
||||||
//! The current size of the tabu list.
|
void
|
||||||
unsigned int currentSize;
|
init ()
|
||||||
|
{
|
||||||
//! The solution tabu list.
|
//nothing to do
|
||||||
std::list<EOT> tabuList;
|
}
|
||||||
};
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
//! Procedure that removes a given solution from the tabu list (if it is into, else does nothing).
|
||||||
|
/*!
|
||||||
|
\param __sol A given solution.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
removeSolution(const EOT & __sol)
|
||||||
|
{
|
||||||
|
typename std::list<EOT>::iterator it;
|
||||||
|
|
||||||
|
it=tabuList.begin();
|
||||||
|
while (it!=tabuList.end()&&(!((*it)==__sol)))
|
||||||
|
{
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (it!=tabuList.end())
|
||||||
|
{
|
||||||
|
tabuList.erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//! The maximum size of the tabu list.
|
||||||
|
unsigned int maxSize;
|
||||||
|
|
||||||
|
//! The current size of the tabu list.
|
||||||
|
unsigned int currentSize;
|
||||||
|
|
||||||
|
//! The solution tabu list.
|
||||||
|
std::list<EOT> tabuList;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <moSolContinue.h>
|
* <moSolContinue.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
|
||||||
|
|
@ -41,18 +41,18 @@
|
||||||
|
|
||||||
//! Class that describes a stop 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).
|
It allows to add an initialisation procedure to an object that is a unary function (eoUF).
|
||||||
*/
|
*/
|
||||||
template < class EOT > class moSolContinue:public eoUF < const EOT &, bool >
|
template < class EOT > class moSolContinue:public eoUF < const EOT &, bool >
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! Procedure which initialises all that the stop criterion needs
|
//! Procedure which initialises all that the stop criterion needs
|
||||||
/*!
|
/*!
|
||||||
Generally, it allocates some data structures or initialises some counters.
|
Generally, it allocates some data structures or initialises some counters.
|
||||||
*/
|
*/
|
||||||
virtual void init () = 0;
|
virtual void init () = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <moSteadyFitSolContinue.h>
|
* <moSteadyFitSolContinue.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,100 +44,100 @@
|
||||||
The stop criterion corresponds to a maximum number of iterations without improvement (after a minimum number of iterations).
|
The stop criterion corresponds to a maximum number of iterations without improvement (after a minimum number of iterations).
|
||||||
*/
|
*/
|
||||||
template < class EOT > class moSteadyFitSolContinue:public moSolContinue < EOT >
|
template < class EOT > class moSteadyFitSolContinue:public moSolContinue < EOT >
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
//! Alias for the fitness.
|
|
||||||
typedef typename EOT::Fitness Fitness;
|
|
||||||
|
|
||||||
//! Basic constructor.
|
|
||||||
/*!
|
|
||||||
\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.
|
|
||||||
*/
|
|
||||||
moSteadyFitSolContinue (unsigned int __maxNumberOfIterations, unsigned int __maxNumberOfIterationWithoutImprovement)
|
|
||||||
: maxNumberOfIterations (__maxNumberOfIterations), maxNumberOfIterationsWithoutImprovement(__maxNumberOfIterationWithoutImprovement),
|
|
||||||
maxNumberOfIterationsReached(false), firstFitnessSaved(true), counter(0)
|
|
||||||
{}
|
|
||||||
|
|
||||||
//! Function that activates the stopping criterion.
|
|
||||||
/*!
|
|
||||||
Indicates if the fitness has not been improved since a number of iterations (after a minimum of iterations).
|
|
||||||
|
|
||||||
\param __sol the current solution.
|
|
||||||
\return true or false.
|
|
||||||
*/
|
|
||||||
bool operator () (const EOT & __sol)
|
|
||||||
{
|
{
|
||||||
if(!maxNumberOfIterationsReached)
|
|
||||||
{
|
|
||||||
maxNumberOfIterationsReached=((++counter)==maxNumberOfIterations);
|
|
||||||
if(maxNumberOfIterationsReached)
|
|
||||||
{
|
|
||||||
std::cout << "moSteadyFitSolContinue: Done the minimum number of iterations [" << counter << "]." << std::endl;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(__sol.invalid())
|
public:
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(firstFitnessSaved)
|
//! Alias for the fitness.
|
||||||
{
|
typedef typename EOT::Fitness Fitness;
|
||||||
fitness=__sol.fitness();
|
|
||||||
counter=0;
|
|
||||||
firstFitnessSaved=false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
counter++;
|
|
||||||
|
|
||||||
if( __sol.fitness() > fitness )
|
//! Basic constructor.
|
||||||
{
|
/*!
|
||||||
fitness=__sol.fitness();
|
\param __maxNumberOfIterations The number of iterations to reach before looking for the fitness.
|
||||||
counter=0;
|
\param __maxNumberOfIterationWithoutImprovement The number of iterations without fitness improvement to reach for stop.
|
||||||
}
|
*/
|
||||||
|
moSteadyFitSolContinue (unsigned int __maxNumberOfIterations, unsigned int __maxNumberOfIterationWithoutImprovement)
|
||||||
if(counter==maxNumberOfIterationsWithoutImprovement)
|
: maxNumberOfIterations (__maxNumberOfIterations), maxNumberOfIterationsWithoutImprovement(__maxNumberOfIterationWithoutImprovement),
|
||||||
{
|
maxNumberOfIterationsReached(false), firstFitnessSaved(true), counter(0)
|
||||||
std::cout << "moSteadyFitSolContinue: Done [" << counter << "] iterations without improvement." << std::endl;
|
{}
|
||||||
}
|
|
||||||
return counter!=maxNumberOfIterationsWithoutImprovement;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Procedure which allows to initialise the stuff needed.
|
//! Function that activates the stopping criterion.
|
||||||
/*!
|
/*!
|
||||||
It can be also used to reinitialize the counter all the needed things.
|
Indicates if the fitness has not been improved since a number of iterations (after a minimum of iterations).
|
||||||
*/
|
|
||||||
void init ()
|
|
||||||
{
|
|
||||||
maxNumberOfIterationsReached=false;
|
|
||||||
counter=0;
|
|
||||||
firstFitnessSaved=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
\param __sol the current solution.
|
||||||
|
\return true or false.
|
||||||
|
*/
|
||||||
|
bool operator () (const EOT & __sol)
|
||||||
|
{
|
||||||
|
if (!maxNumberOfIterationsReached)
|
||||||
|
{
|
||||||
|
maxNumberOfIterationsReached=((++counter)==maxNumberOfIterations);
|
||||||
|
if (maxNumberOfIterationsReached)
|
||||||
|
{
|
||||||
|
std::cout << "moSteadyFitSolContinue: Done the minimum number of iterations [" << counter << "]." << std::endl;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//! Maximum number of iterations before considering the fitness.
|
if (__sol.invalid())
|
||||||
unsigned int maxNumberOfIterations;
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//! Maximum number of iterations without improvement allowed.
|
if (firstFitnessSaved)
|
||||||
unsigned int maxNumberOfIterationsWithoutImprovement;
|
{
|
||||||
|
fitness=__sol.fitness();
|
||||||
|
counter=0;
|
||||||
|
firstFitnessSaved=false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//! Flag that indicates that the maxNumberIteration have been reached.
|
counter++;
|
||||||
bool maxNumberOfIterationsReached;
|
|
||||||
|
|
||||||
//! Flag that this is the first time that the fitness is used.
|
if ( __sol.fitness() > fitness )
|
||||||
bool firstFitnessSaved;
|
{
|
||||||
|
fitness=__sol.fitness();
|
||||||
|
counter=0;
|
||||||
|
}
|
||||||
|
|
||||||
//! Current Fitness.
|
if (counter==maxNumberOfIterationsWithoutImprovement)
|
||||||
Fitness fitness;
|
{
|
||||||
|
std::cout << "moSteadyFitSolContinue: Done [" << counter << "] iterations without improvement." << std::endl;
|
||||||
|
}
|
||||||
|
return counter!=maxNumberOfIterationsWithoutImprovement;
|
||||||
|
}
|
||||||
|
|
||||||
//! The iteration couter.
|
//! Procedure which allows to initialise the stuff needed.
|
||||||
unsigned int counter;
|
/*!
|
||||||
};
|
It can be also used to reinitialize the counter all the needed things.
|
||||||
|
*/
|
||||||
|
void init ()
|
||||||
|
{
|
||||||
|
maxNumberOfIterationsReached=false;
|
||||||
|
counter=0;
|
||||||
|
firstFitnessSaved=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
//! Maximum number of iterations before considering the fitness.
|
||||||
|
unsigned int maxNumberOfIterations;
|
||||||
|
|
||||||
|
//! Maximum number of iterations without improvement allowed.
|
||||||
|
unsigned int maxNumberOfIterationsWithoutImprovement;
|
||||||
|
|
||||||
|
//! Flag that indicates that the maxNumberIteration have been reached.
|
||||||
|
bool maxNumberOfIterationsReached;
|
||||||
|
|
||||||
|
//! Flag that this is the first time that the fitness is used.
|
||||||
|
bool firstFitnessSaved;
|
||||||
|
|
||||||
|
//! Current Fitness.
|
||||||
|
Fitness fitness;
|
||||||
|
|
||||||
|
//! The iteration couter.
|
||||||
|
unsigned int counter;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <moTS.h>
|
* <moTS.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
|
||||||
|
|
@ -52,118 +52,118 @@
|
||||||
Generic algorithm that describes a tabu search.
|
Generic algorithm that describes a tabu search.
|
||||||
*/
|
*/
|
||||||
template < class M > class moTS:public moAlgo < typename M::EOType >
|
template < class M > class moTS: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:
|
||||||
|
|
||||||
//!Constructor of a moTS specifying all the boxes
|
//!Constructor of a moTS specifying all the boxes
|
||||||
/*!
|
/*!
|
||||||
In this constructor, a moTSMoveLoopExpl is instanciated.
|
In this constructor, a moTSMoveLoopExpl is instanciated.
|
||||||
|
|
||||||
\param __move_init move initialisation
|
\param __move_init move initialisation
|
||||||
\param __next_move neighborhood explorer
|
\param __next_move neighborhood explorer
|
||||||
\param __incr_eval efficient evaluation
|
\param __incr_eval efficient evaluation
|
||||||
\param __tabu_list tabu list
|
\param __tabu_list tabu list
|
||||||
\param __aspir_crit aspiration criterion
|
\param __aspir_crit aspiration criterion
|
||||||
\param __cont stop criterion
|
\param __cont stop criterion
|
||||||
\param __full_eval full evaluation function
|
\param __full_eval full evaluation function
|
||||||
*/
|
*/
|
||||||
moTS (moMoveInit < M > &__move_init, moNextMove < M > &__next_move, moMoveIncrEval < M > &__incr_eval, moTabuList < M > &__tabu_list, moAspirCrit < M > &__aspir_crit, moSolContinue < EOT > &__cont, eoEvalFunc < EOT > &__full_eval):move_expl (*new moTSMoveLoopExpl < M >
|
moTS (moMoveInit < M > &__move_init, moNextMove < M > &__next_move, moMoveIncrEval < M > &__incr_eval, moTabuList < M > &__tabu_list, moAspirCrit < M > &__aspir_crit, moSolContinue < EOT > &__cont, eoEvalFunc < EOT > &__full_eval):move_expl (*new moTSMoveLoopExpl < M >
|
||||||
(__move_init, __next_move, __incr_eval, __tabu_list,
|
(__move_init, __next_move, __incr_eval, __tabu_list,
|
||||||
__aspir_crit)), cont (__cont), full_eval (__full_eval)
|
__aspir_crit)), cont (__cont), full_eval (__full_eval)
|
||||||
{}
|
|
||||||
|
|
||||||
//! Constructor with less parameters
|
|
||||||
/*!
|
|
||||||
The explorer is given in the parameters.
|
|
||||||
|
|
||||||
\param __move_expl the explorer (generally different that a moTSMoveLoopExpl)
|
|
||||||
\param __cont stop criterion
|
|
||||||
\param __full_eval full evaluation function
|
|
||||||
*/
|
|
||||||
moTS (moMoveExpl < M > &__move_expl, moSolContinue < EOT > &__cont, eoEvalFunc < EOT > &__full_eval):move_expl (__move_expl),
|
|
||||||
cont (__cont),
|
|
||||||
full_eval (__full_eval)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//! Function which launchs the Tabu Search
|
//! Constructor with less parameters
|
||||||
/*!
|
/*!
|
||||||
Algorithm of the tabu search.
|
The explorer is given in the parameters.
|
||||||
As a moSA or a moHC, it can be used for HYBRIDATION in an evolutionary algorithm.
|
|
||||||
For security a lock (pthread_mutex_t) is closed during the algorithm.
|
|
||||||
|
|
||||||
\param __sol a solution to improve.
|
\param __move_expl the explorer (generally different that a moTSMoveLoopExpl)
|
||||||
\return TRUE.
|
\param __cont stop criterion
|
||||||
*/
|
\param __full_eval full evaluation function
|
||||||
bool operator ()(EOT & __sol)
|
*/
|
||||||
{
|
moTS (moMoveExpl < M > &__move_expl, moSolContinue < EOT > &__cont, eoEvalFunc < EOT > &__full_eval):move_expl (__move_expl),
|
||||||
if (__sol.invalid ())
|
cont (__cont),
|
||||||
{
|
full_eval (__full_eval)
|
||||||
full_eval (__sol);
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
M move;
|
//! Function which launchs the Tabu Search
|
||||||
|
/*!
|
||||||
|
Algorithm of the tabu search.
|
||||||
|
As a moSA or a moHC, it can be used for HYBRIDATION in an evolutionary algorithm.
|
||||||
|
For security a lock (pthread_mutex_t) is closed during the algorithm.
|
||||||
|
|
||||||
EOT best_sol = __sol, new_sol;
|
\param __sol a solution to improve.
|
||||||
|
\return TRUE.
|
||||||
|
*/
|
||||||
|
bool operator ()(EOT & __sol)
|
||||||
|
{
|
||||||
|
if (__sol.invalid ())
|
||||||
|
{
|
||||||
|
full_eval (__sol);
|
||||||
|
}
|
||||||
|
|
||||||
cont.init ();
|
M move;
|
||||||
|
|
||||||
do
|
EOT best_sol = __sol, new_sol;
|
||||||
{
|
|
||||||
|
|
||||||
new_sol = __sol;
|
cont.init ();
|
||||||
|
|
||||||
try
|
do
|
||||||
{
|
{
|
||||||
|
|
||||||
move_expl (__sol, new_sol);
|
new_sol = __sol;
|
||||||
|
|
||||||
}
|
try
|
||||||
catch (EmptySelection & __ex)
|
{
|
||||||
{
|
|
||||||
|
|
||||||
break;
|
move_expl (__sol, new_sol);
|
||||||
}
|
|
||||||
|
|
||||||
/* Updating the best solution
|
}
|
||||||
found until now ? */
|
catch (EmptySelection & __ex)
|
||||||
if (new_sol.fitness () > __sol.fitness ())
|
{
|
||||||
{
|
|
||||||
best_sol = new_sol;
|
|
||||||
}
|
|
||||||
|
|
||||||
__sol = new_sol;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
/* Updating the best solution
|
||||||
while (cont (__sol));
|
found until now ? */
|
||||||
|
if (new_sol.fitness () > __sol.fitness ())
|
||||||
|
{
|
||||||
|
best_sol = new_sol;
|
||||||
|
}
|
||||||
|
|
||||||
__sol = best_sol;
|
__sol = new_sol;
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
}
|
||||||
|
while (cont (__sol));
|
||||||
|
|
||||||
//! Neighborhood explorer
|
__sol = best_sol;
|
||||||
moMoveExpl < M > &move_expl;
|
|
||||||
|
|
||||||
//! Stop criterion
|
return true;
|
||||||
moSolContinue < EOT > &cont;
|
}
|
||||||
|
|
||||||
//! Full evaluation function
|
private:
|
||||||
eoEvalFunc < EOT > &full_eval;
|
|
||||||
};
|
//! Neighborhood explorer
|
||||||
|
moMoveExpl < M > &move_expl;
|
||||||
|
|
||||||
|
//! Stop criterion
|
||||||
|
moSolContinue < EOT > &cont;
|
||||||
|
|
||||||
|
//! Full evaluation function
|
||||||
|
eoEvalFunc < EOT > &full_eval;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <moTSMoveLoopExpl.h>
|
* <moTSMoveLoopExpl.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
|
||||||
|
|
@ -53,105 +53,105 @@
|
||||||
It is used by a moTS.
|
It is used by a moTS.
|
||||||
*/
|
*/
|
||||||
template < class M > class moTSMoveLoopExpl:public moMoveLoopExpl < M >
|
template < class M > class moTSMoveLoopExpl:public moMoveLoopExpl < M >
|
||||||
{
|
|
||||||
|
|
||||||
//!Alias for the type
|
|
||||||
typedef typename M::EOType EOT;
|
|
||||||
|
|
||||||
//!Alias for the fitness
|
|
||||||
typedef typename M::EOType::Fitness Fitness;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
//!Constructor
|
|
||||||
/*!
|
|
||||||
\param __move_init move initialisation
|
|
||||||
\param __next_move neighborhood explorer
|
|
||||||
\param __incr_eval efficient evaluation
|
|
||||||
\param __tabu_list tabu list
|
|
||||||
\param __aspir_crit aspiration criterion
|
|
||||||
*/
|
|
||||||
moTSMoveLoopExpl (moMoveInit < M > &__move_init, moNextMove < M > &__next_move, moMoveIncrEval < M > &__incr_eval, moTabuList < M > &__tabu_list, moAspirCrit < M > &__aspir_crit):
|
|
||||||
move_init (__move_init),
|
|
||||||
next_move (__next_move),
|
|
||||||
incr_eval (__incr_eval),
|
|
||||||
tabu_list (__tabu_list), aspir_crit (__aspir_crit)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
tabu_list.init ();
|
//!Alias for the type
|
||||||
aspir_crit.init ();
|
typedef typename M::EOType EOT;
|
||||||
}
|
|
||||||
|
|
||||||
//!Procedure which lauches the exploration
|
//!Alias for the fitness
|
||||||
/*!
|
typedef typename M::EOType::Fitness Fitness;
|
||||||
The exploration continues while the chosen move is not in the tabu list
|
|
||||||
or the aspiration criterion is true. If these 2 conditions are not true, the
|
|
||||||
exploration stops if the move selector update function returns false.
|
|
||||||
|
|
||||||
\param __old_sol the initial solution
|
public:
|
||||||
\param __new_sol the new solution
|
|
||||||
*/
|
|
||||||
void operator () (const EOT & __old_sol, EOT & __new_sol)
|
|
||||||
{
|
|
||||||
|
|
||||||
M move;
|
//!Constructor
|
||||||
|
/*!
|
||||||
|
\param __move_init move initialisation
|
||||||
|
\param __next_move neighborhood explorer
|
||||||
|
\param __incr_eval efficient evaluation
|
||||||
|
\param __tabu_list tabu list
|
||||||
|
\param __aspir_crit aspiration criterion
|
||||||
|
*/
|
||||||
|
moTSMoveLoopExpl (moMoveInit < M > &__move_init, moNextMove < M > &__next_move, moMoveIncrEval < M > &__incr_eval, moTabuList < M > &__tabu_list, moAspirCrit < M > &__aspir_crit):
|
||||||
|
move_init (__move_init),
|
||||||
|
next_move (__next_move),
|
||||||
|
incr_eval (__incr_eval),
|
||||||
|
tabu_list (__tabu_list), aspir_crit (__aspir_crit)
|
||||||
|
{
|
||||||
|
|
||||||
|
tabu_list.init ();
|
||||||
|
aspir_crit.init ();
|
||||||
|
}
|
||||||
|
|
||||||
|
//!Procedure which lauches the exploration
|
||||||
|
/*!
|
||||||
|
The exploration continues while the chosen move is not in the tabu list
|
||||||
|
or the aspiration criterion is true. If these 2 conditions are not true, the
|
||||||
|
exploration stops if the move selector update function returns false.
|
||||||
|
|
||||||
|
\param __old_sol the initial solution
|
||||||
|
\param __new_sol the new solution
|
||||||
|
*/
|
||||||
|
void operator () (const EOT & __old_sol, EOT & __new_sol)
|
||||||
|
{
|
||||||
|
|
||||||
|
M move;
|
||||||
|
|
||||||
|
|
||||||
move_init (move, __old_sol); /* Restarting the exploration of
|
move_init (move, __old_sol); /* Restarting the exploration of
|
||||||
of the neighborhood ! */
|
of the neighborhood ! */
|
||||||
|
|
||||||
move_select.init (__old_sol.fitness ());
|
move_select.init (__old_sol.fitness ());
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
|
||||||
Fitness fit = incr_eval (move, __old_sol);
|
Fitness fit = incr_eval (move, __old_sol);
|
||||||
|
|
||||||
if (!tabu_list (move, __old_sol) || aspir_crit (move, fit))
|
if (!tabu_list (move, __old_sol) || aspir_crit (move, fit))
|
||||||
{
|
{
|
||||||
if (!move_select.update (move, fit))
|
if (!move_select.update (move, fit))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
while (next_move (move, __old_sol));
|
while (next_move (move, __old_sol));
|
||||||
|
|
||||||
M best_move;
|
M best_move;
|
||||||
|
|
||||||
Fitness best_move_fit;
|
Fitness best_move_fit;
|
||||||
|
|
||||||
move_select (best_move, best_move_fit);
|
move_select (best_move, best_move_fit);
|
||||||
|
|
||||||
__new_sol.fitness (best_move_fit);
|
__new_sol.fitness (best_move_fit);
|
||||||
best_move (__new_sol);
|
best_move (__new_sol);
|
||||||
|
|
||||||
/* Removing moves that are
|
/* Removing moves that are
|
||||||
no more tabu */
|
no more tabu */
|
||||||
tabu_list.update ();
|
tabu_list.update ();
|
||||||
|
|
||||||
// Updating the tabu list
|
// Updating the tabu list
|
||||||
tabu_list.add (best_move, __new_sol);
|
tabu_list.add (best_move, __new_sol);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
//!Move initialisation
|
//!Move initialisation
|
||||||
moMoveInit < M > &move_init;
|
moMoveInit < M > &move_init;
|
||||||
|
|
||||||
//!Neighborhood explorer
|
//!Neighborhood explorer
|
||||||
moNextMove < M > &next_move;
|
moNextMove < M > &next_move;
|
||||||
|
|
||||||
//!Efficient evaluation
|
//!Efficient evaluation
|
||||||
moMoveIncrEval < M > &incr_eval;
|
moMoveIncrEval < M > &incr_eval;
|
||||||
|
|
||||||
//!Move selector
|
//!Move selector
|
||||||
moBestImprSelect < M > move_select;
|
moBestImprSelect < M > move_select;
|
||||||
|
|
||||||
//!Tabu list
|
//!Tabu list
|
||||||
moTabuList < M > &tabu_list;
|
moTabuList < M > &tabu_list;
|
||||||
|
|
||||||
//!Aspiration criterion
|
//!Aspiration criterion
|
||||||
moAspirCrit < M > &aspir_crit;
|
moAspirCrit < M > &aspir_crit;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <moTabuList.h>
|
* <moTabuList.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,37 +45,37 @@
|
||||||
to be used in a moTS.
|
to be used in a moTS.
|
||||||
*/
|
*/
|
||||||
template < class M > class moTabuList:public eoBF < const M &, const typename
|
template < class M > class moTabuList:public eoBF < const M &, const typename
|
||||||
M::EOType &,
|
M::EOType &,
|
||||||
bool >
|
bool >
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! Alias for the type
|
//! Alias for the type
|
||||||
typedef typename M::EOType EOT;
|
typedef typename M::EOType EOT;
|
||||||
|
|
||||||
//! Procedure to add a move in the tabu list
|
//! Procedure to add a move in the tabu list
|
||||||
/*!
|
/*!
|
||||||
The two parameters have not to be modified so they are constant parameters.
|
The two parameters have not to be modified so they are constant parameters.
|
||||||
|
|
||||||
\param __move a new tabu move.
|
\param __move a new tabu move.
|
||||||
\param __sol the origianl solution associated to this move.
|
\param __sol the origianl solution associated to this move.
|
||||||
*/
|
*/
|
||||||
virtual void
|
virtual void
|
||||||
add (const M & __move, const EOT & __sol) = 0;
|
add (const M & __move, const EOT & __sol) = 0;
|
||||||
|
|
||||||
//! Procedure that updates the tabu list content.
|
//! Procedure that updates the tabu list content.
|
||||||
/*!
|
/*!
|
||||||
Generally, a counter associated to each saved move is decreased by one.
|
Generally, a counter associated to each saved move is decreased by one.
|
||||||
*/
|
*/
|
||||||
virtual void
|
virtual void
|
||||||
update () = 0;
|
update () = 0;
|
||||||
|
|
||||||
//! Procedure which initialises the tabu list.
|
//! Procedure which initialises the tabu list.
|
||||||
/*!
|
/*!
|
||||||
Can be useful if the data structure needs to be allocated before being used.
|
Can be useful if the data structure needs to be allocated before being used.
|
||||||
*/
|
*/
|
||||||
virtual void
|
virtual void
|
||||||
init () = 0;
|
init () = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <t-mo.cpp>
|
* <t-mo.cpp>
|
||||||
* 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
|
||||||
|
|
@ -51,7 +51,7 @@ int main()
|
||||||
Chrom chrom1, chrom2;
|
Chrom chrom1, chrom2;
|
||||||
|
|
||||||
std::cout << "chrom1 = " << chrom1 << std::endl
|
std::cout << "chrom1 = " << chrom1 << std::endl
|
||||||
<< "chrom2 = " << chrom2 << std::endl;
|
<< "chrom2 = " << chrom2 << std::endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <hill_climbing.cpp>
|
* <hill_climbing.cpp>
|
||||||
* 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,37 +38,38 @@
|
||||||
#include <tsp>
|
#include <tsp>
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int __argc, char * __argv [])
|
main (int __argc, char * __argv [])
|
||||||
{
|
{
|
||||||
if (__argc != 2) {
|
if (__argc != 2)
|
||||||
|
{
|
||||||
std :: cerr << "Usage : ./hill_climbing [instance]" << std :: endl ;
|
|
||||||
return 1 ;
|
std :: cerr << "Usage : ./hill_climbing [instance]" << std :: endl ;
|
||||||
}
|
return 1 ;
|
||||||
|
}
|
||||||
|
|
||||||
srand (1000) ;
|
srand (1000) ;
|
||||||
|
|
||||||
Graph :: load (__argv [1]) ; // Instance
|
Graph :: load (__argv [1]) ; // Instance
|
||||||
|
|
||||||
Route route ; // Solution
|
Route route ; // Solution
|
||||||
|
|
||||||
RouteInit init ; // Sol. Random Init.
|
RouteInit init ; // Sol. Random Init.
|
||||||
init (route) ;
|
init (route) ;
|
||||||
|
|
||||||
RouteEval full_eval ; // Full. Eval.
|
RouteEval full_eval ; // Full. Eval.
|
||||||
full_eval (route) ;
|
full_eval (route) ;
|
||||||
|
|
||||||
std :: cout << "[From] " << route << std :: endl ;
|
std :: cout << "[From] " << route << std :: endl ;
|
||||||
|
|
||||||
/* Tools for an efficient (? :-))
|
/* Tools for an efficient (? :-))
|
||||||
local search ! */
|
local search ! */
|
||||||
|
|
||||||
TwoOptInit two_opt_init ; // Init.
|
TwoOptInit two_opt_init ; // Init.
|
||||||
|
|
||||||
TwoOptNext two_opt_next ; // Explorer.
|
TwoOptNext two_opt_next ; // Explorer.
|
||||||
|
|
||||||
TwoOptIncrEval two_opt_incr_eval ; // Eff. eval.
|
TwoOptIncrEval two_opt_incr_eval ; // Eff. eval.
|
||||||
|
|
||||||
//moFirstImprSelect <TwoOpt> two_opt_select ;
|
//moFirstImprSelect <TwoOpt> two_opt_select ;
|
||||||
moBestImprSelect <TwoOpt> two_opt_select ;
|
moBestImprSelect <TwoOpt> two_opt_select ;
|
||||||
//moRandImprSelect <TwoOpt> two_opt_select ;
|
//moRandImprSelect <TwoOpt> two_opt_select ;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <tabu_search.cpp>
|
* <tabu_search.cpp>
|
||||||
* 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,33 +38,33 @@
|
||||||
#include <tsp>
|
#include <tsp>
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int __argc, char * __argv [])
|
main (int __argc, char * __argv [])
|
||||||
{
|
{
|
||||||
if (__argc != 2)
|
if (__argc != 2)
|
||||||
{
|
{
|
||||||
std :: cerr << "Usage : ./tabu_search [instance]" << std :: endl ;
|
std :: cerr << "Usage : ./tabu_search [instance]" << std :: endl ;
|
||||||
return 1 ;
|
return 1 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
Graph :: load (__argv [1]) ; // Instance
|
Graph :: load (__argv [1]) ; // Instance
|
||||||
|
|
||||||
Route route ; // Solution
|
Route route ; // Solution
|
||||||
|
|
||||||
RouteInit init ; // Sol. Random Init.
|
RouteInit init ; // Sol. Random Init.
|
||||||
init (route) ;
|
init (route) ;
|
||||||
|
|
||||||
RouteEval full_eval ; // Full. Eval.
|
RouteEval full_eval ; // Full. Eval.
|
||||||
full_eval (route) ;
|
full_eval (route) ;
|
||||||
|
|
||||||
std :: cout << "[From] " << route << std :: endl ;
|
std :: cout << "[From] " << route << std :: endl ;
|
||||||
|
|
||||||
/* Tools for an efficient (? :-))
|
/* Tools for an efficient (? :-))
|
||||||
local search ! */
|
local search ! */
|
||||||
|
|
||||||
TwoOptInit two_opt_init ; // Init.
|
TwoOptInit two_opt_init ; // Init.
|
||||||
|
|
||||||
TwoOptNext two_opt_next ; // Explorer.
|
TwoOptNext two_opt_next ; // Explorer.
|
||||||
|
|
||||||
TwoOptIncrEval two_opt_incr_eval ; // Eff. eval.
|
TwoOptIncrEval two_opt_incr_eval ; // Eff. eval.
|
||||||
|
|
||||||
TwoOptTabuList tabu_list ; // Tabu List
|
TwoOptTabuList tabu_list ; // Tabu List
|
||||||
|
|
@ -77,9 +77,9 @@ main (int __argc, char * __argv [])
|
||||||
|
|
||||||
moTS <TwoOpt> tabu_search (two_opt_init, two_opt_next, two_opt_incr_eval, tabu_list, aspir_crit, cont, full_eval) ;
|
moTS <TwoOpt> tabu_search (two_opt_init, two_opt_next, two_opt_incr_eval, tabu_list, aspir_crit, cont, full_eval) ;
|
||||||
tabu_search (route) ;
|
tabu_search (route) ;
|
||||||
|
|
||||||
std :: cout << "[To] " << route << std :: endl ;
|
std :: cout << "[To] " << route << std :: endl ;
|
||||||
|
|
||||||
return 0 ;
|
return 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <simulated_annealing.cpp>
|
* <simulated_annealing.cpp>
|
||||||
* 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,47 +38,47 @@
|
||||||
#include <tsp>
|
#include <tsp>
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int __argc, char * __argv [])
|
main (int __argc, char * __argv [])
|
||||||
{
|
{
|
||||||
if (__argc != 2)
|
if (__argc != 2)
|
||||||
{
|
{
|
||||||
std :: cerr << "Usage : ./simulated_annealing [instance]" << std :: endl ;
|
std :: cerr << "Usage : ./simulated_annealing [instance]" << std :: endl ;
|
||||||
return 1 ;
|
return 1 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
Graph :: load (__argv [1]) ; // Instance
|
Graph :: load (__argv [1]) ; // Instance
|
||||||
|
|
||||||
Route route ; // Solution
|
Route route ; // Solution
|
||||||
|
|
||||||
RouteInit init ; // Sol. Random Init.
|
RouteInit init ; // Sol. Random Init.
|
||||||
init (route) ;
|
init (route) ;
|
||||||
|
|
||||||
RouteEval full_eval ; // Full. Eval.
|
RouteEval full_eval ; // Full. Eval.
|
||||||
full_eval (route) ;
|
full_eval (route) ;
|
||||||
|
|
||||||
std :: cout << "[From] " << route << std :: endl ;
|
std :: cout << "[From] " << route << std :: endl ;
|
||||||
|
|
||||||
/* Tools for an efficient (? :-))
|
/* Tools for an efficient (? :-))
|
||||||
local search ! */
|
local search ! */
|
||||||
|
|
||||||
TwoOptRand two_opt_rand ; // Route Random. Gen.
|
TwoOptRand two_opt_rand ; // Route Random. Gen.
|
||||||
|
|
||||||
TwoOptIncrEval two_opt_incr_eval ; // Eff. eval.
|
TwoOptIncrEval two_opt_incr_eval ; // Eff. eval.
|
||||||
|
|
||||||
TwoOpt move ;
|
TwoOpt move ;
|
||||||
|
|
||||||
moExponentialCoolingSchedule cool_sched (0.1, 0.98) ; // Exponential Cooling Schedule
|
moExponentialCoolingSchedule cool_sched (0.1, 0.98) ; // Exponential Cooling Schedule
|
||||||
//moLinearCoolingSchedule cool_sched (0.1, 0.5) ; // Linear Cooling Schedule
|
//moLinearCoolingSchedule cool_sched (0.1, 0.5) ; // Linear Cooling Schedule
|
||||||
|
|
||||||
moGenSolContinue <Route> cont (1000) ; /* Temperature Descreasing
|
moGenSolContinue <Route> cont (1000) ; /* Temperature Descreasing
|
||||||
will occur each 1000
|
will occur each 1000
|
||||||
iterations */
|
iterations */
|
||||||
|
|
||||||
moSA <TwoOpt> simulated_annealing (two_opt_rand, two_opt_incr_eval, cont, 1000, cool_sched, full_eval) ;
|
moSA <TwoOpt> simulated_annealing (two_opt_rand, two_opt_incr_eval, cont, 1000, cool_sched, full_eval) ;
|
||||||
simulated_annealing (route) ;
|
simulated_annealing (route) ;
|
||||||
|
|
||||||
std :: cout << "[To] " << route << std :: endl ;
|
std :: cout << "[To] " << route << std :: endl ;
|
||||||
|
|
||||||
return 0 ;
|
return 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,46 +13,46 @@
|
||||||
#include <tsp>
|
#include <tsp>
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int __argc, char * __argv [])
|
main (int __argc, char * __argv [])
|
||||||
{
|
{
|
||||||
if (__argc != 2)
|
if (__argc != 2)
|
||||||
{
|
{
|
||||||
std :: cerr << "Usage : ./iterated_local_search [instance]" << std :: endl ;
|
std :: cerr << "Usage : ./iterated_local_search [instance]" << std :: endl ;
|
||||||
return 1 ;
|
return 1 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
Graph :: load (__argv [1]) ; // Instance
|
Graph :: load (__argv [1]) ; // Instance
|
||||||
|
|
||||||
Route route ; // Solution
|
Route route ; // Solution
|
||||||
|
|
||||||
RouteInit init ; // Sol. Random Init.
|
RouteInit init ; // Sol. Random Init.
|
||||||
init (route) ;
|
init (route) ;
|
||||||
|
|
||||||
RouteEval full_eval ; // Full. Eval.
|
RouteEval full_eval ; // Full. Eval.
|
||||||
full_eval (route) ;
|
full_eval (route) ;
|
||||||
|
|
||||||
std :: cout << "[From] " << route << std :: endl ;
|
std :: cout << "[From] " << route << std :: endl ;
|
||||||
|
|
||||||
TwoOptInit two_opt_init ; // Init.
|
TwoOptInit two_opt_init ; // Init.
|
||||||
|
|
||||||
TwoOptNext two_opt_next ; // Explorer.
|
TwoOptNext two_opt_next ; // Explorer.
|
||||||
|
|
||||||
TwoOptIncrEval two_opt_incr_eval ; // Eff. eval.
|
TwoOptIncrEval two_opt_incr_eval ; // Eff. eval.
|
||||||
|
|
||||||
moBestImprSelect <TwoOpt> two_opt_select ; //Move selection
|
moBestImprSelect <TwoOpt> two_opt_select ; //Move selection
|
||||||
|
|
||||||
moGenSolContinue <Route> cont (1000) ; //Stopping criterion
|
moGenSolContinue <Route> cont (1000) ; //Stopping criterion
|
||||||
|
|
||||||
moFitComparator<Route> comparator; // Route comparator
|
moFitComparator<Route> comparator; // Route comparator
|
||||||
|
|
||||||
CitySwap perturbation; // Route perturbation
|
CitySwap perturbation; // Route perturbation
|
||||||
|
|
||||||
moILS<TwoOpt> iterated_local_search (two_opt_init, two_opt_next, two_opt_incr_eval, two_opt_select,
|
moILS<TwoOpt> iterated_local_search (two_opt_init, two_opt_next, two_opt_incr_eval, two_opt_select,
|
||||||
cont, comparator, perturbation, full_eval) ;
|
cont, comparator, perturbation, full_eval) ;
|
||||||
iterated_local_search(route) ;
|
iterated_local_search(route) ;
|
||||||
|
|
||||||
std :: cout << "[To] " << route << std :: endl ;
|
std :: cout << "[To] " << route << std :: endl ;
|
||||||
|
|
||||||
return 0 ;
|
return 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <city_swap.cpp>
|
* <city_swap.cpp>
|
||||||
* 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,12 +38,13 @@
|
||||||
|
|
||||||
#include "city_swap.h"
|
#include "city_swap.h"
|
||||||
|
|
||||||
bool CitySwap :: operator () (Route & __route) {
|
bool CitySwap :: operator () (Route & __route)
|
||||||
|
{
|
||||||
|
|
||||||
std :: swap (__route [rng.random (__route.size ())],
|
std :: swap (__route [rng.random (__route.size ())],
|
||||||
__route [rng.random (__route.size ())]) ;
|
__route [rng.random (__route.size ())]) ;
|
||||||
|
|
||||||
__route.invalidate () ;
|
__route.invalidate () ;
|
||||||
|
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <city_swap.h>
|
* <city_swap.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
|
||||||
|
|
@ -43,12 +43,13 @@
|
||||||
|
|
||||||
/** Its swaps two vertices
|
/** Its swaps two vertices
|
||||||
randomly choosen */
|
randomly choosen */
|
||||||
class CitySwap : public eoMonOp <Route> {
|
class CitySwap : public eoMonOp <Route>
|
||||||
|
{
|
||||||
public :
|
|
||||||
|
public :
|
||||||
bool operator () (Route & __route) ;
|
|
||||||
|
bool operator () (Route & __route) ;
|
||||||
} ;
|
|
||||||
|
} ;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <edge_xover.cpp>
|
* <edge_xover.cpp>
|
||||||
* 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,119 +44,121 @@
|
||||||
#define MAXINT 1000000
|
#define MAXINT 1000000
|
||||||
|
|
||||||
void
|
void
|
||||||
EdgeXover :: build_map (const Route & __par1, const Route & __par2)
|
EdgeXover :: build_map (const Route & __par1, const Route & __par2)
|
||||||
{
|
{
|
||||||
|
|
||||||
unsigned int len = __par1.size () ;
|
unsigned int len = __par1.size () ;
|
||||||
|
|
||||||
/* Initialization */
|
/* Initialization */
|
||||||
_map.clear () ;
|
_map.clear () ;
|
||||||
_map.resize (len) ;
|
_map.resize (len) ;
|
||||||
|
|
||||||
for (unsigned int i = 0 ; i < len ; i ++)
|
for (unsigned int i = 0 ; i < len ; i ++)
|
||||||
{
|
{
|
||||||
_map [__par1 [i]].insert (__par1 [(i + 1) % len]) ;
|
_map [__par1 [i]].insert (__par1 [(i + 1) % len]) ;
|
||||||
_map [__par2 [i]].insert (__par2 [(i + 1) % len]) ;
|
_map [__par2 [i]].insert (__par2 [(i + 1) % len]) ;
|
||||||
_map [__par1 [i]].insert (__par1 [(i - 1 + len) % len]) ;
|
_map [__par1 [i]].insert (__par1 [(i - 1 + len) % len]) ;
|
||||||
_map [__par2 [i]].insert (__par2 [(i - 1 + len) % len]) ;
|
_map [__par2 [i]].insert (__par2 [(i - 1 + len) % len]) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
visited.clear () ;
|
visited.clear () ;
|
||||||
visited.resize (len, false) ;
|
visited.resize (len, false) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
EdgeXover :: remove_entry (unsigned int __vertex, std :: vector <std :: set <unsigned int> > & __map)
|
EdgeXover :: remove_entry (unsigned int __vertex, std :: vector <std :: set <unsigned int> > & __map)
|
||||||
{
|
{
|
||||||
|
|
||||||
std :: set <unsigned int> & neigh = __map [__vertex] ;
|
|
||||||
|
|
||||||
for (std :: set <unsigned int> :: iterator it = neigh.begin () ; it != neigh.end () ; it ++)
|
std :: set <unsigned int> & neigh = __map [__vertex] ;
|
||||||
{
|
|
||||||
__map [* it].erase (__vertex) ;
|
for (std :: set <unsigned int> :: iterator it = neigh.begin () ; it != neigh.end () ; it ++)
|
||||||
}
|
{
|
||||||
|
__map [* it].erase (__vertex) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
EdgeXover :: add_vertex (unsigned int __vertex, Route & __child)
|
EdgeXover :: add_vertex (unsigned int __vertex, Route & __child)
|
||||||
{
|
{
|
||||||
visited [__vertex] = true ;
|
visited [__vertex] = true ;
|
||||||
__child.push_back (__vertex) ;
|
__child.push_back (__vertex) ;
|
||||||
remove_entry (__vertex, _map) ; /* Removing entries */
|
remove_entry (__vertex, _map) ; /* Removing entries */
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
EdgeXover :: cross (const Route & __par1, const Route & __par2, Route & __child) {
|
EdgeXover :: cross (const Route & __par1, const Route & __par2, Route & __child)
|
||||||
|
{
|
||||||
|
|
||||||
build_map (__par1, __par2) ;
|
build_map (__par1, __par2) ;
|
||||||
|
|
||||||
unsigned int len = __par1.size () ;
|
unsigned int len = __par1.size () ;
|
||||||
|
|
||||||
/* Go ! */
|
/* Go ! */
|
||||||
__child.clear () ;
|
__child.clear () ;
|
||||||
|
|
||||||
unsigned int cur_vertex = rng.random (len) ;
|
unsigned int cur_vertex = rng.random (len) ;
|
||||||
|
|
||||||
add_vertex (cur_vertex, __child) ;
|
add_vertex (cur_vertex, __child) ;
|
||||||
|
|
||||||
for (unsigned int i = 1 ; i < len ; i ++) {
|
for (unsigned int i = 1 ; i < len ; i ++)
|
||||||
|
{
|
||||||
unsigned int len_min_entry = MAXINT ;
|
|
||||||
|
unsigned int len_min_entry = MAXINT ;
|
||||||
std :: set <unsigned int> & neigh = _map [cur_vertex] ;
|
|
||||||
|
std :: set <unsigned int> & neigh = _map [cur_vertex] ;
|
||||||
for (std :: set <unsigned int> :: iterator it = neigh.begin () ; it != neigh.end () ; it ++)
|
|
||||||
{
|
for (std :: set <unsigned int> :: iterator it = neigh.begin () ; it != neigh.end () ; it ++)
|
||||||
unsigned int l = _map [* it].size () ;
|
{
|
||||||
if (len_min_entry > l)
|
unsigned int l = _map [* it].size () ;
|
||||||
{
|
if (len_min_entry > l)
|
||||||
len_min_entry = l ;
|
{
|
||||||
}
|
len_min_entry = l ;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
std :: vector <unsigned int> cand ; /* Candidates */
|
|
||||||
|
std :: vector <unsigned int> cand ; /* Candidates */
|
||||||
for (std :: set <unsigned> :: iterator it = neigh.begin () ; it != neigh.end () ; it ++)
|
|
||||||
{
|
for (std :: set <unsigned> :: iterator it = neigh.begin () ; it != neigh.end () ; it ++)
|
||||||
unsigned int l = _map [* it].size () ;
|
{
|
||||||
if (len_min_entry == l)
|
unsigned int l = _map [* it].size () ;
|
||||||
{
|
if (len_min_entry == l)
|
||||||
cand.push_back (* it) ;
|
{
|
||||||
}
|
cand.push_back (* it) ;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (! cand.size ())
|
|
||||||
{
|
if (! cand.size ())
|
||||||
|
{
|
||||||
/* Oh no ! Implicit mutation */
|
|
||||||
for (unsigned int j = 0 ; j < len ; j ++)
|
/* Oh no ! Implicit mutation */
|
||||||
{
|
for (unsigned int j = 0 ; j < len ; j ++)
|
||||||
if (! visited [j])
|
{
|
||||||
{
|
if (! visited [j])
|
||||||
cand.push_back (j) ;
|
{
|
||||||
}
|
cand.push_back (j) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
cur_vertex = cand [rng.random (cand.size ())] ;
|
|
||||||
|
cur_vertex = cand [rng.random (cand.size ())] ;
|
||||||
add_vertex (cur_vertex, __child) ;
|
|
||||||
}
|
add_vertex (cur_vertex, __child) ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
EdgeXover :: operator () (Route & __route1, Route & __route2)
|
EdgeXover :: operator () (Route & __route1, Route & __route2)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Init. copy
|
// Init. copy
|
||||||
Route par [2] ;
|
Route par [2] ;
|
||||||
par [0] = __route1 ;
|
par [0] = __route1 ;
|
||||||
par [1] = __route2 ;
|
par [1] = __route2 ;
|
||||||
|
|
||||||
cross (par [0], par [1], __route1) ;
|
cross (par [0], par [1], __route1) ;
|
||||||
cross (par [1], par [0], __route2) ;
|
cross (par [1], par [0], __route2) ;
|
||||||
|
|
||||||
assert (valid (__route1)) ;
|
assert (valid (__route1)) ;
|
||||||
assert (valid (__route2)) ;
|
assert (valid (__route2)) ;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <edge_xover.h>
|
* <edge_xover.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,28 +45,28 @@
|
||||||
#include "route.h"
|
#include "route.h"
|
||||||
|
|
||||||
/** Edge Crossover */
|
/** Edge Crossover */
|
||||||
class EdgeXover : public eoQuadOp <Route>
|
class EdgeXover : public eoQuadOp <Route>
|
||||||
{
|
{
|
||||||
|
|
||||||
public :
|
|
||||||
|
|
||||||
bool operator () (Route & __route1, Route & __route2) ;
|
|
||||||
|
|
||||||
private :
|
public :
|
||||||
|
|
||||||
void cross (const Route & __par1, const Route & __par2, Route & __child) ; /* Binary */
|
|
||||||
|
|
||||||
void remove_entry (unsigned int __vertex, std :: vector <std :: set <unsigned> > & __map) ;
|
bool operator () (Route & __route1, Route & __route2) ;
|
||||||
/* Updating the map of entries */
|
|
||||||
|
|
||||||
void build_map (const Route & __par1, const Route & __par2) ;
|
private :
|
||||||
|
|
||||||
void add_vertex (unsigned int __vertex, Route & __child) ;
|
void cross (const Route & __par1, const Route & __par2, Route & __child) ; /* Binary */
|
||||||
|
|
||||||
std :: vector <std :: set <unsigned int> > _map ; /* The handled map */
|
void remove_entry (unsigned int __vertex, std :: vector <std :: set <unsigned> > & __map) ;
|
||||||
|
/* Updating the map of entries */
|
||||||
|
|
||||||
std :: vector <bool> visited ; /* Vertices that are already visited */
|
void build_map (const Route & __par1, const Route & __par2) ;
|
||||||
|
|
||||||
} ;
|
void add_vertex (unsigned int __vertex, Route & __child) ;
|
||||||
|
|
||||||
|
std :: vector <std :: set <unsigned int> > _map ; /* The handled map */
|
||||||
|
|
||||||
|
std :: vector <bool> visited ; /* Vertices that are already visited */
|
||||||
|
|
||||||
|
} ;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <graph.cpp>
|
* <graph.cpp>
|
||||||
* 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
|
||||||
|
|
@ -40,73 +40,74 @@
|
||||||
|
|
||||||
#include "graph.h"
|
#include "graph.h"
|
||||||
|
|
||||||
namespace Graph {
|
namespace Graph
|
||||||
|
{
|
||||||
|
|
||||||
static std :: vector <std :: pair <double, double> > vectCoord ; // Coordinates
|
static std :: vector <std :: pair <double, double> > vectCoord ; // Coordinates
|
||||||
|
|
||||||
static std :: vector <std :: vector <unsigned int> > dist ; // Distances Mat.
|
static std :: vector <std :: vector <unsigned int> > dist ; // Distances Mat.
|
||||||
|
|
||||||
unsigned size ()
|
unsigned size ()
|
||||||
{
|
{
|
||||||
return dist.size () ;
|
return dist.size () ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void computeDistances ()
|
void computeDistances ()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Dim.
|
// Dim.
|
||||||
unsigned int numCities = vectCoord.size () ;
|
unsigned int numCities = vectCoord.size () ;
|
||||||
dist.resize (numCities) ;
|
dist.resize (numCities) ;
|
||||||
for (unsigned int i = 0 ; i < dist.size () ; i ++)
|
for (unsigned int i = 0 ; i < dist.size () ; i ++)
|
||||||
{
|
{
|
||||||
dist [i].resize (numCities) ;
|
dist [i].resize (numCities) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Computations.
|
// Computations.
|
||||||
for (unsigned int i = 0 ; i < dist.size () ; i ++)
|
for (unsigned int i = 0 ; i < dist.size () ; i ++)
|
||||||
{
|
{
|
||||||
for (unsigned int j = i + 1 ; j < dist.size () ; j ++)
|
for (unsigned int j = i + 1 ; j < dist.size () ; j ++)
|
||||||
{
|
{
|
||||||
double distX = (double)(vectCoord [i].first - vectCoord [j].first) ;
|
double distX = (double)(vectCoord [i].first - vectCoord [j].first) ;
|
||||||
double distY = (double)(vectCoord [i].second - vectCoord [j].second) ;
|
double distY = (double)(vectCoord [i].second - vectCoord [j].second) ;
|
||||||
dist [i] [j] = dist [j] [i] = (unsigned) (sqrt ((float) (distX * distX + distY * distY)) + 0.5) ;
|
dist [i] [j] = dist [j] [i] = (unsigned) (sqrt ((float) (distX * distX + distY * distY)) + 0.5) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void load (const char * __fileName)
|
void load (const char * __fileName)
|
||||||
{
|
{
|
||||||
|
|
||||||
std :: ifstream f (__fileName) ;
|
std :: ifstream f (__fileName) ;
|
||||||
|
|
||||||
std :: cout << ">> Loading [" << __fileName << "]" << std :: endl ;
|
std :: cout << ">> Loading [" << __fileName << "]" << std :: endl ;
|
||||||
|
|
||||||
if (f)
|
if (f)
|
||||||
{
|
{
|
||||||
unsigned int num_vert ;
|
unsigned int num_vert ;
|
||||||
|
|
||||||
f >> num_vert ;
|
f >> num_vert ;
|
||||||
vectCoord.resize (num_vert) ;
|
vectCoord.resize (num_vert) ;
|
||||||
|
|
||||||
for (unsigned int i = 0 ; i < num_vert ; i ++)
|
for (unsigned int i = 0 ; i < num_vert ; i ++)
|
||||||
{
|
{
|
||||||
f >> vectCoord [i].first >> vectCoord [i].second ;
|
f >> vectCoord [i].first >> vectCoord [i].second ;
|
||||||
}
|
}
|
||||||
|
|
||||||
f.close () ;
|
f.close () ;
|
||||||
|
|
||||||
computeDistances () ;
|
computeDistances () ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
std :: cout << __fileName << " doesn't exist !!!" << std :: endl ;
|
std :: cout << __fileName << " doesn't exist !!!" << std :: endl ;
|
||||||
// Bye !!!
|
// Bye !!!
|
||||||
exit (1) ;
|
exit (1) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float distance (unsigned int __from, unsigned int __to)
|
float distance (unsigned int __from, unsigned int __to)
|
||||||
{
|
{
|
||||||
return (float)(dist [__from] [__to]) ;
|
return (float)(dist [__from] [__to]) ;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <graph.h>
|
* <graph.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
|
||||||
|
|
@ -40,13 +40,13 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace Graph
|
namespace Graph
|
||||||
{
|
{
|
||||||
void load (const char * __file_name) ;
|
void load (const char * __file_name) ;
|
||||||
/* Loading cities
|
/* Loading cities
|
||||||
(expressed by their coordinates)
|
(expressed by their coordinates)
|
||||||
from the given file name */
|
from the given file name */
|
||||||
|
|
||||||
float distance (unsigned int __from, unsigned int __to) ;
|
float distance (unsigned int __from, unsigned int __to) ;
|
||||||
|
|
||||||
unsigned int size () ; // How many cities ?
|
unsigned int size () ; // How many cities ?
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <mix.h>
|
* <mix.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
|
||||||
|
|
@ -39,9 +39,9 @@
|
||||||
|
|
||||||
#include <utils/eoRNG.h>
|
#include <utils/eoRNG.h>
|
||||||
|
|
||||||
template <class T> void mix (std :: vector <T> & __vect)
|
template <class T> void mix (std :: vector <T> & __vect)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0 ; i < __vect.size () ; i ++)
|
for (unsigned int i = 0 ; i < __vect.size () ; i ++)
|
||||||
{
|
{
|
||||||
std :: swap (__vect [i], __vect [rng.random (__vect.size ())]) ;
|
std :: swap (__vect [i], __vect [rng.random (__vect.size ())]) ;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <order_xover.cpp>
|
* <order_xover.cpp>
|
||||||
* 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
|
||||||
|
|
@ -42,73 +42,73 @@
|
||||||
#include "order_xover.h"
|
#include "order_xover.h"
|
||||||
#include "route_valid.h"
|
#include "route_valid.h"
|
||||||
|
|
||||||
void OrderXover :: cross (const Route & __par1, const Route & __par2, Route & __child)
|
void OrderXover :: cross (const Route & __par1, const Route & __par2, Route & __child)
|
||||||
{
|
{
|
||||||
|
|
||||||
unsigned int cut = rng.random (__par1.size ()) ;
|
unsigned int cut = rng.random (__par1.size ()) ;
|
||||||
|
|
||||||
/* To store vertices that have
|
/* To store vertices that have
|
||||||
already been crossed */
|
already been crossed */
|
||||||
std::vector<bool> v;
|
std::vector<bool> v;
|
||||||
v.resize(__par1.size());
|
v.resize(__par1.size());
|
||||||
|
|
||||||
for (unsigned int i = 0 ; i < __par1.size () ; i ++)
|
for (unsigned int i = 0 ; i < __par1.size () ; i ++)
|
||||||
{
|
{
|
||||||
v [i] = false ;
|
v [i] = false ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy of the left partial
|
/* Copy of the left partial
|
||||||
route of the first parent */
|
route of the first parent */
|
||||||
for (unsigned int i = 0 ; i < cut ; i ++)
|
for (unsigned int i = 0 ; i < cut ; i ++)
|
||||||
{
|
{
|
||||||
__child [i] = __par1 [i] ;
|
__child [i] = __par1 [i] ;
|
||||||
v [__par1 [i]] = true ;
|
v [__par1 [i]] = true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Searching the vertex of the second path, that ended
|
/* Searching the vertex of the second path, that ended
|
||||||
the previous first one */
|
the previous first one */
|
||||||
unsigned int from = 0 ;
|
unsigned int from = 0 ;
|
||||||
for (unsigned int i = 0 ; i < __par2.size () ; i ++)
|
for (unsigned int i = 0 ; i < __par2.size () ; i ++)
|
||||||
{
|
{
|
||||||
if (__par2 [i] == __child [cut - 1])
|
if (__par2 [i] == __child [cut - 1])
|
||||||
{
|
{
|
||||||
from = i ;
|
from = i ;
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Selecting a direction
|
/* Selecting a direction
|
||||||
Left or Right */
|
Left or Right */
|
||||||
char direct = rng.flip () ? 1 : -1 ;
|
char direct = rng.flip () ? 1 : -1 ;
|
||||||
|
|
||||||
/* Copy of the left vertices from
|
/* Copy of the left vertices from
|
||||||
the second parent path */
|
the second parent path */
|
||||||
unsigned int l = cut ;
|
unsigned int l = cut ;
|
||||||
|
|
||||||
for (unsigned int i = 0 ; i < __par2.size () ; i ++)
|
for (unsigned int i = 0 ; i < __par2.size () ; i ++)
|
||||||
{
|
{
|
||||||
unsigned int bidule /* :-) */ = (direct * i + from + __par2.size ()) % __par2.size () ;
|
unsigned int bidule /* :-) */ = (direct * i + from + __par2.size ()) % __par2.size () ;
|
||||||
if (! v [__par2 [bidule]])
|
if (! v [__par2 [bidule]])
|
||||||
{
|
{
|
||||||
__child [l ++] = __par2 [bidule] ;
|
__child [l ++] = __par2 [bidule] ;
|
||||||
v [__par2 [bidule]] = true ;
|
v [__par2 [bidule]] = true ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
v.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool OrderXover :: operator () (Route & __route1, Route & __route2)
|
v.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OrderXover :: operator () (Route & __route1, Route & __route2)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Init. copy
|
// Init. copy
|
||||||
Route par [2] ;
|
Route par [2] ;
|
||||||
par [0] = __route1 ;
|
par [0] = __route1 ;
|
||||||
par [1] = __route2 ;
|
par [1] = __route2 ;
|
||||||
|
|
||||||
cross (par [0], par [1], __route1) ;
|
cross (par [0], par [1], __route1) ;
|
||||||
cross (par [1], par [0], __route2) ;
|
cross (par [1], par [0], __route2) ;
|
||||||
|
|
||||||
assert (valid (__route1)) ;
|
assert (valid (__route1)) ;
|
||||||
assert (valid (__route2)) ;
|
assert (valid (__route2)) ;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <order_xover.h>
|
* <order_xover.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
|
||||||
|
|
@ -42,16 +42,16 @@
|
||||||
#include "route.h"
|
#include "route.h"
|
||||||
|
|
||||||
/** Order Crossover */
|
/** Order Crossover */
|
||||||
class OrderXover : public eoQuadOp <Route>
|
class OrderXover : public eoQuadOp <Route>
|
||||||
{
|
{
|
||||||
|
|
||||||
public :
|
public :
|
||||||
|
|
||||||
bool operator () (Route & __route1, Route & __route2) ;
|
bool operator () (Route & __route1, Route & __route2) ;
|
||||||
|
|
||||||
private :
|
private :
|
||||||
|
|
||||||
void cross (const Route & __par1, const Route & __par2, Route & __child) ;
|
void cross (const Route & __par1, const Route & __par2, Route & __child) ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <part_route_eval.cpp>
|
* <part_route_eval.cpp>
|
||||||
* 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,16 +37,17 @@
|
||||||
#include "part_route_eval.h"
|
#include "part_route_eval.h"
|
||||||
#include "graph.h"
|
#include "graph.h"
|
||||||
|
|
||||||
PartRouteEval :: PartRouteEval (float __from, float __to) : from (__from), to (__to) {}
|
PartRouteEval :: PartRouteEval (float __from, float __to) : from (__from), to (__to)
|
||||||
|
{}
|
||||||
|
|
||||||
void PartRouteEval :: operator () (Route & __route)
|
void PartRouteEval :: operator () (Route & __route)
|
||||||
{
|
{
|
||||||
float len = 0 ;
|
float len = 0 ;
|
||||||
|
|
||||||
for (unsigned int i = (unsigned int) (__route.size () * from) ; i < (unsigned int ) (__route.size () * to) ; i ++)
|
for (unsigned int i = (unsigned int) (__route.size () * from) ; i < (unsigned int ) (__route.size () * to) ; i ++)
|
||||||
{
|
{
|
||||||
len -= Graph :: distance (__route [i], __route [(i + 1) % Graph :: size ()]) ;
|
len -= Graph :: distance (__route [i], __route [(i + 1) % Graph :: size ()]) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
__route.fitness (len) ;
|
__route.fitness (len) ;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <part_route_eval.h>
|
* <part_route_eval.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
|
||||||
|
|
@ -42,21 +42,21 @@
|
||||||
#include "route.h"
|
#include "route.h"
|
||||||
|
|
||||||
/** Route Evaluator */
|
/** Route Evaluator */
|
||||||
class PartRouteEval : public eoEvalFunc <Route>
|
class PartRouteEval : public eoEvalFunc <Route>
|
||||||
{
|
{
|
||||||
|
|
||||||
public :
|
|
||||||
|
|
||||||
/** Constructor */
|
|
||||||
PartRouteEval (float __from, float __to) ;
|
|
||||||
|
|
||||||
void operator () (Route & __route) ;
|
|
||||||
|
|
||||||
private :
|
|
||||||
|
|
||||||
float from, to ;
|
public :
|
||||||
|
|
||||||
} ;
|
/** Constructor */
|
||||||
|
PartRouteEval (float __from, float __to) ;
|
||||||
|
|
||||||
|
void operator () (Route & __route) ;
|
||||||
|
|
||||||
|
private :
|
||||||
|
|
||||||
|
float from, to ;
|
||||||
|
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <part_two_opt_init.cpp>
|
* <part_two_opt_init.cpp>
|
||||||
* 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,7 +38,7 @@
|
||||||
|
|
||||||
#include "part_two_opt_init.h"
|
#include "part_two_opt_init.h"
|
||||||
|
|
||||||
void PartTwoOptInit :: operator () (TwoOpt & __move, const Route & __route)
|
void PartTwoOptInit :: operator () (TwoOpt & __move, const Route & __route)
|
||||||
{
|
{
|
||||||
__move.first = rng.random (__route.size () - 6) ;
|
__move.first = rng.random (__route.size () - 6) ;
|
||||||
__move.second = __move.first + 2 ;
|
__move.second = __move.first + 2 ;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <part_two_opt_init.h>
|
* <part_two_opt_init.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
|
||||||
|
|
@ -42,13 +42,13 @@
|
||||||
#include "two_opt.h"
|
#include "two_opt.h"
|
||||||
|
|
||||||
/** It sets the first couple of edges */
|
/** It sets the first couple of edges */
|
||||||
class PartTwoOptInit : public moMoveInit <TwoOpt>
|
class PartTwoOptInit : public moMoveInit <TwoOpt>
|
||||||
{
|
{
|
||||||
|
|
||||||
public :
|
public :
|
||||||
|
|
||||||
void operator () (TwoOpt & __move, const Route & __route) ;
|
void operator () (TwoOpt & __move, const Route & __route) ;
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <part_two_opt_next.cpp>
|
* <part_two_opt_next.cpp>
|
||||||
* 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,21 +37,21 @@
|
||||||
#include "part_two_opt_next.h"
|
#include "part_two_opt_next.h"
|
||||||
#include "graph.h"
|
#include "graph.h"
|
||||||
|
|
||||||
bool TwoOptNext :: operator () (TwoOpt & __move, const Route & __route)
|
bool TwoOptNext :: operator () (TwoOpt & __move, const Route & __route)
|
||||||
{
|
{
|
||||||
if (__move.first == Graph :: size () - 4 && __move.second == __move.first + 2)
|
if (__move.first == Graph :: size () - 4 && __move.second == __move.first + 2)
|
||||||
{
|
{
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
__move.second ++ ;
|
__move.second ++ ;
|
||||||
if (__move.second == Graph :: size () - 1)
|
if (__move.second == Graph :: size () - 1)
|
||||||
{
|
{
|
||||||
__move.first ++ ;
|
__move.first ++ ;
|
||||||
__move.second = __move.first + 2 ;
|
__move.second = __move.first + 2 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <part_two_opt_next.h>
|
* <part_two_opt_next.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
|
||||||
|
|
@ -41,13 +41,13 @@
|
||||||
#include "two_opt.h"
|
#include "two_opt.h"
|
||||||
|
|
||||||
/** It updates a couple of edges */
|
/** It updates a couple of edges */
|
||||||
class PartTwoOptNext : public moNextMove <TwoOpt>
|
class PartTwoOptNext : public moNextMove <TwoOpt>
|
||||||
{
|
{
|
||||||
|
|
||||||
public :
|
public :
|
||||||
|
|
||||||
bool operator () (TwoOpt & __move, const Route & __route) ;
|
bool operator () (TwoOpt & __move, const Route & __route) ;
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <partial_mapped_xover.cpp>
|
* <partial_mapped_xover.cpp>
|
||||||
* 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,69 +44,69 @@
|
||||||
#include "route_valid.h"
|
#include "route_valid.h"
|
||||||
#include "mix.h"
|
#include "mix.h"
|
||||||
|
|
||||||
void PartialMappedXover :: repair (Route & __route, unsigned __cut1, unsigned __cut2)
|
void PartialMappedXover :: repair (Route & __route, unsigned __cut1, unsigned __cut2)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::vector<unsigned int> v; // Number of times a cities are visited ...
|
std::vector<unsigned int> v; // Number of times a cities are visited ...
|
||||||
|
|
||||||
v.resize(__route.size ());
|
v.resize(__route.size ());
|
||||||
|
|
||||||
for (unsigned int i = 0 ; i < __route.size () ; i ++)
|
for (unsigned int i = 0 ; i < __route.size () ; i ++)
|
||||||
{
|
{
|
||||||
v [i] = 0 ;
|
v [i] = 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0 ; i < __route.size () ; i ++)
|
for (unsigned int i = 0 ; i < __route.size () ; i ++)
|
||||||
{
|
{
|
||||||
v [__route [i]] ++ ;
|
v [__route [i]] ++ ;
|
||||||
}
|
}
|
||||||
|
|
||||||
std :: vector <unsigned int> vert ;
|
std :: vector <unsigned int> vert ;
|
||||||
|
|
||||||
for (unsigned int i = 0 ; i < __route.size () ; i ++)
|
for (unsigned int i = 0 ; i < __route.size () ; i ++)
|
||||||
{
|
{
|
||||||
if (! v [i])
|
if (! v [i])
|
||||||
{
|
{
|
||||||
vert.push_back (i) ;
|
vert.push_back (i) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mix (vert) ;
|
mix (vert) ;
|
||||||
|
|
||||||
for (unsigned int i = 0 ; i < __route.size () ; i ++)
|
for (unsigned int i = 0 ; i < __route.size () ; i ++)
|
||||||
{
|
{
|
||||||
if (i < __cut1 || i >= __cut2)
|
if (i < __cut1 || i >= __cut2)
|
||||||
{
|
{
|
||||||
if (v [__route [i]] > 1)
|
if (v [__route [i]] > 1)
|
||||||
{
|
{
|
||||||
__route [i] = vert.back () ;
|
__route [i] = vert.back () ;
|
||||||
vert.pop_back () ;
|
vert.pop_back () ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
v.clear();
|
v.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PartialMappedXover :: operator () (Route & __route1, Route & __route2)
|
bool PartialMappedXover :: operator () (Route & __route1, Route & __route2)
|
||||||
{
|
{
|
||||||
unsigned int cut1 = rng.random (__route1.size ()), cut2 = rng.random (__route2.size ()) ;
|
unsigned int cut1 = rng.random (__route1.size ()), cut2 = rng.random (__route2.size ()) ;
|
||||||
|
|
||||||
if (cut2 < cut1)
|
if (cut2 < cut1)
|
||||||
{
|
{
|
||||||
std :: swap (cut1, cut2) ;
|
std :: swap (cut1, cut2) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Between the cuts
|
// Between the cuts
|
||||||
for (unsigned int i = cut1 ; i < cut2 ; i ++)
|
for (unsigned int i = cut1 ; i < cut2 ; i ++)
|
||||||
{
|
{
|
||||||
std :: swap (__route1 [i], __route2 [i]) ;
|
std :: swap (__route1 [i], __route2 [i]) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Outside the cuts
|
// Outside the cuts
|
||||||
repair (__route1, cut1, cut2) ;
|
repair (__route1, cut1, cut2) ;
|
||||||
repair (__route2, cut1, cut2) ;
|
repair (__route2, cut1, cut2) ;
|
||||||
|
|
||||||
// Debug
|
// Debug
|
||||||
assert (valid (__route1)) ;
|
assert (valid (__route1)) ;
|
||||||
assert (valid (__route2)) ;
|
assert (valid (__route2)) ;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <partial_mapped_xover.h>
|
* <partial_mapped_xover.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
|
||||||
|
|
@ -42,15 +42,16 @@
|
||||||
#include "route.h"
|
#include "route.h"
|
||||||
|
|
||||||
/** Partial Mapped Crossover */
|
/** Partial Mapped Crossover */
|
||||||
class PartialMappedXover : public eoQuadOp <Route> {
|
class PartialMappedXover : public eoQuadOp <Route>
|
||||||
|
{
|
||||||
public :
|
|
||||||
|
|
||||||
bool operator () (Route & __route1, Route & __route2) ;
|
|
||||||
|
|
||||||
private :
|
public :
|
||||||
|
|
||||||
void repair (Route & __route, unsigned __cut1, unsigned __cut2) ;
|
bool operator () (Route & __route1, Route & __route2) ;
|
||||||
} ;
|
|
||||||
|
private :
|
||||||
|
|
||||||
|
void repair (Route & __route, unsigned __cut1, unsigned __cut2) ;
|
||||||
|
} ;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <route.h>
|
* <route.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
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <route_eval.cpp>
|
* <route_eval.cpp>
|
||||||
* 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,15 +37,15 @@
|
||||||
#include "route_eval.h"
|
#include "route_eval.h"
|
||||||
#include "graph.h"
|
#include "graph.h"
|
||||||
|
|
||||||
void RouteEval :: operator () (Route & __route)
|
void RouteEval :: operator () (Route & __route)
|
||||||
{
|
{
|
||||||
|
|
||||||
float len = 0 ;
|
float len = 0 ;
|
||||||
|
|
||||||
for (unsigned int i = 0 ; i < Graph :: size () ; i ++)
|
for (unsigned int i = 0 ; i < Graph :: size () ; i ++)
|
||||||
{
|
{
|
||||||
len -= Graph :: distance (__route [i], __route [(i + 1) % Graph :: size ()]) ;
|
len -= Graph :: distance (__route [i], __route [(i + 1) % Graph :: size ()]) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
__route.fitness (len) ;
|
__route.fitness (len) ;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <route_eval.h>
|
* <route_eval.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
|
||||||
|
|
@ -42,14 +42,14 @@
|
||||||
#include "route.h"
|
#include "route.h"
|
||||||
|
|
||||||
/** Route Evaluator */
|
/** Route Evaluator */
|
||||||
class RouteEval : public eoEvalFunc <Route>
|
class RouteEval : public eoEvalFunc <Route>
|
||||||
{
|
{
|
||||||
|
|
||||||
public :
|
public :
|
||||||
|
|
||||||
void operator () (Route & __route) ;
|
void operator () (Route & __route) ;
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <route_init.cpp>
|
* <route_init.cpp>
|
||||||
* 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
|
||||||
|
|
@ -39,25 +39,25 @@
|
||||||
#include "route_init.h"
|
#include "route_init.h"
|
||||||
#include "graph.h"
|
#include "graph.h"
|
||||||
|
|
||||||
void RouteInit :: operator () (Route & __route)
|
void RouteInit :: operator () (Route & __route)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Init.
|
// Init.
|
||||||
__route.clear () ;
|
__route.clear () ;
|
||||||
for (unsigned int i = 0 ; i < Graph :: size () ; i ++)
|
for (unsigned int i = 0 ; i < Graph :: size () ; i ++)
|
||||||
{
|
{
|
||||||
__route.push_back (i) ;
|
__route.push_back (i) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Swap. cities
|
// Swap. cities
|
||||||
|
|
||||||
for (unsigned int i = 0 ; i < Graph :: size () ; i ++)
|
for (unsigned int i = 0 ; i < Graph :: size () ; i ++)
|
||||||
{
|
{
|
||||||
//unsigned int j = rng.random (Graph :: size ()) ;
|
//unsigned int j = rng.random (Graph :: size ()) ;
|
||||||
|
|
||||||
unsigned int j = (unsigned int) (Graph :: size () * (rand () / (RAND_MAX + 1.0))) ;
|
unsigned int j = (unsigned int) (Graph :: size () * (rand () / (RAND_MAX + 1.0))) ;
|
||||||
unsigned int city = __route [i] ;
|
unsigned int city = __route [i] ;
|
||||||
__route [i] = __route [j] ;
|
__route [i] = __route [j] ;
|
||||||
__route [j] = city ;
|
__route [j] = city ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <route_init.h>
|
* <route_init.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
|
||||||
|
|
@ -41,13 +41,13 @@
|
||||||
|
|
||||||
#include "route.h"
|
#include "route.h"
|
||||||
|
|
||||||
class RouteInit : public eoInit <Route>
|
class RouteInit : public eoInit <Route>
|
||||||
{
|
{
|
||||||
|
|
||||||
public :
|
public :
|
||||||
|
|
||||||
void operator () (Route & __route) ;
|
void operator () (Route & __route) ;
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <route_valid.cpp>
|
* <route_valid.cpp>
|
||||||
* 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,31 +38,31 @@
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
bool valid (Route & __route)
|
bool valid (Route & __route)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::vector<unsigned int> t;
|
std::vector<unsigned int> t;
|
||||||
t.resize(__route.size());
|
t.resize(__route.size());
|
||||||
|
|
||||||
for (unsigned int i = 0 ; i < __route.size () ; i ++)
|
for (unsigned int i = 0 ; i < __route.size () ; i ++)
|
||||||
{
|
{
|
||||||
t [i] = 0 ;
|
t [i] = 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0 ; i < __route.size () ; i ++)
|
for (unsigned int i = 0 ; i < __route.size () ; i ++)
|
||||||
{
|
{
|
||||||
t [__route [i]] ++ ;
|
t [__route [i]] ++ ;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0 ; i < __route.size () ; i ++)
|
for (unsigned int i = 0 ; i < __route.size () ; i ++)
|
||||||
{
|
{
|
||||||
if (t [i] != 1)
|
if (t [i] != 1)
|
||||||
{
|
{
|
||||||
t.clear();
|
t.clear();
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
t.clear();
|
t.clear();
|
||||||
return true ; // OK.
|
return true ; // OK.
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <route_valid.h>
|
* <route_valid.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
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <tsp.h>
|
* <tsp.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
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <two_opt.cpp>
|
* <two_opt.cpp>
|
||||||
* 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
|
||||||
|
|
@ -36,24 +36,24 @@
|
||||||
|
|
||||||
#include "two_opt.h"
|
#include "two_opt.h"
|
||||||
|
|
||||||
TwoOpt TwoOpt :: operator ! () const
|
TwoOpt TwoOpt :: operator ! () const
|
||||||
{
|
{
|
||||||
TwoOpt move = * this ;
|
TwoOpt move = * this ;
|
||||||
std :: swap (move.first, move.second) ;
|
std :: swap (move.first, move.second) ;
|
||||||
|
|
||||||
return move ;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TwoOpt :: operator () (Route & __route)
|
return move ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TwoOpt :: operator () (Route & __route)
|
||||||
{
|
{
|
||||||
|
|
||||||
std :: vector <unsigned int> seq_cities ;
|
std :: vector <unsigned int> seq_cities ;
|
||||||
|
|
||||||
for (unsigned int i = second ; i > first ; i --)
|
for (unsigned int i = second ; i > first ; i --)
|
||||||
{
|
{
|
||||||
seq_cities.push_back (__route [i]) ;
|
seq_cities.push_back (__route [i]) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int j = 0 ;
|
unsigned int j = 0 ;
|
||||||
for (unsigned int i = first + 1 ; i < second + 1 ; i ++)
|
for (unsigned int i = first + 1 ; i < second + 1 ; i ++)
|
||||||
{
|
{
|
||||||
|
|
@ -61,12 +61,12 @@ void TwoOpt :: operator () (Route & __route)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TwoOpt :: readFrom (std :: istream & __is)
|
void TwoOpt :: readFrom (std :: istream & __is)
|
||||||
{
|
{
|
||||||
__is >> first >> second ;
|
__is >> first >> second ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TwoOpt :: printOn (std :: ostream & __os) const
|
void TwoOpt :: printOn (std :: ostream & __os) const
|
||||||
{
|
{
|
||||||
__os << first << ' ' << second ;
|
__os << first << ' ' << second ;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <two_opt.h>
|
* <two_opt.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,18 +44,18 @@
|
||||||
|
|
||||||
#include "route.h"
|
#include "route.h"
|
||||||
|
|
||||||
class TwoOpt : public moMove <Route>, public std :: pair <unsigned, unsigned>, public eoPersistent
|
class TwoOpt : public moMove <Route>, public std :: pair <unsigned, unsigned>, public eoPersistent
|
||||||
{
|
{
|
||||||
|
|
||||||
public :
|
public :
|
||||||
|
|
||||||
TwoOpt operator ! () const ;
|
TwoOpt operator ! () const ;
|
||||||
|
|
||||||
void operator () (Route & __route) ;
|
void operator () (Route & __route) ;
|
||||||
|
|
||||||
void readFrom (std :: istream & __is) ;
|
void readFrom (std :: istream & __is) ;
|
||||||
|
|
||||||
void printOn (std :: ostream & __os) const ;
|
void printOn (std :: ostream & __os) const ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <two_opt_incr_eval.cpp>
|
* <two_opt_incr_eval.cpp>
|
||||||
* 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,17 +37,17 @@
|
||||||
#include "two_opt_incr_eval.h"
|
#include "two_opt_incr_eval.h"
|
||||||
#include "graph.h"
|
#include "graph.h"
|
||||||
|
|
||||||
float TwoOptIncrEval :: operator () (const TwoOpt & __move, const Route & __route)
|
float TwoOptIncrEval :: operator () (const TwoOpt & __move, const Route & __route)
|
||||||
{
|
{
|
||||||
// From
|
// From
|
||||||
unsigned int v1 = __route [__move.first], v1_next = __route [__move.first + 1] ;
|
unsigned int v1 = __route [__move.first], v1_next = __route [__move.first + 1] ;
|
||||||
|
|
||||||
// To
|
// To
|
||||||
unsigned int v2 = __route [__move.second], v2_next = __route [__move.second + 1] ;
|
unsigned int v2 = __route [__move.second], v2_next = __route [__move.second + 1] ;
|
||||||
|
|
||||||
return __route.fitness ()
|
return __route.fitness ()
|
||||||
- Graph :: distance (v1, v2)
|
- Graph :: distance (v1, v2)
|
||||||
- Graph :: distance (v1_next, v2_next)
|
- Graph :: distance (v1_next, v2_next)
|
||||||
+ Graph :: distance (v1, v1_next)
|
+ Graph :: distance (v1, v1_next)
|
||||||
+ Graph :: distance (v2, v2_next) ;
|
+ Graph :: distance (v2, v2_next) ;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <two_opt_incr_eval.h>
|
* <two_opt_incr_eval.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
|
||||||
|
|
@ -40,13 +40,13 @@
|
||||||
#include <moMoveIncrEval.h>
|
#include <moMoveIncrEval.h>
|
||||||
#include "two_opt.h"
|
#include "two_opt.h"
|
||||||
|
|
||||||
class TwoOptIncrEval : public moMoveIncrEval <TwoOpt>
|
class TwoOptIncrEval : public moMoveIncrEval <TwoOpt>
|
||||||
{
|
{
|
||||||
|
|
||||||
public :
|
|
||||||
|
|
||||||
float operator () (const TwoOpt & __move, const Route & __route) ;
|
|
||||||
|
|
||||||
} ;
|
public :
|
||||||
|
|
||||||
|
float operator () (const TwoOpt & __move, const Route & __route) ;
|
||||||
|
|
||||||
|
} ;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <two_opt_init.cpp>
|
* <two_opt_init.cpp>
|
||||||
* 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
|
||||||
|
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
#include "two_opt_init.h"
|
#include "two_opt_init.h"
|
||||||
|
|
||||||
void TwoOptInit :: operator () (TwoOpt & __move, const Route & __route)
|
void TwoOptInit :: operator () (TwoOpt & __move, const Route & __route)
|
||||||
{
|
{
|
||||||
__move.first = 0 ;
|
__move.first = 0 ;
|
||||||
__move.second = 2 ;
|
__move.second = 2 ;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <two_opt_init.h>
|
* <two_opt_init.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
|
||||||
|
|
@ -42,13 +42,13 @@
|
||||||
#include "two_opt.h"
|
#include "two_opt.h"
|
||||||
|
|
||||||
/** It sets the first couple of edges */
|
/** It sets the first couple of edges */
|
||||||
class TwoOptInit : public moMoveInit <TwoOpt>
|
class TwoOptInit : public moMoveInit <TwoOpt>
|
||||||
{
|
{
|
||||||
|
|
||||||
public :
|
public :
|
||||||
|
|
||||||
void operator () (TwoOpt & __move, const Route & __route) ;
|
void operator () (TwoOpt & __move, const Route & __route) ;
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <two_opt_next.cpp>
|
* <two_opt_next.cpp>
|
||||||
* 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,21 +37,21 @@
|
||||||
#include "two_opt_next.h"
|
#include "two_opt_next.h"
|
||||||
#include "graph.h"
|
#include "graph.h"
|
||||||
|
|
||||||
bool TwoOptNext :: operator () (TwoOpt & __move, const Route & __route)
|
bool TwoOptNext :: operator () (TwoOpt & __move, const Route & __route)
|
||||||
{
|
{
|
||||||
if (__move.first == Graph :: size () - 4 && __move.second == __move.first + 2)
|
if (__move.first == Graph :: size () - 4 && __move.second == __move.first + 2)
|
||||||
{
|
{
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
__move.second ++ ;
|
__move.second ++ ;
|
||||||
if (__move.second == Graph :: size () - 1)
|
if (__move.second == Graph :: size () - 1)
|
||||||
{
|
{
|
||||||
__move.first ++ ;
|
__move.first ++ ;
|
||||||
__move.second = __move.first + 2 ;
|
__move.second = __move.first + 2 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <two_opt_next.h>
|
* <two_opt_next.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
|
||||||
|
|
@ -41,13 +41,13 @@
|
||||||
#include "two_opt.h"
|
#include "two_opt.h"
|
||||||
|
|
||||||
/** It updates a couple of edges */
|
/** It updates a couple of edges */
|
||||||
class TwoOptNext : public moNextMove <TwoOpt>
|
class TwoOptNext : public moNextMove <TwoOpt>
|
||||||
{
|
{
|
||||||
|
|
||||||
public :
|
public :
|
||||||
|
|
||||||
bool operator () (TwoOpt & __move, const Route & __route) ;
|
bool operator () (TwoOpt & __move, const Route & __route) ;
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <two_opt_rand.cpp>
|
* <two_opt_rand.cpp>
|
||||||
* 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,7 +38,7 @@
|
||||||
#include "graph.h"
|
#include "graph.h"
|
||||||
#include <utils/eoRNG.h>
|
#include <utils/eoRNG.h>
|
||||||
|
|
||||||
void TwoOptRand :: operator () (TwoOpt & __move)
|
void TwoOptRand :: operator () (TwoOpt & __move)
|
||||||
{
|
{
|
||||||
__move.first = rng.random (Graph :: size () - 3) ;
|
__move.first = rng.random (Graph :: size () - 3) ;
|
||||||
__move.second = __move.first + 2 + rng.random (Graph :: size () - __move.first - 3) ;
|
__move.second = __move.first + 2 + rng.random (Graph :: size () - __move.first - 3) ;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <two_opt_rand.h>
|
* <two_opt_rand.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
|
||||||
|
|
@ -41,13 +41,13 @@
|
||||||
|
|
||||||
#include "two_opt.h"
|
#include "two_opt.h"
|
||||||
|
|
||||||
class TwoOptRand : public moRandMove <TwoOpt>
|
class TwoOptRand : public moRandMove <TwoOpt>
|
||||||
{
|
{
|
||||||
|
|
||||||
public :
|
public :
|
||||||
|
|
||||||
void operator () (TwoOpt & __move) ;
|
void operator () (TwoOpt & __move) ;
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <two_opt_tabu_list.cpp>
|
* <two_opt_tabu_list.cpp>
|
||||||
* 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
|
||||||
|
|
@ -39,45 +39,45 @@
|
||||||
|
|
||||||
#define TABU_LENGTH 10
|
#define TABU_LENGTH 10
|
||||||
|
|
||||||
void TwoOptTabuList :: init ()
|
void TwoOptTabuList :: init ()
|
||||||
{
|
{
|
||||||
// Size (eventually)
|
// Size (eventually)
|
||||||
tabu_span.resize (Graph :: size ()) ;
|
tabu_span.resize (Graph :: size ()) ;
|
||||||
for (unsigned int i = 0 ; i < tabu_span.size () ; i ++)
|
for (unsigned int i = 0 ; i < tabu_span.size () ; i ++)
|
||||||
{
|
{
|
||||||
tabu_span [i].resize (Graph :: size ()) ;
|
tabu_span [i].resize (Graph :: size ()) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear
|
// Clear
|
||||||
for (unsigned int i = 0 ; i < tabu_span.size () ; i ++)
|
for (unsigned int i = 0 ; i < tabu_span.size () ; i ++)
|
||||||
{
|
{
|
||||||
for (unsigned int j = 0 ; j < tabu_span [i].size () ; j ++)
|
for (unsigned int j = 0 ; j < tabu_span [i].size () ; j ++)
|
||||||
{
|
{
|
||||||
tabu_span [i] [j] = 0 ;
|
tabu_span [i] [j] = 0 ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TwoOptTabuList :: operator () (const TwoOpt & __move, const Route & __sol)
|
bool TwoOptTabuList :: operator () (const TwoOpt & __move, const Route & __sol)
|
||||||
{
|
{
|
||||||
return tabu_span [__move.first] [__move.second] > 0 ;
|
return tabu_span [__move.first] [__move.second] > 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TwoOptTabuList :: add (const TwoOpt & __move, const Route & __sol)
|
void TwoOptTabuList :: add (const TwoOpt & __move, const Route & __sol)
|
||||||
{
|
{
|
||||||
tabu_span [__move.first] [__move.second] = tabu_span [__move.second] [__move.first] = TABU_LENGTH ;
|
tabu_span [__move.first] [__move.second] = tabu_span [__move.second] [__move.first] = TABU_LENGTH ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TwoOptTabuList :: update ()
|
void TwoOptTabuList :: update ()
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0 ; i < tabu_span.size () ; i ++)
|
for (unsigned int i = 0 ; i < tabu_span.size () ; i ++)
|
||||||
{
|
{
|
||||||
for (unsigned int j = 0 ; j < tabu_span [i].size () ; j ++)
|
for (unsigned int j = 0 ; j < tabu_span [i].size () ; j ++)
|
||||||
{
|
{
|
||||||
if (tabu_span [i] [j] > 0)
|
if (tabu_span [i] [j] > 0)
|
||||||
{
|
{
|
||||||
tabu_span [i] [j] -- ;
|
tabu_span [i] [j] -- ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <two_opt_tabu_list.h>
|
* <two_opt_tabu_list.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
|
||||||
|
|
@ -42,22 +42,22 @@
|
||||||
#include "route.h"
|
#include "route.h"
|
||||||
|
|
||||||
/** The table of tabu movements, i.e. forbidden edges */
|
/** The table of tabu movements, i.e. forbidden edges */
|
||||||
class TwoOptTabuList : public moTabuList <TwoOpt>
|
class TwoOptTabuList : public moTabuList <TwoOpt>
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
||||||
bool operator () (const TwoOpt & __move, const Route & __sol) ;
|
bool operator () (const TwoOpt & __move, const Route & __sol) ;
|
||||||
|
|
||||||
void add (const TwoOpt & __move, const Route & __sol) ;
|
void add (const TwoOpt & __move, const Route & __sol) ;
|
||||||
|
|
||||||
void update () ;
|
void update () ;
|
||||||
|
|
||||||
void init () ;
|
void init () ;
|
||||||
|
|
||||||
private :
|
private :
|
||||||
|
|
||||||
std :: vector <std :: vector <unsigned> > tabu_span ;
|
std :: vector <std :: vector <unsigned> > tabu_span ;
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue