GraphHopper.com | Forum | GitHub | Maps | Blog

Bug with duplicate vehicle type id


#1

Hi all,

Currently jsprit does not forbid duplicate vehicle type id, thus one can define multiple vehicle types with the same id but with different properties such as cost parameters, like I did in the example provided at the end of this post.

In the example, the fleet manager will always use v2 because it thinks v1 and v2 are with the same vehicle type, and it leads to non-optimal solution.

vrp.getTypes() returns only vehicleType1, because jsprit considers two vehicle-types are equal if they have the same typeId.

[[typeId=type][capacity=[noDimensions=1][[dimIndex=0][dimValue=0]]][costs=[fixed=0.0][perTime=0.0][perDistance=1.0][perWaitingTimeUnit=0.0]]]

When I changed the type id of vehicleType2 to a different one, I would get the optimal solution, and vrp.getTypes() would return two vehicle types.

Best regards,
He

    VehicleType vehicleType1 = VehicleTypeImpl.Builder.newInstance("type")
        .build();
    VehicleType vehicleType2 = VehicleTypeImpl.Builder.newInstance("type")
        .setFixedCost(100)
        .build();

    Vehicle v1 = VehicleImpl.Builder.newInstance("v1")
        .setType(vehicleType1)
        .setStartLocation(Location.newInstance(0, 0))
        .setReturnToDepot(true)
        .setLatestArrival(300)
        .build();

    Vehicle v2 = VehicleImpl.Builder.newInstance("v2")
        .setType(vehicleType2)
        .setStartLocation(Location.newInstance(0, 0))
        .setReturnToDepot(true)
        .setLatestArrival(300)
        .build();

    Service s1 = Service.Builder.newInstance("s1")
        .setLocation(Location.newInstance(1, 0))
        .setServiceTime(100)
        .build();
    Service s2 = Service.Builder.newInstance("s2")
        .setLocation(Location.newInstance(1, 0))
        .setServiceTime(100)
        .build();

    VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance()
        .addJob(s1)
        .addJob(s2)
        .addVehicle(v1)
        .addVehicle(v2)
        .setFleetSize(VehicleRoutingProblem.FleetSize.FINITE)
        .build();

    System.out.println(vrp.getTypes());

    Jsprit.Builder algoBuilder = Jsprit.Builder.newInstance(vrp);
    algoBuilder.setProperty(Jsprit.Parameter.FIXED_COST_PARAM, "1.0");
    VehicleRoutingAlgorithm algo = algoBuilder.buildAlgorithm();
    VehicleRoutingProblemSolution solution = Solutions.bestOf(algo.searchSolutions());
    SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE);