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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public:
|
|||
cpt++;
|
||||
res = (cpt < maxIter);
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public :
|
|||
neighborhood(_neighborhood), eval(_eval)
|
||||
{
|
||||
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);
|
||||
res = (elapsed < max);
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,9 @@
|
|||
|
||||
/**
|
||||
* 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>
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ public:
|
|||
//apply the local search on the copy
|
||||
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) {
|
||||
isAccept = false;
|
||||
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>
|
||||
|
||||
/**
|
||||
* Explore the neighborhood according to the local search algorithm
|
||||
* Explore the neighborhood according to the local search algorithm
|
||||
*
|
||||
* During this exploration,
|
||||
* the parameters are updated
|
||||
* one neighbor is selected
|
||||
* 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 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 &))
|
||||
*
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -120,6 +120,7 @@ public:
|
|||
eval(_solution, currentNeighbor);
|
||||
|
||||
//initialize the best neighbor
|
||||
assert(not currentNeighbor.invalid());
|
||||
bestVector.push_back(currentNeighbor);
|
||||
|
||||
//test all others neighbors
|
||||
|
|
@ -129,21 +130,37 @@ public:
|
|||
|
||||
//eval
|
||||
eval(_solution, currentNeighbor);
|
||||
assert(not currentNeighbor.invalid());
|
||||
|
||||
//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)) {
|
||||
#endif
|
||||
bestVector.clear();
|
||||
assert(not currentNeighbor.invalid());
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// choose randomly one of the best solutions
|
||||
unsigned int i = rng.random(bestVector.size());
|
||||
// choose randomly one of the best solutions
|
||||
unsigned int i = rng.random(bestVector.size());
|
||||
|
||||
// the selected Neighbor
|
||||
selectedNeighbor = bestVector[i];
|
||||
// the selected Neighbor
|
||||
selectedNeighbor = bestVector[i];
|
||||
}
|
||||
else {
|
||||
//if _solution hasn't neighbor,
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ public:
|
|||
nbStep(_nbStep) {
|
||||
isAccept = false;
|
||||
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) {
|
||||
isAccept = false;
|
||||
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;
|
||||
|
||||
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);
|
||||
add(_stat, _monitoring);
|
||||
// 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