Added a field for saving the fitness of the solution (useful for monitoring)

This commit is contained in:
LPTK 2013-07-18 14:13:35 +02:00
commit 6548a0e223

View file

@ -57,11 +57,9 @@ public:
* @param _cont an external continuator (can be a checkpoint!)
* @param _fullEval a full evaluation function
*/
moLocalSearch(NeighborhoodExplorer& _searchExpl,
moContinuator<Neighbor> & _cont, eoEvalFunc<EOT>& _fullEval) :
searchExplorer(_searchExpl), cont(&_cont), fullEval(_fullEval) {
}
;
moLocalSearch(NeighborhoodExplorer& _searchExpl, moContinuator<Neighbor> & _cont, eoEvalFunc<EOT>& _fullEval)
: searchExplorer(_searchExpl), cont(&_cont), fullEval(_fullEval), currentSolutionFitness(0)
{ }
/**
* Run the local search on a solution
@ -79,7 +77,11 @@ public:
cont->init(_solution);
bool b;
do {
do
{
currentSolutionFitness = _solution.fitness();
// explore the neighborhood of the solution
searchExplorer(_solution);
// if a solution in the neighborhood can be accepted
@ -93,7 +95,8 @@ public:
searchExplorer.updateParam(_solution);
b = (*cont)(_solution);
} while (b && searchExplorer.isContinue(_solution));
}
while (b && searchExplorer.isContinue(_solution));
searchExplorer.terminate(_solution);
@ -101,7 +104,6 @@ public:
return true;
}
;
/**
* Set an external continuator
@ -131,7 +133,16 @@ public:
return searchExplorer;
}
/**
* Useful for monitoring with anb eoGetterUpdater
* @return the fitness of the last computed solution
*/
double getCurrentSolutionFitness() const {
return currentSolutionFitness;
}
protected:
// make the exploration of the neighborhood according to a local search heuristic
moNeighborhoodExplorer<Neighbor>& searchExplorer;
@ -140,6 +151,12 @@ protected:
//full evaluation function
eoEvalFunc<EOT>& fullEval;
private:
// fitness of the last computed solution
double currentSolutionFitness;
};
#endif