Added a field for saving the fitness of the solution (useful for monitoring)
This commit is contained in:
parent
b5f15a4a3d
commit
6548a0e223
1 changed files with 108 additions and 91 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue