Here's the problem that I'm trying to solve:
- There's a town with patients at location (x,y) and a time when they will die.
- The patient needs to reach the hospital before he/she dies in order to be rescued.
- A bunch of hospitals at (x,y) with some ambulances which can pick up maximum of four patients on one trip, and deliver them to any hospital.
- An ambulance starts at a hospital, takes multiple trips and can end up at any hospital.
- We are supposed to save the maximum number of patients we can.
- full problem description here: http://cs.nyu.edu/courses/fall15/CSCI-GA.2965-001/ambulance.html
I'm trying to use jsprit for solving this problem and can't figure out how to do the following: (I want to know what part of the API should I look into)
1) Specifying that there are finite ambulances, but they can go on multiple trips.
- Does setting VehicleRoutingProblem.Builder.setFleetSize(FleetSize.INFINITE) do this? The code doesn't document the exact functionality.
2) Constraining the patients to be delivered to the hospital before they die, or leave them.
- Does Shipment.Builder.newInstance("...").setDeliveryTimeWindow(time_of_patient_dying) achieve this?
3) Adding a 1 minute unload time for any ambulance reaching a hospital for deliveries.
- Don't know which part of the API to look at for this.
4) Let the ambulances choose better routes by letting them deliver patients to any hospital.
- Don't know which part of the API to look at for this.
Here's my code until now:
// make vehicle routing problem builder
VehicleRoutingProblem.Builder vrpBuilder =
VehicleRoutingProblem.Builder.newInstance();
// make vehicle type
VehicleTypeImpl.Builder vehicleTypeBuilder =
VehicleTypeImpl.Builder.newInstance("ambulanceWithFourBeds")
.addCapacityDimension(0, 4);
VehicleType vehicleType = vehicleTypeBuilder.build();
// putting multiple vehicles at every hospital
List<Location> locations = state.getVehicleLocations();
int counter = 0;
for (Location location : locations) {
VehicleImpl.Builder vehicleBuilder =
VehicleImpl.Builder.newInstance("ambulance_" + counter++);
vehicleBuilder.setStartLocation(location);
vehicleBuilder.setType(vehicleType);
vrpBuilder.addVehicle(vehicleBuilder.build());
}
List<Patient> patients = state.getPatients();
counter = 0;
for (Patient patient : patients) {
Shipment shipment = Shipment.Builder.newInstance("patient_" + counter++)
.addSizeDimension(0, 1).setDeliveryTimeWindow(patient.getTimeWindow())
.setPickupLocation(Location.newInstance(patient.x, patient.y))
.setDeliveryLocation(patient.getAssignedClusterCentroid()).build();
vrpBuilder.addJob(shipment);
}
vrpBuilder.setRoutingCost(new ManhattanCosts(vrpBuilder.getLocations()));
VehicleRoutingProblem problem = vrpBuilder.build();