/** * Returns an unmodifiable list of activities on this route (without start/end). * * @return list of tourActivities */ public List<TourActivity> getActivities() { return Collections.unmodifiableList(tourActivities.getActivities()); }
private Map<Job, VehicleRoute> map(Collection<VehicleRoute> vehicleRoutes) { Map<Job, VehicleRoute> map = new HashMap<Job, VehicleRoute>(vrp.getJobs().size()); for (VehicleRoute r : vehicleRoutes) { for (Job j : r.getTourActivities().getJobs()) { map.put(j, r); } } return map; }
@Override public void handleJobInsertion(Job job, InsertionData iData, VehicleRoute route) { if (job instanceof Service) { route.setVehicleAndDepartureTime(iData.getSelectedVehicle(), iData.getVehicleDepartureTime()); if (!iData.getSelectedVehicle().isReturnToDepot()) { if (iData.getDeliveryInsertionIndex() >= route.getTourActivities().getActivities().size()) { setEndLocation(route, (Service) job); } } TourActivity activity = vehicleRoutingProblem.copyAndGetActivities(job).get(0); route.getTourActivities().addActivity(iData.getDeliveryInsertionIndex(), activity); } else delegator.handleJobInsertion(job, iData, route); }
private TourActivities(TourActivities tour2copy) { for (TourActivity tourAct : tour2copy.getActivities()) { TourActivity newAct = tourAct.duplicate(); this.tourActivities.add(newAct); addJob(newAct); } }
/** * Builds the route. * * @return {@link VehicleRoute} * @throws IllegalArgumentException if there are still shipments that have been picked up though but not delivery. */ public VehicleRoute build() { if (!openShipments.isEmpty()) { throw new IllegalArgumentException("there are still shipments that have not been delivered yet."); } if (!vehicle.isReturnToDepot()) { if (!tourActivities.isEmpty()) { end.setLocation(tourActivities.getActivities().get(tourActivities.getActivities().size() - 1).getLocation()); } } return new VehicleRoute(this); }
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; }
@Override public void inform(Event event) { if (event instanceof InsertBreak) { InsertBreak insertActivity = (InsertBreak) event; if (!insertActivity.getNewVehicle().isReturnToDepot()) { if (insertActivity.getIndex() >= insertActivity.getVehicleRoute().getActivities().size()) { insertActivity.getVehicleRoute().getEnd().setLocation(insertActivity.getActivity().getLocation()); } } VehicleRoute vehicleRoute = ((InsertBreak) event).getVehicleRoute(); if (!vehicleRoute.isEmpty()) { if (vehicleRoute.getVehicle() != ((InsertBreak) event).getNewVehicle()) { if (vehicleRoute.getVehicle().getBreak() != null) { boolean removed = vehicleRoute.getTourActivities().removeJob(vehicleRoute.getVehicle().getBreak()); if (removed) logger.trace("remove old break " + vehicleRoute.getVehicle().getBreak()); } } } insertActivity.getVehicleRoute().getTourActivities().addActivity(insertActivity.getIndex(), ((InsertBreak) event).getActivity()); } }
/** * Adds specified activity at the end of activity-list. * <p>If act instanceof JobActivity, it adds underlying job also. * * @param act to be added * @throws IllegalArgumentException if activity-list already contains act. */ public void addActivity(TourActivity act) { if (tourActivities.contains(act)) throw new IllegalArgumentException("act " + act + " already in tour. cannot add act twice."); tourActivities.add(act); addJob(act); }
/** * Copy constructor copying a route. * * @param route to copy */ private VehicleRoute(VehicleRoute route) { this.start = Start.copyOf(route.getStart()); this.end = End.copyOf(route.getEnd()); this.tourActivities = TourActivities.copyOf(route.getTourActivities()); this.vehicle = route.getVehicle(); this.driver = route.getDriver(); }
/** * Returns tour if tour-activity-sequence is empty, i.e. to activity on the tour yet. * * @return true if route is empty */ public boolean isEmpty() { return tourActivities.isEmpty(); }
public static TourActivities copyOf(TourActivities tourActivities) { return new TourActivities(tourActivities); }
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; }
private TourActivities(TourActivities tour2copy) { for (TourActivity tourAct : tour2copy.getActivities()) { TourActivity newAct = tourAct.duplicate(); this.tourActivities.add(newAct); addJob(newAct); } }
/** * Builds the route. * * @return {@link VehicleRoute} * @throws IllegalArgumentException if there are still shipments that have been picked up though but not delivery. */ public VehicleRoute build() { if (!openShipments.isEmpty()) { throw new IllegalArgumentException("there are still shipments that have not been delivered yet."); } if (!vehicle.isReturnToDepot()) { if (!tourActivities.isEmpty()) { end.setLocation(tourActivities.getActivities().get(tourActivities.getActivities().size() - 1).getLocation()); } } return new VehicleRoute(this); }
@Override public void inform(Event event) { if (event instanceof InsertBreak) { InsertBreak insertActivity = (InsertBreak) event; if (!insertActivity.getNewVehicle().isReturnToDepot()) { if (insertActivity.getIndex() >= insertActivity.getVehicleRoute().getActivities().size()) { insertActivity.getVehicleRoute().getEnd().setLocation(insertActivity.getActivity().getLocation()); } } VehicleRoute vehicleRoute = ((InsertBreak) event).getVehicleRoute(); if (!vehicleRoute.isEmpty()) { if (vehicleRoute.getVehicle() != ((InsertBreak) event).getNewVehicle()) { if (vehicleRoute.getVehicle().getBreak() != null) { boolean removed = vehicleRoute.getTourActivities().removeJob(vehicleRoute.getVehicle().getBreak()); if (removed) logger.trace("remove old break " + vehicleRoute.getVehicle().getBreak()); } } } insertActivity.getVehicleRoute().getTourActivities().addActivity(insertActivity.getIndex(), ((InsertBreak) event).getActivity()); } }
/** * Inserts the specified activity add the specified insertionIndex. Shifts the element currently at that position (if any) and * any subsequent elements to the right (adds one to their indices). * <p>If specified activity instanceof JobActivity, it adds job to jobList. * <p>If insertionIndex > tourActivitiies.size(), it just adds the specified act at the end. * * @param insertionIndex index where activity needs to be inserted * @param act activity to be inserted * @throws IndexOutOfBoundsException if insertionIndex < 0; */ public void addActivity(int insertionIndex, TourActivity act) { assert insertionIndex >= 0 : "insertionIndex < 0, this cannot be"; /* * if 1 --> between start and act(0) --> act(0) * if 2 && 2 <= acts.size --> between act(0) and act(1) --> act(1) * if 2 && 2 > acts.size --> at actEnd * ... * */ if (insertionIndex < tourActivities.size()) { tourActivities.add(insertionIndex, act); } else if (insertionIndex >= tourActivities.size()) { tourActivities.add(act); } addJob(act); }
/** * Copy constructor copying a route. * * @param route to copy */ private VehicleRoute(VehicleRoute route) { this.start = Start.copyOf(route.getStart()); this.end = End.copyOf(route.getEnd()); this.tourActivities = TourActivities.copyOf(route.getTourActivities()); this.vehicle = route.getVehicle(); this.driver = route.getDriver(); }
/** * Returns tour if tour-activity-sequence is empty, i.e. to activity on the tour yet. * * @return true if route is empty */ public boolean isEmpty() { return tourActivities.isEmpty(); }
public static TourActivities copyOf(TourActivities tourActivities) { return new TourActivities(tourActivities); }
@Override public String toString() { return "[start=" + start + "][end=" + end + "][departureTime=" + start.getEndTime() + "][vehicle=" + vehicle + "][driver=" + driver + "][nuOfActs=" + tourActivities.getActivities().size() + "]"; }