refactor(mo): use clog instead of cout & use at accessors in Debug builds
Should really use eo::log, but waiting for logger refactoring.
This commit is contained in:
parent
399b222661
commit
ab375d55ac
13 changed files with 38 additions and 19 deletions
|
|
@ -84,7 +84,7 @@ public:
|
||||||
bool res = (cpt < maxNoImprove);
|
bool res = (cpt < maxNoImprove);
|
||||||
|
|
||||||
if (!res && verbose)
|
if (!res && verbose)
|
||||||
std::cout << "STOP in moBestNoImproveContinuator: Reached maximum number of iterations without improvement [" << cpt << "/" << maxNoImprove << "]" << std::endl;
|
std::clog << "STOP in moBestNoImproveContinuator: Reached maximum number of iterations without improvement [" << cpt << "/" << maxNoImprove << "]" << std::endl;
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ public:
|
||||||
cpt++;
|
cpt++;
|
||||||
res = (cpt < maxIter);
|
res = (cpt < maxIter);
|
||||||
if (!res && verbose)
|
if (!res && verbose)
|
||||||
std::cout << "STOP in moIterContinuator: Reached maximum number of iterations [" << cpt << "/" << maxIter << "]" << std::endl;
|
std::clog << "STOP in moIterContinuator: Reached maximum number of iterations [" << cpt << "/" << maxIter << "]" << std::endl;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ public :
|
||||||
neighborhood(_neighborhood), eval(_eval)
|
neighborhood(_neighborhood), eval(_eval)
|
||||||
{
|
{
|
||||||
if (!neighborhood.isRandom()) {
|
if (!neighborhood.isRandom()) {
|
||||||
std::cout << "moNeighborFitnessStat::Warning -> the neighborhood used is not random, the neighbor will not be random" << std::endl;
|
std::clog << "moNeighborFitnessStat::Warning -> the neighborhood used is not random, the neighbor will not be random" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ public:
|
||||||
time_t elapsed = (time_t) difftime(time(NULL), start);
|
time_t elapsed = (time_t) difftime(time(NULL), start);
|
||||||
res = (elapsed < max);
|
res = (elapsed < max);
|
||||||
if (!res && verbose)
|
if (!res && verbose)
|
||||||
std::cout << "STOP in moTimeContinuator: Reached maximum time [" << elapsed << "/" << max << "]" << std::endl;
|
std::clog << "STOP in moTimeContinuator: Reached maximum time [" << elapsed << "/" << max << "]" << std::endl;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,9 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Full evaluation to use with a moBackableNeighbor
|
* Full evaluation to use with a moBackableNeighbor
|
||||||
* !!!WARNING!!! Use only when your solution is composed by a fitness Value and a "genotype"
|
*
|
||||||
|
* @warning Use only when your solution is composed by a fitness Value and a "genotype",
|
||||||
|
* and no any other data structure.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
template<class BackableNeighbor>
|
template<class BackableNeighbor>
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ public:
|
||||||
//apply the local search on the copy
|
//apply the local search on the copy
|
||||||
ls(currentSol);
|
ls(currentSol);
|
||||||
|
|
||||||
// std::cout << "(solution)\t" << current << std::endl;
|
// std::clog << "(solution)\t" << current << std::endl;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ public:
|
||||||
moMetropolisHastingExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator, unsigned int _nbStep) : moNeighborhoodExplorer<Neighbor>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator), nbStep(_nbStep) {
|
moMetropolisHastingExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator, unsigned int _nbStep) : moNeighborhoodExplorer<Neighbor>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator), nbStep(_nbStep) {
|
||||||
isAccept = false;
|
isAccept = false;
|
||||||
if (!neighborhood.isRandom()) {
|
if (!neighborhood.isRandom()) {
|
||||||
std::cout << "moMetropolisHastingExplorer::Warning -> the neighborhood used is not random" << std::endl;
|
std::clog << "moMetropolisHastingExplorer::Warning -> the neighborhood used is not random" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,16 +44,16 @@
|
||||||
#include <eval/moDummyEval.h>
|
#include <eval/moDummyEval.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Explore the neighborhood according to the local search algorithm
|
* Explore the neighborhood according to the local search algorithm
|
||||||
*
|
*
|
||||||
* During this exploration,
|
* During this exploration,
|
||||||
* the parameters are updated
|
* the parameters are updated
|
||||||
* one neighbor is selected
|
* one neighbor is selected
|
||||||
* a comparason with the solution is made to acccept or not this new neighbor
|
* a comparason with the solution is made to acccept or not this new neighbor
|
||||||
*
|
*
|
||||||
* The current neighbor (currentNeigbor) is the neighbor under consideration during the search (in operator()(EOT &))
|
* The current neighbor (currentNeigbor) is the neighbor under consideration during the search (in operator()(EOT &))
|
||||||
*
|
*
|
||||||
* The selected neighbor (selectedNeighbor) is the neighbor selected in method operator()(EOT &).
|
* The selected neighbor (selectedNeighbor) is the neighbor selected in method operator()(EOT &).
|
||||||
* If this neighbor is accepted, then the solution is moved on this neighbor (in move(EOT &))
|
* If this neighbor is accepted, then the solution is moved on this neighbor (in move(EOT &))
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,7 @@ public:
|
||||||
eval(_solution, currentNeighbor);
|
eval(_solution, currentNeighbor);
|
||||||
|
|
||||||
//initialize the best neighbor
|
//initialize the best neighbor
|
||||||
|
assert(not currentNeighbor.invalid());
|
||||||
bestVector.push_back(currentNeighbor);
|
bestVector.push_back(currentNeighbor);
|
||||||
|
|
||||||
//test all others neighbors
|
//test all others neighbors
|
||||||
|
|
@ -129,21 +130,37 @@ public:
|
||||||
|
|
||||||
//eval
|
//eval
|
||||||
eval(_solution, currentNeighbor);
|
eval(_solution, currentNeighbor);
|
||||||
|
assert(not currentNeighbor.invalid());
|
||||||
|
|
||||||
//if we found a better neighbor, update the best
|
//if we found a better neighbor, update the best
|
||||||
|
#ifndef NDEBUG
|
||||||
|
assert(bestVector.size() > 0);
|
||||||
|
assert(not bestVector.at(0).invalid());
|
||||||
|
if (neighborComparator(bestVector.at(0), currentNeighbor)) {
|
||||||
|
#else
|
||||||
if (neighborComparator(bestVector[0], currentNeighbor)) {
|
if (neighborComparator(bestVector[0], currentNeighbor)) {
|
||||||
|
#endif
|
||||||
bestVector.clear();
|
bestVector.clear();
|
||||||
|
assert(not currentNeighbor.invalid());
|
||||||
bestVector.push_back(currentNeighbor);
|
bestVector.push_back(currentNeighbor);
|
||||||
}
|
}
|
||||||
else if (neighborComparator.equals(currentNeighbor, bestVector[0])) //if the current is equals to previous best solutions then update vector of the best solution
|
//if the current is equals to previous best solutions
|
||||||
|
// then update vector of the best solution
|
||||||
|
#ifndef NDEBUG
|
||||||
|
else if (neighborComparator.equals(currentNeighbor, bestVector.at(0))) {
|
||||||
|
#else
|
||||||
|
else if (neighborComparator.equals(currentNeighbor, bestVector[0])) {
|
||||||
|
#endif
|
||||||
|
assert(not currentNeighbor.invalid());
|
||||||
bestVector.push_back(currentNeighbor);
|
bestVector.push_back(currentNeighbor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// choose randomly one of the best solutions
|
// choose randomly one of the best solutions
|
||||||
unsigned int i = rng.random(bestVector.size());
|
unsigned int i = rng.random(bestVector.size());
|
||||||
|
|
||||||
// the selected Neighbor
|
// the selected Neighbor
|
||||||
selectedNeighbor = bestVector[i];
|
selectedNeighbor = bestVector[i];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//if _solution hasn't neighbor,
|
//if _solution hasn't neighbor,
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ public:
|
||||||
nbStep(_nbStep) {
|
nbStep(_nbStep) {
|
||||||
isAccept = false;
|
isAccept = false;
|
||||||
if (!neighborhood.isRandom()) {
|
if (!neighborhood.isRandom()) {
|
||||||
std::cout << "moRandomNeutralWalkExplorer::Warning -> the neighborhood used is not random (" << neighborhood.className() << ")" << std::endl;
|
std::clog << "moRandomNeutralWalkExplorer::Warning -> the neighborhood used is not random (" << neighborhood.className() << ")" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ public:
|
||||||
moRandomWalkExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval) : moNeighborhoodExplorer<Neighbor>(_neighborhood, _eval) {
|
moRandomWalkExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval) : moNeighborhoodExplorer<Neighbor>(_neighborhood, _eval) {
|
||||||
isAccept = false;
|
isAccept = false;
|
||||||
if (!neighborhood.isRandom()) {
|
if (!neighborhood.isRandom()) {
|
||||||
std::cout << "moRandomNeutralWalkExplorer::Warning -> the neighborhood used is not random (" << neighborhood.className() << ")" << std::endl;
|
std::clog << "moRandomNeutralWalkExplorer::Warning -> the neighborhood used is not random (" << neighborhood.className() << ")" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ public:
|
||||||
isAccept = false;
|
isAccept = false;
|
||||||
|
|
||||||
if (!neighborhood.isRandom()) {
|
if (!neighborhood.isRandom()) {
|
||||||
std::cout << "moSAexplorer::Warning -> the neighborhood used is not random" << std::endl;
|
std::clog << "moSAexplorer::Warning -> the neighborhood used is not random" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ public:
|
||||||
checkpoint = new moCheckpoint<Neighbor>(*continuator);
|
checkpoint = new moCheckpoint<Neighbor>(*continuator);
|
||||||
add(_stat, _monitoring);
|
add(_stat, _monitoring);
|
||||||
// precision of the output by default
|
// precision of the output by default
|
||||||
precisionOutput = std::cout.precision();
|
precisionOutput = std::clog.precision();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue