Hi,
I am trying to model a scenario where there are 2 shipments having same pickup and destination locations and pickup time window.
Shipment S1 required capacity : 4500
Shipment S2 required capacity : 2500
There are 2 vehicles(V1,V2) available at pickup location(same coordinates) with capacity of 5000 and 3000 respectively.
In this scenario, S1 should get assigned to V1 and S2 to V2.
However, S2 is getting assigned to V1 keeping S1 in unassigned state. Not sure if I am missing something. I am using version 1.6.3-SNAPSHOT
Regards,
Amit
Code:
public class MultipleShipmentMultipleVehicles {
public static void main(String[] args) {
Location.Builder locBuilder = Location.Builder.newInstance();
Coordinate coordinate1 = Coordinate.newInstance(5, 7);
locBuilder.setId("VL1").setCoordinate(coordinate1);
Location VL1 = locBuilder.build();
Location.Builder locBuilder1 = Location.Builder.newInstance();
locBuilder1.setId("PL1").setCoordinate(coordinate1);
Location PL1 = locBuilder1.build();
Location.Builder locBuilder2 = Location.Builder.newInstance();
Coordinate coordinate2 = Coordinate.newInstance(6, 9);
locBuilder2.setId("DL1").setCoordinate(coordinate2);
Location DL1 = locBuilder2.build();
VehicleTypeImpl.Builder vehicleType1Builder = VehicleTypeImpl.Builder.newInstance("vehicleType1")
.addCapacityDimension(0, 5000);
VehicleType vehicleType1 = vehicleType1Builder.build();
Builder vehicleBuilder1 = VehicleImpl.Builder.newInstance("V1");
vehicleBuilder1.setStartLocation(VL1);
vehicleBuilder1.setType(vehicleType1);
VehicleImpl vehicle1 = vehicleBuilder1.build();
VehicleTypeImpl.Builder vehicleType2Builder = VehicleTypeImpl.Builder.newInstance("vehicleType2")
.addCapacityDimension(0, 3000);
VehicleType vehicleType2 = vehicleType2Builder.build();
Builder vehicleBuilder2 = VehicleImpl.Builder.newInstance("V2");
vehicleBuilder2.setStartLocation(VL1);
vehicleBuilder2.setType(vehicleType2);
VehicleImpl vehicle2 = vehicleBuilder2.build();
VehicleRoutingTransportCostsMatrix.Builder costMatrixBuilder = com.graphhopper.jsprit.core.util.VehicleRoutingTransportCostsMatrix.Builder
.newInstance(true);
costMatrixBuilder.addTransportDistance("PL1", "DL1", 10.0);
costMatrixBuilder.addTransportTime("PL1", "DL1", 60.0);
costMatrixBuilder.addTransportDistance("VL1", "DL1", 25.0);
costMatrixBuilder.addTransportTime("VL1", "DL1", 150.0);
costMatrixBuilder.addTransportDistance("VL1", "PL1", 0);
costMatrixBuilder.addTransportTime("VL1", "PL1", 0);
VehicleRoutingTransportCosts costMatrix = costMatrixBuilder.build();
Shipment shipment1 = Shipment.Builder.newInstance("S1").addSizeDimension(0, 4500).setPickupLocation(PL1)
.setDeliveryLocation(DL1).setPickupTimeWindow(new TimeWindow(200.0, 200.00)).build();
Shipment shipment2 = Shipment.Builder.newInstance("S2").addSizeDimension(0, 2500).setPickupLocation(PL1)
.setDeliveryLocation(DL1).setPickupTimeWindow(new TimeWindow(200.0, 200.00)).build();
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
vrpBuilder.addVehicle(vehicle1).addVehicle(vehicle2);
vrpBuilder.addJob(shipment1).addJob(shipment2);
vrpBuilder.setFleetSize(FleetSize.FINITE);
VehicleRoutingProblem problem = vrpBuilder.setRoutingCost(costMatrix).build();
StateManager stateManager = new StateManager(problem);
stateManager.addStateUpdater(new StateVisitor(stateManager));
VehicleRoutingAlgorithm algorithm = Jsprit.Builder.newInstance(problem).addCoreStateAndConstraintStuff(true)
.setProperty(Jsprit.Parameter.VEHICLE_SWITCH, "true").buildAlgorithm();
algorithm.setMaxIterations(2000);
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);
SolutionPrinter.print(problem, bestSolution, SolutionPrinter.Print.VERBOSE);
}
}