private double distance(TourActivity activity) { return distanceCalculator.getDistance(prevAct.getLocation(), activity.getLocation(),prevActDeparture, route.getVehicle()); }
double getDistance(TourActivity from, TourActivity to) { return costMatrix.getDistance(from.getLocation().getId(), to.getLocation().getId()); } }
private double transportCost(TourActivity activity) { return transportCost.getTransportCost(prevAct.getLocation(), activity.getLocation(), prevActDeparture, route.getDriver(), route.getVehicle()); }
double getDistance(TourActivity from, TourActivity to) { return costsMatrix.getDistance(from.getLocation().getId(), to.getLocation().getId()); }
@Override public void visit(TourActivity activity) { double distance = distanceCalculator.getDistance(prevAct.getLocation(), activity.getLocation(), prevAct.getEndTime(), route.getVehicle()); sumDistance += distance; stateManager.putActivityState(activity, distanceId, sumDistance); prevAct = activity; }
private double c(TourActivity from, TourActivity to, Vehicle vehicle) { return vrp.getTransportCosts().getTransportCost(from.getLocation(), to.getLocation(), from.getEndTime(), DriverImpl.noDriver(), vehicle); }
private void setRouteEndToLastActivity(VehicleRoute route) { if (!route.getActivities().isEmpty()) { TourActivity lastAct = route.getActivities().get(route.getActivities().size() - 1); route.getEnd().setLocation(lastAct.getLocation()); } }
@Override public void visit(TourActivity activity) { for (Vehicle v : uniqueVehicles) { State old = states.get(v.getVehicleTypeIdentifier()); double distance = old.getDistance(); distance += transportDistance.getDistance(old.getPrevLocation(), activity.getLocation(), 0, v); stateManager.putActivityState(activity, v, traveledDistanceId, distance); states.put(v.getVehicleTypeIdentifier(), new State(activity.getLocation(), distance)); } }
@Override public void visit(TourActivity activity) { if (firstAct) { firstAct = false; if (!vehicle.isReturnToDepot()) { assert activity.getLocation().getId().equals(end.getLocation().getId()) : "route end and last activity are not equal even route is open. this should not be."; } } }
/** * 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); }
private double sample(VehicleRoutingTransportCosts costs, VehicleRoute r) { double min = Double.MAX_VALUE; double sum = 0; for (int i = 0; i < noDistanceSamples; i++) { TourActivity act1 = RandomUtils.nextItem(r.getActivities(), random); TourActivity act2 = RandomUtils.nextItem(r.getActivities(), random); double dist = costs.getTransportCost(act1.getLocation(), act2.getLocation(), 0., null, r.getVehicle()); if (dist < min) min = dist; sum += dist; } double avg = sum / ((double) noDistanceSamples); return (avg - min) * epsFactor; }
@Override public void visit(TourActivity activity) { double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocation(), prevAct.getLocation(), latestArrTimeAtPrevAct, route.getDriver(), route.getVehicle()) - activityCosts.getActivityDuration(activity,latestArrTimeAtPrevAct,route.getDriver(),route.getVehicle()); double latestArrivalTime = Math.min(activity.getTheoreticalLatestOperationStartTime(), potentialLatestArrivalTimeAtCurrAct); states.putInternalTypedActivityState(activity, InternalStates.LATEST_OPERATION_START_TIME, latestArrivalTime); latestArrTimeAtPrevAct = latestArrivalTime; prevAct = activity; }
@Override public void visit(TourActivity activity) { if (!beginFirst) throw new IllegalStateException("never called begin. this however is essential here"); double transportTime = this.transportTime.getTransportTime(prevAct.getLocation(), activity.getLocation(), startAtPrevAct, route.getDriver(), route.getVehicle()); double arrivalTimeAtCurrAct = startAtPrevAct + transportTime; actArrTime = arrivalTimeAtCurrAct; double operationStartTime; if (activityPolicy.equals(ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS)) { operationStartTime = Math.max(activity.getTheoreticalEarliestOperationStartTime(), arrivalTimeAtCurrAct); } else if (activityPolicy.equals(ActivityPolicy.AS_SOON_AS_ARRIVED)) { operationStartTime = actArrTime; } else operationStartTime = actArrTime; double operationEndTime = operationStartTime + activityCosts.getActivityDuration(activity,actArrTime,route.getDriver(),route.getVehicle()); actEndTime = operationEndTime; prevAct = activity; startAtPrevAct = operationEndTime; }
@Override public void visit(TourActivity currAct) { double timeOfNearestMessenger = bestMessengers.get(((JobActivity) currAct).getJob().getId()); double potential_latest_arrTime_at_currAct = latest_arrTime_at_prevAct - routingCosts.getBackwardTransportTime(currAct.getLocation(), prevAct.getLocation(), latest_arrTime_at_prevAct, route.getDriver(), route.getVehicle()) - currAct.getOperationTime(); double latest_arrTime_at_currAct = Math.min(3 * timeOfNearestMessenger, potential_latest_arrTime_at_currAct); stateManager.putActivityState(currAct, latest_act_arrival_time_stateId, latest_arrTime_at_currAct); assert currAct.getArrTime() <= latest_arrTime_at_currAct : "this must not be since it breaks condition; actArrTime: " + currAct.getArrTime() + " latestArrTime: " + latest_arrTime_at_currAct + " vehicle: " + route.getVehicle().getId(); latest_arrTime_at_prevAct = latest_arrTime_at_currAct; prevAct = currAct; }
@Override public void finish() { double transportTime = this.transportTime.getTransportTime(prevAct.getLocation(), route.getEnd().getLocation(), startAtPrevAct, route.getDriver(), route.getVehicle()); double arrivalTimeAtCurrAct = startAtPrevAct + transportTime; actArrTime = arrivalTimeAtCurrAct; actEndTime = arrivalTimeAtCurrAct; beginFirst = false; }
@Override public void visit(TourActivity act) { timeTracker.visit(act); double transportCost = this.transportCost.getTransportCost(prevAct.getLocation(), act.getLocation(), startTimeAtPrevAct, vehicleRoute.getDriver(), vehicleRoute.getVehicle()); double actCost = activityCost.getActivityCost(act, timeTracker.getActArrTime(), vehicleRoute.getDriver(), vehicleRoute.getVehicle()); totalOperationCost += transportCost; totalOperationCost += actCost; states.putInternalTypedActivityState(act, InternalStates.COSTS, totalOperationCost); prevAct = act; startTimeAtPrevAct = timeTracker.getActEndTime(); }
@Override public void finish() { double distance = distanceCalculator.getDistance(prevAct.getLocation(), route.getEnd().getLocation(),prevAct.getEndTime(), route.getVehicle()); sumDistance += distance; stateManager.putRouteState(route, distanceId, sumDistance); } }
public void visit(TourActivity activity) { for (Vehicle vehicle : vehicles) { double latestArrTimeAtPrevAct = latest_arrTimes_at_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()]; Location prevLocation = location_of_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()]; double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocation(), prevLocation, latestArrTimeAtPrevAct, route.getDriver(), vehicle) - activityCosts.getActivityDuration(activity, latestArrTimeAtPrevAct, route.getDriver(), route.getVehicle()); double latestArrivalTime = Math.min(activity.getTheoreticalLatestOperationStartTime(), potentialLatestArrivalTimeAtCurrAct); if (latestArrivalTime < activity.getTheoreticalEarliestOperationStartTime()) { stateManager.putTypedInternalRouteState(route, vehicle, InternalStates.SWITCH_NOT_FEASIBLE, true); } stateManager.putInternalTypedActivityState(activity, vehicle, InternalStates.LATEST_OPERATION_START_TIME, latestArrivalTime); latest_arrTimes_at_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = latestArrivalTime; location_of_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = activity.getLocation(); } }
@Override public void inform(Event event) { if (event instanceof InsertActivity) { InsertActivity insertActivity = (InsertActivity) event; if (!insertActivity.getNewVehicle().isReturnToDepot()) { if (insertActivity.getIndex() >= insertActivity.getVehicleRoute().getActivities().size()) { insertActivity.getVehicleRoute().getEnd().setLocation(insertActivity.getActivity().getLocation()); } } insertActivity.getVehicleRoute().getTourActivities().addActivity(insertActivity.getIndex(), ((InsertActivity) event).getActivity()); } }
@Override public void finish() { timeTracker.finish(); double transportCost = this.transportCost.getTransportCost(prevAct.getLocation(), vehicleRoute.getEnd().getLocation(), startTimeAtPrevAct, vehicleRoute.getDriver(), vehicleRoute.getVehicle()); double actCost = activityCost.getActivityCost(vehicleRoute.getEnd(), timeTracker.getActEndTime(), vehicleRoute.getDriver(), vehicleRoute.getVehicle()); totalOperationCost += transportCost; totalOperationCost += actCost; states.putTypedInternalRouteState(vehicleRoute, InternalStates.COSTS, totalOperationCost); startTimeAtPrevAct = 0.0; prevAct = null; vehicleRoute = null; totalOperationCost = 0.0; }