cooling schedule changes

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

View file

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

View file

@ -52,7 +52,8 @@ public:
* @param _span number of iteration with equal temperature
* @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
@ -70,8 +71,9 @@ public:
* update the temperature by a factor
* @param _temp current temperature to update
* @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) {
_temp *= alpha;
step = 0;

View file

@ -96,7 +96,7 @@ public:
* @param _solution unused 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);
//temperature must not changed 2*
test.update(temperature, 0);
test.update(temperature, 0, sol);
assert(temperature == 100);
assert(test(temperature));
test.update(temperature, 0);
test.update(temperature, 0, sol);
assert(temperature == 100);
assert(test(temperature));
//then temperature must be /10
test.update(temperature, 0);
test.update(temperature, 0, sol);
assert(temperature == 10);
assert(test(temperature));
test.update(temperature, 0);
test.update(temperature, 0, sol);
assert(temperature == 10);
assert(test(temperature));
test.update(temperature, 0);
test.update(temperature, 0, sol);
assert(temperature == 10);
assert(test(temperature));
test.update(temperature, 0);
test.update(temperature, 0, sol);
assert(temperature == 1);
std::cout << "\n";
assert(test(temperature));
test.update(temperature, 0);
test.update(temperature, 0, sol);
std::cout << "\n";
assert(temperature == 1);
assert(test(temperature));
test.update(temperature, 0);
test.update(temperature, 0, sol);
std::cout << "\n";
assert(temperature == 1);
assert(test(temperature));
test.update(temperature, 0);
test.update(temperature, 0, sol);
assert(temperature == 0.1);
assert(!test(temperature));

View file

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