public void add(TimeWindow timeWindow){ for(TimeWindow tw : timeWindows){ if(timeWindow.getStart() > tw.getStart() && timeWindow.getStart() < tw.getEnd()){ throw new IllegalArgumentException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow); } if(timeWindow.getEnd() > tw.getStart() && timeWindow.getEnd() < tw.getEnd()){ throw new IllegalArgumentException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow); } if(timeWindow.getStart() <= tw.getStart() && timeWindow.getEnd() >= tw.getEnd()){ throw new IllegalArgumentException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow); } } timeWindows.add(timeWindow); }
public Builder addPickup(Shipment shipment, TimeWindow pickupTimeWindow) { if (openShipments.contains(shipment)) throw new IllegalArgumentException("shipment has already been added. cannot add it twice."); List<AbstractActivity> acts = jobActivityFactory.createActivities(shipment); TourActivity act = acts.get(0); act.setTheoreticalEarliestOperationStartTime(pickupTimeWindow.getStart()); act.setTheoreticalLatestOperationStartTime(pickupTimeWindow.getEnd()); tourActivities.addActivity(act); openShipments.add(shipment); openActivities.put(shipment, acts.get(1)); return this; }
public Builder addDelivery(Shipment shipment, TimeWindow deliveryTimeWindow) { if (openShipments.contains(shipment)) { TourActivity act = openActivities.get(shipment); act.setTheoreticalEarliestOperationStartTime(deliveryTimeWindow.getStart()); act.setTheoreticalLatestOperationStartTime(deliveryTimeWindow.getEnd()); tourActivities.addActivity(act); openShipments.remove(shipment); } else { throw new IllegalArgumentException("cannot deliver shipment. shipment " + shipment + " needs to be picked up first."); } return this; }
public Builder addService(Service service, TimeWindow timeWindow) { if (service == null) throw new IllegalArgumentException("service must not be null"); List<AbstractActivity> acts = jobActivityFactory.createActivities(service); TourActivity act = acts.get(0); act.setTheoreticalEarliestOperationStartTime(timeWindow.getStart()); act.setTheoreticalLatestOperationStartTime(timeWindow.getEnd()); tourActivities.addActivity(act); return this; }
public static void main(String[] args) { VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); new LopezIbanezBlumReader(builder).read("input/Dumas/n20w20.001.txt"); VehicleRoutingProblem vrp = builder.build(); System.out.println("0->1: " + vrp.getTransportCosts().getTransportCost(Location.newInstance(0), Location.newInstance(1), 0, null, null)); System.out.println("0->20: " + vrp.getTransportCosts().getTransportCost(Location.newInstance(0), Location.newInstance(20), 0, null, null)); System.out.println("4->18: " + vrp.getTransportCosts().getTransportCost(Location.newInstance(4), Location.newInstance(18), 0, null, null)); System.out.println("20->8: " + vrp.getTransportCosts().getTransportCost(Location.newInstance(20), Location.newInstance(8), 0, null, null)); System.out.println("18: " + ((Service) vrp.getJobs().get("" + 18)).getTimeWindow().getStart() + " " + ((Service) vrp.getJobs().get("" + 18)).getTimeWindow().getEnd()); System.out.println("20: " + ((Service) vrp.getJobs().get("" + 20)).getTimeWindow().getStart() + " " + ((Service) vrp.getJobs().get("" + 20)).getTimeWindow().getEnd()); System.out.println("1: " + ((Service) vrp.getJobs().get("" + 1)).getTimeWindow().getStart() + " " + ((Service) vrp.getJobs().get("" + 1)).getTimeWindow().getEnd()); }
private Builder addBreakInternally(Break currentBreak, TimeWindow timeWindow, Location breakLocation) { List<AbstractActivity> acts = jobActivityFactory.createActivities(currentBreak); BreakActivity act = (BreakActivity) acts.get(0); act.setTheoreticalEarliestOperationStartTime(timeWindow.getStart()); act.setTheoreticalLatestOperationStartTime(timeWindow.getEnd()); act.setLocation(breakLocation); tourActivities.addActivity(act); return this; }
private double scoreService(InsertionData best, Job job) { Location location = ((Service) job).getLocation(); double maxDepotDistance = 0; if (location != null) { maxDepotDistance = Math.max( getDistance(best.getSelectedVehicle().getStartLocation(), location), getDistance(best.getSelectedVehicle().getEndLocation(), location) ); } return Math.max(timeWindowParam * (((Service) job).getTimeWindow().getEnd() - ((Service) job).getTimeWindow().getStart()), minTimeWindowScore) + depotDistanceParam * maxDepotDistance; }
private double scoreShipment(InsertionData best, Job job) { Shipment shipment = (Shipment) job; double maxDepotDistance_1 = Math.max( getDistance(best.getSelectedVehicle().getStartLocation(), shipment.getPickupLocation()), getDistance(best.getSelectedVehicle().getStartLocation(), shipment.getDeliveryLocation()) ); double maxDepotDistance_2 = Math.max( getDistance(best.getSelectedVehicle().getEndLocation(), shipment.getPickupLocation()), getDistance(best.getSelectedVehicle().getEndLocation(), shipment.getDeliveryLocation()) ); double maxDepotDistance = Math.max(maxDepotDistance_1, maxDepotDistance_2); double minTimeToOperate = Math.min(shipment.getPickupTimeWindow().getEnd() - shipment.getPickupTimeWindow().getStart(), shipment.getDeliveryTimeWindow().getEnd() - shipment.getDeliveryTimeWindow().getStart()); return Math.max(timeWindowParam * minTimeToOperate, minTimeWindowScore) + depotDistanceParam * maxDepotDistance; }
deliveryAct2Insert.setTheoreticalEarliestOperationStartTime(timeWindow.getStart()); deliveryAct2Insert.setTheoreticalLatestOperationStartTime(timeWindow.getEnd()); ActivityContext activityContext = new ActivityContext(); deliveryAct2Insert.setTheoreticalEarliestOperationStartTime(bestTimeWindow.getStart()); deliveryAct2Insert.setTheoreticalLatestOperationStartTime(bestTimeWindow.getEnd()); insertionData.getEvents().add(new InsertActivity(currentRoute, newVehicle, deliveryAct2Insert, insertionIndex));
pickupShipment.setTheoreticalEarliestOperationStartTime(pickupTimeWindow.getStart()); pickupShipment.setTheoreticalLatestOperationStartTime(pickupTimeWindow.getEnd()); ActivityContext activityContext = new ActivityContext(); deliverShipment.setTheoreticalEarliestOperationStartTime(deliveryTimeWindow.getStart()); deliverShipment.setTheoreticalLatestOperationStartTime(deliveryTimeWindow.getEnd()); ActivityContext activityContext_ = new ActivityContext(); pickupShipment.setTheoreticalEarliestOperationStartTime(bestPickupTimeWindow.getStart()); pickupShipment.setTheoreticalLatestOperationStartTime(bestPickupTimeWindow.getEnd()); deliverShipment.setTheoreticalEarliestOperationStartTime(bestDeliveryTimeWindow.getStart()); deliverShipment.setTheoreticalLatestOperationStartTime(bestDeliveryTimeWindow.getEnd()); insertionData.setVehicleDepartureTime(newVehicleDepartureTime);
boolean pickupInsertionNotFulfilledBreak = true; for (TimeWindow pickupTimeWindow : shipment.getPickupTimeWindows()) { pickupShipment.setTheoreticalEarliestOperationStartTime(pickupTimeWindow.getStart()); pickupShipment.setTheoreticalLatestOperationStartTime(pickupTimeWindow.getEnd()); ActivityContext activityContext = new ActivityContext(); boolean deliveryInsertionNotFulfilledBreak = true; for (TimeWindow deliveryTimeWindow : shipment.getDeliveryTimeWindows()) { deliverShipment.setTheoreticalEarliestOperationStartTime(deliveryTimeWindow.getStart()); deliverShipment.setTheoreticalLatestOperationStartTime(deliveryTimeWindow.getEnd()); ActivityContext activityContext_ = new ActivityContext(); pickupShipment.setTheoreticalEarliestOperationStartTime(bestPickupTimeWindow.getStart()); pickupShipment.setTheoreticalLatestOperationStartTime(bestPickupTimeWindow.getEnd()); deliverShipment.setTheoreticalEarliestOperationStartTime(bestDeliveryTimeWindow.getStart()); deliverShipment.setTheoreticalLatestOperationStartTime(bestDeliveryTimeWindow.getEnd()); insertionData.setVehicleDepartureTime(newVehicleDepartureTime);
for (Location location : locations) { breakAct2Insert.setLocation(location); breakAct2Insert.setTheoreticalEarliestOperationStartTime(breakToInsert.getTimeWindow().getStart()); breakAct2Insert.setTheoreticalLatestOperationStartTime(breakToInsert.getTimeWindow().getEnd()); ConstraintsStatus status = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct, breakAct2Insert, nextAct, prevActStartTime);
public Builder addDelivery(Shipment shipment, TimeWindow deliveryTimeWindow) { if (openShipments.contains(shipment)) { TourActivity act = openActivities.get(shipment); act.setTheoreticalEarliestOperationStartTime(deliveryTimeWindow.getStart()); act.setTheoreticalLatestOperationStartTime(deliveryTimeWindow.getEnd()); tourActivities.addActivity(act); openShipments.remove(shipment); } else { throw new IllegalArgumentException("cannot deliver shipment. shipment " + shipment + " needs to be picked up first."); } return this; }
public Builder addService(Service service, TimeWindow timeWindow) { if (service == null) throw new IllegalArgumentException("service must not be null"); List<AbstractActivity> acts = jobActivityFactory.createActivities(service); TourActivity act = acts.get(0); act.setTheoreticalEarliestOperationStartTime(timeWindow.getStart()); act.setTheoreticalLatestOperationStartTime(timeWindow.getEnd()); tourActivities.addActivity(act); return this; }
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.duration", shipment.getPickupServiceTime()); for(TimeWindow tw : pu_tws) { xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.timeWindows.timeWindow(" + index + ").start", tw.getStart()); xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.timeWindows.timeWindow(" + index + ").end", tw.getEnd()); ++index; index = 0; for(TimeWindow tw : del_tws) { xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.timeWindows.timeWindow(" + index + ").start", tw.getStart()); xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.timeWindows.timeWindow(" + index + ").end", tw.getEnd()); ++index;
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").duration", service.getServiceDuration()); for(TimeWindow tw : tws) { xmlConfig.setProperty(shipmentPathString + "(" + counter + ").timeWindows.timeWindow(" + index + ").start", tw.getStart()); xmlConfig.setProperty(shipmentPathString + "(" + counter + ").timeWindows.timeWindow(" + index + ").end", tw.getEnd()); ++index;
private Builder addBreakInternally(Break currentBreak, TimeWindow timeWindow, Location breakLocation) { List<AbstractActivity> acts = jobActivityFactory.createActivities(currentBreak); BreakActivity act = (BreakActivity) acts.get(0); act.setTheoreticalEarliestOperationStartTime(timeWindow.getStart()); act.setTheoreticalLatestOperationStartTime(timeWindow.getEnd()); act.setLocation(breakLocation); tourActivities.addActivity(act); return this; }
private double scoreService(InsertionData best, Job job) { Location location = ((Service) job).getLocation(); double maxDepotDistance = 0; if (location != null) { maxDepotDistance = Math.max( getDistance(best.getSelectedVehicle().getStartLocation(), location), getDistance(best.getSelectedVehicle().getEndLocation(), location) ); } return Math.max(timeWindowParam * (((Service) job).getTimeWindow().getEnd() - ((Service) job).getTimeWindow().getStart()), minTimeWindowScore) + depotDistanceParam * maxDepotDistance; }
xmlConfig.setProperty(vehiclePathString + "(" + counter + ").breaks.duration", vehicle.getBreak().getServiceDuration()); for(TimeWindow tw : tws) { xmlConfig.setProperty(vehiclePathString + "(" + counter + ").breaks.timeWindows.timeWindow(" + index + ").start", tw.getStart()); xmlConfig.setProperty(vehiclePathString + "(" + counter + ").breaks.timeWindows.timeWindow(" + index + ").end", tw.getEnd()); ++index;
static CarrierService createCarrierService(Service service) { CarrierService.Builder serviceBuilder = CarrierService.Builder.newInstance(Id.create(service.getId(), CarrierService.class), Id.create(service.getLocation().getId(), Link.class)); serviceBuilder.setCapacityDemand(service.getSize().get(0)); serviceBuilder.setServiceDuration(service.getServiceDuration()); serviceBuilder.setServiceStartTimeWindow(TimeWindow.newInstance(service.getTimeWindow().getStart(), service.getTimeWindow().getEnd())); return serviceBuilder.build(); }