I have a question regarding Jsprit.Parameter.FAST_REGRET.

I am trying to use it with initial routes, but no solution is generated. If I remove “Jsprit.Parameter.FAST_REGRET”, the solution is generated. I don’t know why is that.

From the description of FAST_REGRET, it says “Fast regret boosts your computation, i.e. it reduces computation time significantly. However, it can only be use currently if no complicated dependencies between jobs and activities are defined.”

What does “no complicated dependencies between jobs and activities are defined” mean?

Is it possible to use FAST_REGRET when you have initial routes?



This is incredibly obscure I’m afraid. What do you mean “no solution is generated”? How are you using “Jsprit.Parameter.FAST_REGRET”? Are there errors; what’s your setup? You need to give us some basis on which to make a judgement.

Sorry if I wasn’t clear. Here is how I use Jsprit.Parameter.FAST_REGRET:

VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();

VehicleRoute initialRoute = VehicleRoute.Builder.newInstance(getVehicle(“IDxxx”, vrpBuilder)).addService(getService(“s1”, vrpBuilder)).addService(getService(“s2”, vrpBuilder)).build();
VehicleRoutingProblem problem = vrpBuilder.build();

Builder vraBuilder = Jsprit.Builder.newInstance(problem).setStateAndConstraintManager(stateManager, constraintManager);
vraBuilder.setProperty(Jsprit.Parameter.FAST_REGRET, “true”);
VehicleRoutingAlgorithm vra = vraBuilder.buildAlgorithm();

The problem is that there are no errors to show or tack, and no solution is produced. It is just stopped.
However, if I remove the initialRoute part, it works fine and the solution is produced. Or if I remove the vraBuilder.setProperty(Jsprit.Parameter.FAST_REGRET, “true”) part and keep the initialRoute part, it works fine and the solution is produced.



Does anyone experience the same problem described above?

Can “Jsprit.Parameter.FAST_REGRET” be used with “addInitialVehicleRoute( )”?


are the jobs you added to the initialRoute (i.e., services s1 and s2) part of the vrp? if so, you probably will need to remove them from the vrp.

No, they are not part of the vrp. I checked that.

It is very strange that when I add Jsprit.Parameter.FAST_REGRET, it does not work:

vraBuilder.setProperty(Jsprit.Parameter.FAST_REGRET, “true”);

If I remove it, it works fine with the initialRoute.

Any thoughts what Jsprit.Parameter.FAST_REGRET does? Thanks!

are there any other constraints that you added to the problem?

and also just to confirm, the algo worked fine when you added Jsprit.Parameter.FAST_REGRET and removed the initial route?

Best regards,

There are no other constraints.

Yes, the algo worked fine when I added Jsprit.Parameter.FAST_REGRET and removed the initial route.


hmm, is it possible that you can share with us the full code to construct the vrp and the algo? thanks.

Here is the full code:

import jsprit.core.algorithm.VehicleRoutingAlgorithm;
import jsprit.core.algorithm.box.Jsprit;
import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.VehicleRoutingProblem.Builder;
import jsprit.core.problem.io.VrpXMLReader;
import jsprit.core.problem.io.VrpXMLWriter;
import jsprit.core.problem.job.Job;
import jsprit.core.problem.job.Service;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.reporting.SolutionPrinter;
import jsprit.core.util.Solutions;
import java.util.Collection;

public class MultipleDepotWithInitialRoutesExample {

public static void main(String[] args) {

    VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
     * Read cordeau-instance p01
    new VrpXMLReader(vrpBuilder).read("input/cordeau01.xml");

     * Add initial route with 1_4_vehicle and services 44, 26
    VehicleRoute initialRoute = VehicleRoute.Builder.newInstance(getVehicle("1_4_vehicle", vrpBuilder)).addService(getService("44", vrpBuilder))
        .addService(getService("26", vrpBuilder)).build();

    VehicleRoutingProblem vrp = vrpBuilder.build();

    // this works fine
//VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).buildAlgorithm();
    // this does not work, when Jsprit.Parameter.FAST_REGRET is used
VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp)
			.setProperty(Jsprit.Parameter.FAST_REGRET, "true").buildAlgorithm();
    Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();



private static Service getService(String serviceId, Builder vrpBuilder) {
    for (Job j : vrpBuilder.getAddedJobs()) {
        if (j.getId().equals(serviceId)) {
            return (Service) j;
    return null;

private static Vehicle getVehicle(String vehicleId, Builder vrpBuilder) {
    for (Vehicle v : vrpBuilder.getAddedVehicles()) {
        if (v.getId().equals(vehicleId)) return v;
    return null;

services 44 and 26 are added to the initial route by .addService(getService(“44”, vrpBuilder)) and .addService(getService(“26”, vrpBuilder)). it looks to me that they are part of the vrp, no?

Best regards,

No, they are not part of the vrp. You can check it using:

“since job (service) 26 and 44 are already planned in initial route and thus static AND sequence is fixed they should not be in jobMap anymore (only variable jobs are in jobMap).”

The example I posted is from:


I got the following error when I run the above code with “Jsprit.Parameter.FAST_REGRET”:

Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 50
at jsprit.core.algorithm.recreate.RegretInsertionFast.updateInsertionData(RegretInsertionFast.java:164)
at jsprit.core.algorithm.recreate.RegretInsertionFast.insertUnassignedJobs(RegretInsertionFast.java:136)
at jsprit.core.algorithm.recreate.AbstractInsertionStrategy.insertJobs(AbstractInsertionStrategy.java:89)
at jsprit.core.algorithm.InsertionInitialSolutionFactory.createSolution(InsertionInitialSolutionFactory.java:56)
at jsprit.core.algorithm.PrettyAlgorithmBuilder$2.informAlgorithmStarts(PrettyAlgorithmBuilder.java:144)
at jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners.algorithmStarts(VehicleRoutingAlgorithmListeners.java:127)
at jsprit.core.algorithm.VehicleRoutingAlgorithm.algorithmStarts(VehicleRoutingAlgorithm.java:296)
at jsprit.core.algorithm.VehicleRoutingAlgorithm.searchSolutions(VehicleRoutingAlgorithm.java:196)
at MultipleDepotWithInitialRoutesExample.main(MultipleDepotWithInitialRoutesExample.java:48)

exactly, I got the same error when I constructed a small example.

what you need to do is that you should not add services 26 and 44 to the vrp.

What do you mean not adding them to vrp? They are already not part of vrp since I put them in initial route.

look at the following example. s1 is added to the initial route, and is also added to the vrp. yes vrp.getJobs().containsKey(“s1”) will return false, but the algo will throw the error you encountered.

how to fix it? do not call .addJob(s1) when constructing the vrp.

    VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type")
    VehicleImpl v = VehicleImpl.Builder.newInstance("v1")
        .setStartLocation(Location.newInstance(1, 0))
    Service s1 = Service.Builder.newInstance("s1").setLocation(Location.newInstance(0, 0))
    Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(0, 0))
    Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(0, 0))
    VehicleRoute initialRoute = VehicleRoute.Builder.newInstance(v)
    VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance()

    VehicleRoutingAlgorithm algorithm = Jsprit.Builder.newInstance(vrp)
        .setProperty(Jsprit.Parameter.FAST_REGRET, "true")
    VehicleRoutingProblemSolution s = Solutions.bestOf(algorithm.searchSolutions());
    SolutionPrinter.print(vrp, s, SolutionPrinter.Print.VERBOSE);

I think this is not the reason for the error. In my previous example that I posted which is adopted from (see below):

There is no addJob() for the jobs in the initialRoute(). So, s1 is added to the initial route, and is not added to the vrp.

Any other thoughts? Thanks!

I ll have a look at this asap also (within the next two weeks).
I just opened an issue for this: https://github.com/graphhopper/jsprit/issues/331

Great, thank you!!!