cooling schedule changes

This commit is contained in:
LPTK 2013-06-05 15:46:33 +02:00
commit b4b4b2eaba
6 changed files with 45 additions and 41 deletions

View file

@ -55,8 +55,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 * @param _acceptedMove true when the move is accepted, false otherwise
* @param _currentSolution the current solution
*/ */
virtual void update(double& _temp, bool _acceptedMove) = 0; virtual void update(double& _temp, bool _acceptedMove, EOT & _currentSolution) = 0;
}; };

View file

@ -80,25 +80,26 @@ 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 * @param _acceptedMove true when the move is accepted, false otherwise
* @param _currentSolution the current solution
*/ */
virtual void update(double& _temp, bool _acceptedMove) { virtual void update(double& _temp, bool _acceptedMove, EOT & _currentSolution) {
spanTries++; spanTries++;
if (_acceptedMove) if (_acceptedMove)
spanMove++; spanMove++;
if (spanTries >= spanTriesMax || spanMove >= spanMoveMax) { if (spanTries >= spanTriesMax || spanMove >= spanMoveMax) {
_temp *= alpha; _temp *= alpha;
if (spanMove == 0) // no move during this span ? if (spanMove == 0) // no move during this span ?
nbSpan++; nbSpan++;
else else
nbSpan = 0; nbSpan = 0;
spanTries = 0; spanTries = 0;
spanMove = 0; spanMove = 0;
} }
} }
/** /**
* compare the number of span with no move * compare the number of span with no move

View file

@ -52,7 +52,8 @@ public:
* @param _span number of iteration with equal temperature * @param _span number of iteration with equal temperature
* @param _finalT final temperature, threshold of the stopping criteria * @param _finalT final temperature, threshold of the stopping criteria
*/ */
moSimpleCoolingSchedule(double _initT, double _alpha, unsigned _span, double _finalT) : initT(_initT), alpha(_alpha), span(_span), finalT(_finalT) {} moSimpleCoolingSchedule(double _initT, double _alpha, unsigned _span, double _finalT)
: initT(_initT), alpha(_alpha), span(_span), finalT(_finalT) {}
/** /**
* Getter on the initial temperature * Getter on the initial temperature
@ -70,8 +71,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 * @param _acceptedMove true when the move is accepted, false otherwise
* @param _currentSolution the current solution
*/ */
virtual void update(double& _temp, bool _acceptedMove) { virtual void update(double& _temp, bool _acceptedMove, EOT & _currentSolution) {
if (step >= span) { if (step >= span) {
_temp *= alpha; _temp *= alpha;
step = 0; step = 0;

View file

@ -96,7 +96,7 @@ public:
* @param _solution unused solution * @param _solution unused solution
*/ */
virtual void updateParam(EOT & _solution) { virtual void updateParam(EOT & _solution) {
coolingSchedule.update(temperature, this->moveApplied()); coolingSchedule.update(temperature, this->moveApplied(), _solution);
}; };
/** /**

View file

@ -48,38 +48,38 @@ int main() {
assert(temperature == 100); assert(temperature == 100);
//temperature must not changed 2* //temperature must not changed 2*
test.update(temperature, 0); test.update(temperature, 0, sol);
assert(temperature == 100); assert(temperature == 100);
assert(test(temperature)); assert(test(temperature));
test.update(temperature, 0); test.update(temperature, 0, sol);
assert(temperature == 100); assert(temperature == 100);
assert(test(temperature)); assert(test(temperature));
//then temperature must be /10 //then temperature must be /10
test.update(temperature, 0); test.update(temperature, 0, sol);
assert(temperature == 10); assert(temperature == 10);
assert(test(temperature)); assert(test(temperature));
test.update(temperature, 0); test.update(temperature, 0, sol);
assert(temperature == 10); assert(temperature == 10);
assert(test(temperature)); assert(test(temperature));
test.update(temperature, 0); test.update(temperature, 0, sol);
assert(temperature == 10); assert(temperature == 10);
assert(test(temperature)); assert(test(temperature));
test.update(temperature, 0); test.update(temperature, 0, sol);
assert(temperature == 1); assert(temperature == 1);
std::cout << "\n"; std::cout << "\n";
assert(test(temperature)); assert(test(temperature));
test.update(temperature, 0); test.update(temperature, 0, sol);
std::cout << "\n"; std::cout << "\n";
assert(temperature == 1); assert(temperature == 1);
assert(test(temperature)); assert(test(temperature));
test.update(temperature, 0); test.update(temperature, 0, sol);
std::cout << "\n"; std::cout << "\n";
assert(temperature == 1); assert(temperature == 1);
assert(test(temperature)); assert(test(temperature));
test.update(temperature, 0); test.update(temperature, 0, sol);
assert(temperature == 0.1); assert(temperature == 0.1);
assert(!test(temperature)); assert(!test(temperature));

View file

@ -48,38 +48,38 @@ int main() {
assert(temperature==100); assert(temperature==100);
//temperature must not changed 2* //temperature must not changed 2*
test.update(temperature,0); test.update(temperature,0,sol);
assert(temperature==100); assert(temperature==100);
assert(test(temperature)); assert(test(temperature));
test.update(temperature,0); test.update(temperature,0,sol);
assert(temperature==100); assert(temperature==100);
assert(test(temperature)); assert(test(temperature));
//then temperature must be /10 //then temperature must be /10
test.update(temperature,0); test.update(temperature,0,sol);
assert(temperature==10); assert(temperature==10);
assert(test(temperature)); assert(test(temperature));
test.update(temperature,0); test.update(temperature,0,sol);
assert(temperature==10); assert(temperature==10);
assert(test(temperature)); assert(test(temperature));
test.update(temperature,0); test.update(temperature,0,sol);
assert(temperature==10); assert(temperature==10);
assert(test(temperature)); assert(test(temperature));
test.update(temperature,0); test.update(temperature,0,sol);
assert(temperature == 1); assert(temperature == 1);
std::cout<< "\n"; std::cout<< "\n";
assert(test(temperature)); assert(test(temperature));
test.update(temperature,0); test.update(temperature,0,sol);
std::cout<< "\n"; std::cout<< "\n";
assert(temperature==1); assert(temperature==1);
assert(test(temperature)); assert(test(temperature));
test.update(temperature,0); test.update(temperature,0,sol);
std::cout<< "\n"; std::cout<< "\n";
assert(temperature==1); assert(temperature==1);
assert(test(temperature)); assert(test(temperature));
test.update(temperature,0); test.update(temperature,0,sol);
assert(temperature==0.1); assert(temperature==0.1);
assert(!test(temperature)); assert(!test(temperature));