@Override public InsertionData getInsertionData( final VehicleRoute currentRoute, final Job jobToInsert, final Vehicle newVehicle, double newVehicleDepartureTime, final Driver newDriver, final double bestKnownPrice) { double fixcost_contribution = getFixCostContribution(currentRoute, jobToInsert, newVehicle); if (fixcost_contribution > bestKnownPrice) { return InsertionData.createEmptyInsertionData(); } InsertionData iData = standardServiceInsertion.getInsertionData( currentRoute, jobToInsert, newVehicle, newVehicleDepartureTime, newDriver, bestKnownPrice); if (iData instanceof NoInsertionFound) { return iData; } double totalInsertionCost = iData.getInsertionCost() + fixcost_contribution; InsertionData insertionData = new InsertionData( totalInsertionCost, iData.getPickupInsertionIndex(), iData.getDeliveryInsertionIndex(), newVehicle, newDriver); insertionData.setVehicleDepartureTime(newVehicleDepartureTime); insertionData.getEvents().addAll(iData.getEvents()); return insertionData; }
private double scoreService(InsertionData best, Job job) { double maxDepotDistance = Math.max( getDistance( best.getSelectedVehicle().getStartLocation(), ((Service) job).getLocation()), getDistance( best.getSelectedVehicle().getEndLocation(), ((Service) job).getLocation())); return Math.max( tw_param * (((Service) job).getTimeWindow().getEnd() - ((Service) job).getTimeWindow().getStart()), minTimeWindowScore) + depotDistance_param * maxDepotDistance; }
@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 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(tw_param * minTimeToOperate, minTimeWindowScore) + depotDistance_param * maxDepotDistance; }
static double score( Job unassignedJob, InsertionData best, InsertionData secondBest, ScoringFunction scoringFunction) { if (best == null) { throw new IllegalStateException("cannot insert job " + unassignedJob.getId()); } double score; if (secondBest == null) { // either there is only one vehicle or there are more vehicles, but they cannot // load unassignedJob // if only one vehicle, I want the job to be inserted with min iCosts // if there are more vehicles, I want this job to be prioritized since there are no // alternatives score = Integer.MAX_VALUE - best.getInsertionCost() + scoringFunction.score(best, unassignedJob); } else { score = (secondBest.getInsertionCost() - best.getInsertionCost()) + scoringFunction.score(best, unassignedJob); } return score; }
public void insertJob(Job job, InsertionData insertionData, VehicleRoute vehicleRoute) { insertionListeners.informBeforeJobInsertion(job, insertionData, vehicleRoute); if (insertionData == null || (insertionData instanceof NoInsertionFound)) throw new IllegalStateException("insertionData null. cannot insert job."); if (job == null) throw new IllegalStateException("cannot insert null-job"); if (!(vehicleRoute.getVehicle().getId().equals(insertionData.getSelectedVehicle().getId()))) { insertionListeners.informVehicleSwitched( vehicleRoute, vehicleRoute.getVehicle(), insertionData.getSelectedVehicle()); vehicleRoute.setVehicleAndDepartureTime( insertionData.getSelectedVehicle(), insertionData.getVehicleDepartureTime()); } jobInsertionHandler.handleJobInsertion(job, insertionData, vehicleRoute); insertionListeners.informJobInserted( job, vehicleRoute, insertionData.getInsertionCost(), insertionData.getAdditionalTime()); }
@Override public void handleJobInsertion(Job job, InsertionData iData, VehicleRoute route) { if (job instanceof Shipment) { List<AbstractActivity> acts = vehicleRoutingProblem.copyAndGetActivities(job); TourActivity pickupShipment = acts.get(0); TourActivity deliverShipment = acts.get(1); route.setVehicleAndDepartureTime( iData.getSelectedVehicle(), iData.getVehicleDepartureTime()); if (!iData.getSelectedVehicle().isReturnToDepot()) { if (iData.getDeliveryInsertionIndex() >= route.getActivities().size()) { setEndLocation(route, (Shipment) job); } } route.getTourActivities().addActivity(iData.getDeliveryInsertionIndex(), deliverShipment); route.getTourActivities().addActivity(iData.getPickupInsertionIndex(), pickupShipment); } else delegator.handleJobInsertion(job, iData, route); }
static ScoredJob getScoredJob( Collection<VehicleRoute> routes, Job unassignedJob, JobInsertionCostsCalculator insertionCostsCalculator, ScoringFunction scoringFunction) { InsertionData best = null; InsertionData secondBest = null; VehicleRoute bestRoute = null; double benchmark = Double.MAX_VALUE; for (VehicleRoute route : routes) { if (secondBest != null) { benchmark = secondBest.getInsertionCost(); } InsertionData iData = insertionCostsCalculator.getInsertionData( route, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, benchmark); if (iData instanceof InsertionData.NoInsertionFound) continue; if (best == null) { best = iData; bestRoute = route; } else if (iData.getInsertionCost() < best.getInsertionCost()) { secondBest = best; best = iData; bestRoute = route; } else if (secondBest == null || (iData.getInsertionCost() < secondBest.getInsertionCost())) { secondBest = iData; } } VehicleRoute emptyRoute = VehicleRoute.emptyRoute(); InsertionData iData = insertionCostsCalculator.getInsertionData( emptyRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, benchmark); if (!(iData instanceof InsertionData.NoInsertionFound)) { if (best == null) { best = iData; bestRoute = emptyRoute; } else if (iData.getInsertionCost() < best.getInsertionCost()) { secondBest = best; best = iData; bestRoute = emptyRoute; } else if (secondBest == null || (iData.getInsertionCost() < secondBest.getInsertionCost())) { secondBest = iData; } } if (best == null) { return new RegretInsertion.BadJob(unassignedJob); } double score = score(unassignedJob, best, secondBest, scoringFunction); ScoredJob scoredJob; if (bestRoute == emptyRoute) { scoredJob = new ScoredJob(unassignedJob, score, best, bestRoute, true); } else scoredJob = new ScoredJob(unassignedJob, score, best, bestRoute, false); return scoredJob; }