1

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();
  • Welcome to Stack Overflow! You seem to be asking for someone to write some code for you. Stack Overflow is a question and answer site, not a code-writing service. Please [see here](http://stackoverflow.com/help/how-to-ask) to learn how to write effective questions. – Dan Lowe Oct 18 '15 at 19:55
  • Hi @DanLowe, I have written some code already, adding it to my post.. Thanks for the feedback :) – Kshitiz Sethia Oct 18 '15 at 20:50

1 Answers1

0

Hmm, I'm still learning the ropes in terms of how to ask a question. I have almost solved the problem described above. Here's my results (and a link to the whole code):

  1. Specifying that there are finite ambulances, but they can go on multiple trips. - Set FleetSize to FINITE
  2. Constraining the patients to be delivered to the hospital before they die, or leave them. Shipment.Builder.newInstance("...").setDeliveryTimeWindow(time_of_patient_dying) achieves this.
  3. Adding a 1 minute unload time for any ambulance reaching a hospital for deliveries. - Inherit VehicleRoutingTransportCosts and add 1 to all distance and times.

  4. Let the ambulances choose better routes by letting them deliver patients to any hospital. - Still unresolved.

  • Can you specify point 4 further. Which part is unresolved here? – Stefan Schröder Nov 02 '15 at 20:13
  • I want to be able to assign delivery deadline to the shipments. But they should be able to be delivered to any depot. Does this description help? Or should I give an example from the problem? – Kshitiz Sethia Nov 04 '15 at 01:51
  • This is interesting. However, it is not yet easily possible, i.e. unfortunately you can only set one delivery location a priori. Please add a new feature to jsprit's issue tracker. – Stefan Schröder Nov 08 '15 at 13:16