0

I am scheduling passenger pickup/dropoff routes.

Multiple passengers in a vehicle is good!

Passenger extra time in vehicle is bad.

If Bob lives close to dest and Alice lives far from dest, ideally we would pick up Alice, then Bob, then drop them both off. JSprit doesn't seem to have a built-in constraint for this.

Essentially, I want a soft constraint for passenger extra minutes in vehicle, above the straight-shot drive time from pickup to dropoff. I think a simple penalty for overall time in vehicle would work all right instead of calculating the extra. Any thoughts about how to structure this constraint in JSprit? Is it a soft version of MaxTimeInVehicleConstraint?

Sam Barnum
  • 10,559
  • 3
  • 54
  • 60

1 Answers1

0

I've solved this by using JSprit.setObjectiveFunction() instead of a custom constraint. Much simpler to implement.

public double getCosts( VehicleRoutingProblemSolution solution ) {
    double costPerPassengerSecond = 0.001;
    double costs = 0.0;
    int passengersInVehicle = 0;
    for ( VehicleRoute route : solution.getRoutes() ) {
        costs += route.getVehicle().getType().getVehicleCostParams().fix;
        TourActivity prevAct = route.getStart();

        for ( TourActivity act : route.getActivities() ) {
            costs += vrp.getTransportCosts().getTransportCost(prevAct.getLocation(), act.getLocation(), prevAct.getEndTime(), route.getDriver(), route.getVehicle());
            //costs += vrp.getActivityCosts().getActivityCost(act, act.getArrTime(), route.getDriver(), route.getVehicle()); // there are no activity costs, because CostPerServiceTime is zero
            costs += costPerPassengerSecond * passengersInVehicle * vrp.getTransportCosts().getTransportTime(prevAct.getLocation(), act.getLocation(), prevAct.getEndTime(), route.getDriver(), route.getVehicle());
            passengersInVehicle += act.getSize().get(0);
        }


        costs += vrp.getTransportCosts().getTransportCost(prevAct.getLocation(), route.getEnd().getLocation(), prevAct.getEndTime(), route.getDriver(), route.getVehicle());
        //if ( route.getVehicle().getBreak() != null && !hasBreak && route.getEnd().getArrTime() > route.getVehicle().getBreak().getTimeWindow().getEnd() ) {
        //  costs += 4.0 * (maxCosts * 2.0 + route.getVehicle().getBreak().getServiceDuration() * route.getVehicle().getType().getVehicleCostParams().perServiceTimeUnit);
        //}

    }
    return costs;
}
Sam Barnum
  • 10,559
  • 3
  • 54
  • 60