Finish (and change on moCoolingSchudele) the moDynSpanCoolingSchudele

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1902 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
verel 2010-07-28 15:47:02 +00:00
commit da72b737b7
4 changed files with 59 additions and 40 deletions

View file

@ -54,8 +54,9 @@ public:
/** /**
* update the temperature * update the temperature
* @param _temp current temperature to update * @param _temp current temperature to update
* @param _acceptedMove true when the move is accepted, false otherwise
*/ */
virtual void update(double& _temp) = 0; virtual void update(double& _temp, bool _acceptedMove) = 0;
}; };

View file

@ -39,6 +39,8 @@
/** /**
* Cooling Schedule of the temperature in the simulated algorithm * Cooling Schedule of the temperature in the simulated algorithm
* dynamic span : maximum number of tries and maximum number of moves
* stop on the number of span with no move
* *
*/ */
template< class EOT > template< class EOT >
@ -49,11 +51,12 @@ public:
* default constructor * default constructor
* @param _initT initial temperature * @param _initT initial temperature
* @param _alpha factor of decreasing * @param _alpha factor of decreasing
* @param _spanMove maximum number of move with equal temperature * @param _spanTriesMax maximum number of total move at equal temperature
* @param _spanNoMove maximum number of no improvement with equal temperature * @param _spanMoveMax maximum number of moves at equal temperature
* @param _nbSpan maximum number of span with no improvmement before stopping the search * @param _nbSpanMax maximum number of span with no move before stopping the search
*/ */
moDynSpanCoolingSchedule(double _initT, double _alpha, unsigned int _spanMove, unsigned int _spanNoMove, unsigned int _nbSpan) : initT(_initT), alpha(_alpha), spanMove(_spanMove), spanNoMove(_spanNoMove), nbSpan(_nbSpan) { moDynSpanCoolingSchedule(double _initT, double _alpha, unsigned int _spanTriesMax, unsigned int _spanMoveMax, unsigned int _nbSpanMax) :
initT(_initT), alpha(_alpha), spanTriesMax(_spanTriesMax), spanMoveMax(_spanMoveMax), nbSpanMax(_nbSpanMax) {
} }
/** /**
@ -61,41 +64,49 @@ public:
* @param _solution initial solution * @param _solution initial solution
*/ */
virtual double init(EOT & _solution) { virtual double init(EOT & _solution) {
// number of successive moves since the last temperature change // number of tries since the last temperature change
nbMove = 0; spanTries = 0;
// number of no improvement since the last temperature change // number of move since the last temperature change
nbNoMove = 0; spanMove = 0;
// number of span with no improvement // number of successive span with no move
nbSpan = 0; nbSpan = 0;
return initT; return initT;
} }
/** /**
* update the temperature by a factor * update the temperature by a factor
* @param _temp current temperature to update * @param _temp current temperature to update
*/ * @param _acceptedMove true when the move is accepted, false otherwise
virtual void update(double& _temp) { */
if (nbMove >= spanMove || nbNoMove >= spanNoMove) { virtual void update(double& _temp, bool _acceptedMove) {
_temp *= alpha; spanTries++;
nbMove = 0; if (_acceptedMove)
nbNoMove = 0; spanMove++;
} else {
nbMove++; if (spanTries >= spanTriesMax || spanMove >= spanMoveMax) {
nbNoMove++; _temp *= alpha;
}
if (spanMove == 0) // no move during this span ?
nbSpan++;
else
nbSpan = 0;
spanTries = 0;
spanMove = 0;
} }
}
/** /**
* compare the temperature to the threshold * compare the number of span with no move
* @param _temp current temperature * @param _temp current temperature
* @return true if the current temperature is over the threshold (final temperature) * @return true if the search can continue
*/ */
virtual bool operator()(double _temp) { virtual bool operator()(double _temp) {
return _temp > finalT; return nbSpan <= nbSpanMax;
} }
private: private:
@ -105,17 +116,23 @@ private:
// coefficient of decrease // coefficient of decrease
double alpha; double alpha;
// // number of total move at equal temperature
unsigned int spanTries;
// number of move at equal temperature
unsigned int spanMove; unsigned int spanMove;
// // number of successive spans with no move
unsigned int spanNoMove;
// maximum number of iterations at the same temperature
unsigned int nbSpan; unsigned int nbSpan;
// threshold temperature // maximum number of total move at equal temperature
double finalT; unsigned int spanTriesMax;
// maximum number of move at equal temperature
unsigned int spanMoveMax;
// maximum number of successive spans with no move
unsigned int nbSpanMax;
// number of steps with the same temperature // number of steps with the same temperature
unsigned int step; unsigned int step;

View file

@ -69,8 +69,9 @@ public:
/** /**
* update the temperature by a factor * update the temperature by a factor
* @param _temp current temperature to update * @param _temp current temperature to update
* @param _acceptedMove true when the move is accepted, false otherwise
*/ */
virtual void update(double& _temp) { virtual void update(double& _temp, bool _acceptedMove) {
if (step >= span) { if (step >= span) {
_temp *= alpha; _temp *= alpha;
step = 0; step = 0;

View file

@ -86,8 +86,8 @@ public:
* @param _solution the solution * @param _solution the solution
*/ */
virtual void initParam(EOT & _solution) { virtual void initParam(EOT & _solution) {
temperature = coolingSchedule.init(_solution); temperature = coolingSchedule.init(_solution);
isAccept = true; isAccept = true;
}; };
/** /**
@ -95,7 +95,7 @@ public:
* @param _solution unused solution * @param _solution unused solution
*/ */
virtual void updateParam(EOT & _solution) { virtual void updateParam(EOT & _solution) {
coolingSchedule.update(temperature); coolingSchedule.update(temperature, this->moveApplied());
}; };
/** /**