In OptaPlanner, I noticed that there is variable changes listener for every move. And SolverEventListener
for bestSolutionChanged
which is calculated after every phases. However, I could not find to catch the changes in each step end.
Any suggestions to listen the Step changes in Construction Heuristic phase?
To listen to to events on a level of steps and phases, you 'll need to use an internal listener called PhaseLifecycleListener
. For example the internal benchmarker code uses it:
StepScoreSingleStatisticListener listener = new StepScoreSingleStatisticListener();
((DefaultSolver) solver).addPhaseLifecycleListener(listener);
// solver.solve(...);
((DefaultSolver) solver).removePhaseLifecycleListener(listener);
The implementation could look something like this:
private class StepScoreSingleStatisticListener extends PhaseLifecycleListenerAdapter {
@Override
public void stepEnded(AbstractStepScope stepScope) {
...
}
}
Warning: This is internal API, not backwards compatible in future releases, not documented, not for the faint hearted, use at own risk, you're not in Kansas anymore Dorothy, ... :)