Minimize the total time in jsprit

481 views Asked by At

I think about optimizing the tours of our local fund-raising. We have a fixed amount of groups which move from location to location. The target is that the total time is minimized and (hopefully) all groups take the same amount of time.

So far I only found settings for cost per vehicle operation (distance, fix, transportTime, ...).

Does anyone know how to implement this goal in jsprit?

2

There are 2 answers

0
Sutirtha Kayal On

You need to add customized constraints for your problem.

0
Zufar Muhamadeev On

Total time should be optimized by JSprit without any customization. About same amount time - i think easest way is to create custom SolutionCostCalculator and increase route cost if time is not same.

public class CustomSolutionCostCalculator implements SolutionCostCalculator {

    private StateManager stateManager;

    public SPSolutionCostCalculator(StateManager aStateManager) {
        stateManager = aStateManager;
    }

    @Override
    public double getCosts(VehicleRoutingProblemSolution solution) {
        double cost = 0.0;
        // calculate cost
        return cost;
    }
}

and then use it while create algorithm:

VehicleRoutingProblem vrp = vrpBuilder.build();
// init your vrp

VehicleRoutingAlgorithm algorithm = Jsprit.Builder.newInstance(vrp)
            .setObjectiveFunction(new SPSolutionCostCalculator(stateManager))
            .buildAlgorithm();
Collection<VehicleRoutingProblemSolution> searchSolutions = algorithm.searchSolutions();
VehicleRoutingProblemSolution solution = Solutions.bestOf(searchSolutions);