use of org.cpsolver.ifs.model.InfoProvider in project cpsolver by UniTime.
the class RoundRobinNeighbourSelection method changeSelection.
/**
* Change selection
* @param selectionIndex current selection index
*/
@SuppressWarnings("unchecked")
public void changeSelection(int selectionIndex) {
iSolver.currentSolution().getLock().writeLock().lock();
try {
Progress progress = Progress.getInstance(iSolver.currentSolution().getModel());
int newSelectionIndex = 1 + selectionIndex;
// already changed
if (newSelectionIndex <= iSelectionIdx)
return;
// already changed
if (selectionIndex == -1 && iSelectionIdx >= 0)
return;
iSelectionIdx = newSelectionIndex;
if (selectionIndex >= 0) {
try {
NeighbourSelection<V, T> selection = iSelections.get(selectionIndex % iSelections.size());
if (selection instanceof InfoProvider) {
Map<String, String> info = new HashMap<String, String>();
((InfoProvider<V, T>) selection).getInfo(iSolver.currentSolution().getAssignment(), info);
if (!info.isEmpty())
for (Map.Entry<String, String> e : info.entrySet()) progress.debug(e.getKey() + ": " + e.getValue());
}
} catch (Exception e) {
}
}
sLogger.info("Phase changed to " + ((newSelectionIndex % iSelections.size()) + 1));
progress.debug(iSolver.currentSolution().toString());
if (iSolver.currentSolution().getBestInfo() == null || iSolver.getSolutionComparator().isBetterThanBestSolution(iSolver.currentSolution()))
iSolver.currentSolution().saveBest();
iSelections.get(iSelectionIdx % iSelections.size()).init(iSolver);
} finally {
iSolver.currentSolution().getLock().writeLock().unlock();
}
}
Aggregations