1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

modify insertion to incorporate open-routes

This commit is contained in:
Stefan Schroeder 2013-11-27 17:22:42 +01:00
parent e5e5783d67
commit 4e25d894b6
7 changed files with 299 additions and 0 deletions

View file

@ -62,10 +62,20 @@ class Inserter {
if(job instanceof Service){
route.getTourActivities().addActivity(iData.getDeliveryInsertionIndex(), this.activityFactory.createActivity((Service)job));
route.setDepartureTime(iData.getVehicleDepartureTime());
if(!iData.getSelectedVehicle().isReturnToDepot()){
if(iData.getDeliveryInsertionIndex()>=route.getTourActivities().getActivities().size()){
setEndLocation(route,(Service)job);
}
}
}
else delegator.handleJobInsertion(job, iData, route);
}
private void setEndLocation(VehicleRoute route, Service service) {
route.getEnd().setCoordinate(service.getCoord());
route.getEnd().setLocationId(service.getLocationId());
}
public void setNextHandler(JobInsertionHandler jobInsertionHandler){
this.delegator = jobInsertionHandler;
}
@ -86,10 +96,20 @@ class Inserter {
route.getTourActivities().addActivity(iData.getDeliveryInsertionIndex(), deliverShipment);
route.getTourActivities().addActivity(iData.getPickupInsertionIndex(), pickupShipment);
route.setDepartureTime(iData.getVehicleDepartureTime());
if(!iData.getSelectedVehicle().isReturnToDepot()){
if(iData.getDeliveryInsertionIndex()>=route.getTourActivities().getActivities().size()){
setEndLocation(route,(Shipment)job);
}
}
}
else delegator.handleJobInsertion(job, iData, route);
}
private void setEndLocation(VehicleRoute route, Shipment shipment) {
route.getEnd().setCoordinate(shipment.getDeliveryCoord());
route.getEnd().setLocationId(shipment.getDeliveryLocation());
}
public void setNextHandler(JobInsertionHandler jobInsertionHandler){
this.delegator = jobInsertionHandler;
}

View file

@ -23,6 +23,7 @@ package jsprit.core.algorithm.recreate;
import jsprit.core.problem.cost.VehicleRoutingActivityCosts;
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
import jsprit.core.problem.misc.JobInsertionContext;
import jsprit.core.problem.solution.route.activity.End;
import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.util.CalculationUtils;
@ -61,6 +62,13 @@ class LocalActivityInsertionCostsCalculator implements ActivityInsertionCostsCal
double act_costs_newAct = activityCosts.getActivityCost(newAct, newAct_arrTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
//open routes
if(nextAct instanceof End){
if(!iFacts.getNewVehicle().isReturnToDepot()){
return new ActivityInsertionCosts(tp_costs_prevAct_newAct, tp_time_prevAct_newAct);
}
}
double tp_costs_newAct_nextAct = routingCosts.getTransportCost(newAct.getLocationId(), nextAct.getLocationId(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
double tp_time_newAct_nextAct = routingCosts.getTransportTime(newAct.getLocationId(), nextAct.getLocationId(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle());

View file

@ -35,5 +35,7 @@ public interface Vehicle {
public abstract String getId();
public abstract int getCapacity();
public abstract boolean isReturnToDepot();
}

View file

@ -54,6 +54,8 @@ public class VehicleImpl implements Vehicle {
private double earliestStart = 0.0;
private double latestArrival = Double.MAX_VALUE;
private boolean returnToDepot = true;
private VehicleType type = VehicleTypeImpl.Builder.newInstance("default", 0).build();
private Builder(String id) {
@ -66,6 +68,11 @@ public class VehicleImpl implements Vehicle {
return this;
}
public Builder setReturnToDepot(boolean returnToDepot){
this.returnToDepot = returnToDepot;
return this;
}
public Builder setLocationId(String id){
this.locationId = id;
return this;
@ -113,6 +120,8 @@ public class VehicleImpl implements Vehicle {
private final double earliestDeparture;
private final double latestArrival;
private boolean returnToDepot;
private VehicleImpl(Builder builder){
id = builder.id;
@ -121,6 +130,7 @@ public class VehicleImpl implements Vehicle {
locationId = builder.locationId;
earliestDeparture = builder.earliestStart;
latestArrival = builder.latestArrival;
returnToDepot = builder.returnToDepot;
}
@ -193,5 +203,16 @@ public class VehicleImpl implements Vehicle {
public int getCapacity() {
return type.getCapacity();
}
/**
* @return the returnToDepot
*/
public boolean isReturnToDepot() {
return returnToDepot;
}
}