Need multiple best solutions

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() {
            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()) {
                        } else {
                            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");
            if(oldSolution.getUnassignedJobs().size() == newSolution.getUnassignedJobs().size()
                    && oldSolution.getUnassignedJobs().containsAll(newSolution.getUnassignedJobs())) {
                System.out.println("same unassigned jobs");
            if(oldSolution.getRoutes().size() == newSolution.getRoutes().size() &&
                    oldSolution.getRoutes().containsAll(newSolution.getRoutes())) {
                System.out.println("same routes");
            System.err.println("[" + index + "] " + checker);
            if(checker == 3)
                return true;
            index ++;
        return false;

Hello there

Sorry to dig this old topic out, but I am also interested in this approach: keep the 10 best (and different) solutions.

I retrieved your code, which seem to work quite well, but I’m not sure it is the best way to go.
Has Jsprit a best (or native) way to keep these solutions?


Powered by Discourse