Hi, I’m currently trying to create a way to end up with 5 best DIFFERENT solutions throughout the iteration process.
Is this a feasible way of achieving it?
I’m currently adding a solutionchecker to know if solutions are the same, but is there a more native way to do it through JSprit?
I have added an IterationsEndListener
`algorithm.addListener(new IterationEndsListener() {
@Override
public void informIterationEnds(int i, VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> iterationSolutions) {
VehicleRoutingProblemSolution iterationSolution = Solutions.bestOf(iterationSolutions);
if(iterationSolution != null && !alternativeExists(iterationSolution))
if(MAX_ALTERNATIVES > alternatives.size()) {
alternatives.add(iterationSolution);
} else {
alternatives.add(iterationSolution);
alternatives.sort(solutionComparator);
alternatives.remove(alternatives.size() - 1);
}
}
});`
and something of a checker for same solutions
` private boolean alternativeExists(VehicleRoutingProblemSolution newSolution) {
int index = 0;
int checker;
for(VehicleRoutingProblemSolution oldSolution : alternatives) {
checker = 0;
if(oldSolution.getCost() == newSolution.getCost()) {
System.out.println("same cost");
checker++;
}
if(oldSolution.getUnassignedJobs().size() == newSolution.getUnassignedJobs().size()
&& oldSolution.getUnassignedJobs().containsAll(newSolution.getUnassignedJobs())) {
System.out.println("same unassigned jobs");
checker++;
}
if(oldSolution.getRoutes().size() == newSolution.getRoutes().size() &&
oldSolution.getRoutes().containsAll(newSolution.getRoutes())) {
System.out.println("same routes");
checker++;
}
System.err.println("[" + index + "] " + checker);
if(checker == 3)
return true;
index ++;
}
return false;
}
`