From ca26171548141160b40ba92a3d54bfc6ce5ff6a3 Mon Sep 17 00:00:00 2001 From: oblonski Date: Thu, 4 Feb 2016 11:08:35 +0100 Subject: [PATCH] make service time dependent on vehicle - #199 --- .../recreate/BreakInsertionCalculator.java | 4 ++-- .../JobInsertionCostsCalculatorBuilder.java | 2 +- .../recreate/ShipmentInsertionCalculator.java | 13 ++++++++----- .../recreate/VariableTransportCostCalculator.java | 1 - .../UpdateVehicleDependentPracticalTimeWindows.java | 1 + .../jsprit/core/analysis/SolutionAnalyser.java | 3 ++- .../constraint/AdditionalTransportationCosts.java | 2 +- .../VehicleDependentTimeWindowConstraints.java | 2 +- .../jsprit/core/util/ActivityTimeTracker.java | 3 ++- .../state/UpdatePracticalTimeWindowTest.java | 2 ++ .../state/UpdateVehicleDependentTimeWindowTest.java | 2 +- ...eWindowWithStartTimeAndMaxOperationTimeTest.java | 2 ++ 12 files changed, 23 insertions(+), 14 deletions(-) diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/BreakInsertionCalculator.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/BreakInsertionCalculator.java index 961f4159..0d0e2408 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/BreakInsertionCalculator.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/BreakInsertionCalculator.java @@ -20,6 +20,7 @@ import com.graphhopper.jsprit.core.problem.JobActivityFactory; import com.graphhopper.jsprit.core.problem.Location; import com.graphhopper.jsprit.core.problem.constraint.*; import com.graphhopper.jsprit.core.problem.constraint.HardActivityConstraint.ConstraintsStatus; +import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingActivityCosts; import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingTransportCosts; import com.graphhopper.jsprit.core.problem.driver.Driver; import com.graphhopper.jsprit.core.problem.job.Break; @@ -31,7 +32,6 @@ import com.graphhopper.jsprit.core.problem.solution.route.activity.End; import com.graphhopper.jsprit.core.problem.solution.route.activity.Start; import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity; import com.graphhopper.jsprit.core.problem.vehicle.Vehicle; -import com.graphhopper.jsprit.core.util.CalculationUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -40,7 +40,7 @@ import java.util.Iterator; import java.util.List; /** - * Calculator that calculates the best insertion position for a {@link jsprit.core.problem.job.Service}. + * Calculator that calculates the best insertion position for a service. * * @author schroeder */ diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/JobInsertionCostsCalculatorBuilder.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/JobInsertionCostsCalculatorBuilder.java index 0886aecf..93f4e929 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/JobInsertionCostsCalculatorBuilder.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/JobInsertionCostsCalculatorBuilder.java @@ -286,7 +286,7 @@ public class JobInsertionCostsCalculatorBuilder { } }; - ShipmentInsertionCalculator shipmentInsertion = new ShipmentInsertionCalculator(vrp.getTransportCosts(), vrp.getActivityCosts(), actInsertionCalc, constraintManager); + ShipmentInsertionCalculator shipmentInsertion = new ShipmentInsertionCalculator(vrp.getTransportCosts(), vrp.getActivityCosts(),actInsertionCalc, constraintManager); shipmentInsertion.setJobActivityFactory(activityFactory); ServiceInsertionCalculator serviceInsertion = new ServiceInsertionCalculator(vrp.getTransportCosts(), vrp.getActivityCosts(), actInsertionCalc, constraintManager); serviceInsertion.setJobActivityFactory(activityFactory); diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/ShipmentInsertionCalculator.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/ShipmentInsertionCalculator.java index 0c35524c..631ab5c6 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/ShipmentInsertionCalculator.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/ShipmentInsertionCalculator.java @@ -19,6 +19,7 @@ package com.graphhopper.jsprit.core.algorithm.recreate; import com.graphhopper.jsprit.core.problem.JobActivityFactory; import com.graphhopper.jsprit.core.problem.constraint.*; import com.graphhopper.jsprit.core.problem.constraint.HardActivityConstraint.ConstraintsStatus; +import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingActivityCosts; import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingTransportCosts; import com.graphhopper.jsprit.core.problem.driver.Driver; import com.graphhopper.jsprit.core.problem.job.Job; @@ -31,7 +32,6 @@ import com.graphhopper.jsprit.core.problem.solution.route.activity.Start; import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow; import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity; import com.graphhopper.jsprit.core.problem.vehicle.Vehicle; -import com.graphhopper.jsprit.core.util.CalculationUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -54,11 +54,13 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator { private VehicleRoutingTransportCosts transportCosts; + private VehicleRoutingActivityCosts activityCosts; + private JobActivityFactory activityFactory; private AdditionalAccessEgressCalculator additionalAccessEgressCalculator; - public ShipmentInsertionCalculator(VehicleRoutingTransportCosts routingCosts, ActivityInsertionCostsCalculator activityInsertionCostsCalculator, ConstraintManager constraintManager) { + public ShipmentInsertionCalculator(VehicleRoutingTransportCosts routingCosts, VehicleRoutingActivityCosts activityCosts, ActivityInsertionCostsCalculator activityInsertionCostsCalculator, ConstraintManager constraintManager) { super(); this.activityInsertionCostsCalculator = activityInsertionCostsCalculator; this.hardRouteLevelConstraint = constraintManager; @@ -66,6 +68,7 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator { this.softActivityConstraint = constraintManager; this.softRouteConstraint = constraintManager; this.transportCosts = routingCosts; + this.activityCosts = activityCosts; additionalAccessEgressCalculator = new AdditionalAccessEgressCalculator(routingCosts); logger.debug("initialise {}", this); } @@ -159,7 +162,7 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator { TourActivity prevAct_deliveryLoop = pickupShipment; double shipmentPickupArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocation(), pickupShipment.getLocation(), prevActEndTime, newDriver, newVehicle); - double shipmentPickupEndTime = CalculationUtils.getActivityEndTime(shipmentPickupArrTime, pickupShipment); + double shipmentPickupEndTime = Math.max(shipmentPickupArrTime, pickupShipment.getTheoreticalEarliestOperationStartTime()) + activityCosts.getActivityDuration(pickupShipment, shipmentPickupArrTime, newDriver, newVehicle); pickupContext.setArrivalTime(shipmentPickupArrTime); pickupContext.setEndTime(shipmentPickupEndTime); @@ -211,7 +214,7 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator { if (deliveryInsertionNotFulfilledBreak) break; //update prevAct and endTime double nextActArrTime = prevActEndTime_deliveryLoop + transportCosts.getTransportTime(prevAct_deliveryLoop.getLocation(), nextAct_deliveryLoop.getLocation(), prevActEndTime_deliveryLoop, newDriver, newVehicle); - prevActEndTime_deliveryLoop = CalculationUtils.getActivityEndTime(nextActArrTime, nextAct_deliveryLoop); + prevActEndTime_deliveryLoop = Math.max(nextActArrTime, nextAct_deliveryLoop.getTheoreticalEarliestOperationStartTime()) + activityCosts.getActivityDuration(nextAct_deliveryLoop,nextActArrTime,newDriver,newVehicle); prevAct_deliveryLoop = nextAct_deliveryLoop; j++; } @@ -221,7 +224,7 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator { } //update prevAct and endTime double nextActArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActEndTime, newDriver, newVehicle); - prevActEndTime = CalculationUtils.getActivityEndTime(nextActArrTime, nextAct); + prevActEndTime = Math.max(nextActArrTime, nextAct.getTheoreticalEarliestOperationStartTime()) + activityCosts.getActivityDuration(nextAct,nextActArrTime,newDriver,newVehicle); prevAct = nextAct; i++; } diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/VariableTransportCostCalculator.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/VariableTransportCostCalculator.java index 1d7415c8..dcf32d45 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/VariableTransportCostCalculator.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/VariableTransportCostCalculator.java @@ -22,7 +22,6 @@ import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingTransportCosts; import com.graphhopper.jsprit.core.problem.misc.JobInsertionContext; import com.graphhopper.jsprit.core.problem.solution.route.activity.End; import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity; -import com.graphhopper.jsprit.core.util.CalculationUtils; public class VariableTransportCostCalculator implements SoftActivityConstraint { diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/state/UpdateVehicleDependentPracticalTimeWindows.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/state/UpdateVehicleDependentPracticalTimeWindows.java index f15c9393..ac67a969 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/state/UpdateVehicleDependentPracticalTimeWindows.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/state/UpdateVehicleDependentPracticalTimeWindows.java @@ -18,6 +18,7 @@ package com.graphhopper.jsprit.core.algorithm.state; import com.graphhopper.jsprit.core.problem.Location; +import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingActivityCosts; import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingTransportCosts; import com.graphhopper.jsprit.core.problem.solution.route.RouteVisitor; import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute; diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/analysis/SolutionAnalyser.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/analysis/SolutionAnalyser.java index cc442a0f..a3c6f024 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/analysis/SolutionAnalyser.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/analysis/SolutionAnalyser.java @@ -23,6 +23,7 @@ import com.graphhopper.jsprit.core.problem.Capacity; import com.graphhopper.jsprit.core.problem.Location; import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem; import com.graphhopper.jsprit.core.problem.cost.TransportDistance; +import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingActivityCosts; import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingTransportCosts; import com.graphhopper.jsprit.core.problem.solution.SolutionCostCalculator; import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution; @@ -283,7 +284,7 @@ public class SolutionAnalyser { sum_transport_time += transportTime; prevActDeparture = activity.getEndTime(); //service time - sum_service_time += activityCosts.getActivityDuration(activity,activity.getArrTime(),route.getDriver(),route.getVehicle()); + sum_service_time += activityCosts.getActivityDuration(activity, activity.getArrTime(), route.getDriver(), route.getVehicle()); stateManager.putActivityState(activity, transport_time_id, sum_transport_time); diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/constraint/AdditionalTransportationCosts.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/constraint/AdditionalTransportationCosts.java index ea739af4..8b17bce3 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/constraint/AdditionalTransportationCosts.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/constraint/AdditionalTransportationCosts.java @@ -16,11 +16,11 @@ ******************************************************************************/ package com.graphhopper.jsprit.core.problem.constraint; +import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingActivityCosts; import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingTransportCosts; import com.graphhopper.jsprit.core.problem.misc.JobInsertionContext; import com.graphhopper.jsprit.core.problem.solution.route.activity.End; import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity; -import com.graphhopper.jsprit.core.util.CalculationUtils; /** * Calculates additional transportation costs induced by inserting newAct. diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/constraint/VehicleDependentTimeWindowConstraints.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/constraint/VehicleDependentTimeWindowConstraints.java index a7f450b0..6c947114 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/constraint/VehicleDependentTimeWindowConstraints.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/constraint/VehicleDependentTimeWindowConstraints.java @@ -19,12 +19,12 @@ package com.graphhopper.jsprit.core.problem.constraint; import com.graphhopper.jsprit.core.algorithm.state.InternalStates; import com.graphhopper.jsprit.core.problem.Location; +import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingActivityCosts; import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingTransportCosts; import com.graphhopper.jsprit.core.problem.misc.JobInsertionContext; import com.graphhopper.jsprit.core.problem.solution.route.activity.End; import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity; import com.graphhopper.jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter; -import com.graphhopper.jsprit.core.util.CalculationUtils; /** diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/util/ActivityTimeTracker.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/util/ActivityTimeTracker.java index 079e8fc3..55934191 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/util/ActivityTimeTracker.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/util/ActivityTimeTracker.java @@ -19,7 +19,8 @@ package com.graphhopper.jsprit.core.util; import com.graphhopper.jsprit.core.problem.cost.ForwardTransportTime; import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingActivityCosts; import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute; -import com.graphhopper.jsprit.core.problem.solution.route.activity.*; +import com.graphhopper.jsprit.core.problem.solution.route.activity.ActivityVisitor; +import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity; public class ActivityTimeTracker implements ActivityVisitor { diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/state/UpdatePracticalTimeWindowTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/state/UpdatePracticalTimeWindowTest.java index 7d602bae..2b6bdd49 100644 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/state/UpdatePracticalTimeWindowTest.java +++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/state/UpdatePracticalTimeWindowTest.java @@ -22,7 +22,9 @@ import com.graphhopper.jsprit.core.problem.AbstractActivity; import com.graphhopper.jsprit.core.problem.JobActivityFactory; import com.graphhopper.jsprit.core.problem.Location; import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem; +import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingActivityCosts; import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingTransportCosts; +import com.graphhopper.jsprit.core.problem.cost.WaitingTimeCosts; import com.graphhopper.jsprit.core.problem.driver.Driver; import com.graphhopper.jsprit.core.problem.job.Delivery; import com.graphhopper.jsprit.core.problem.job.Job; diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/state/UpdateVehicleDependentTimeWindowTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/state/UpdateVehicleDependentTimeWindowTest.java index 223487c4..93a62f5e 100644 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/state/UpdateVehicleDependentTimeWindowTest.java +++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/state/UpdateVehicleDependentTimeWindowTest.java @@ -201,7 +201,7 @@ public class UpdateVehicleDependentTimeWindowTest { .addService(service).addService(service2, TimeWindow.newInstance(70, 80)).build(); StateManager stateManager = new StateManager(vrp); - UpdateVehicleDependentPracticalTimeWindows updater = new UpdateVehicleDependentPracticalTimeWindows(stateManager,routingCosts); + UpdateVehicleDependentPracticalTimeWindows updater = new UpdateVehicleDependentPracticalTimeWindows(stateManager,routingCosts,activityCosts); updater.setVehiclesToUpdate(new UpdateVehicleDependentPracticalTimeWindows.VehiclesToUpdate() { @Override diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/constraint/VehicleDependentTimeWindowWithStartTimeAndMaxOperationTimeTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/constraint/VehicleDependentTimeWindowWithStartTimeAndMaxOperationTimeTest.java index 654ecee0..62b4de34 100644 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/constraint/VehicleDependentTimeWindowWithStartTimeAndMaxOperationTimeTest.java +++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/constraint/VehicleDependentTimeWindowWithStartTimeAndMaxOperationTimeTest.java @@ -22,7 +22,9 @@ import com.graphhopper.jsprit.core.algorithm.state.StateManager; import com.graphhopper.jsprit.core.algorithm.state.UpdateActivityTimes; import com.graphhopper.jsprit.core.algorithm.state.UpdateVehicleDependentPracticalTimeWindows; import com.graphhopper.jsprit.core.problem.*; +import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingActivityCosts; import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingTransportCosts; +import com.graphhopper.jsprit.core.problem.cost.WaitingTimeCosts; import com.graphhopper.jsprit.core.problem.job.Job; import com.graphhopper.jsprit.core.problem.job.Service; import com.graphhopper.jsprit.core.problem.misc.JobInsertionContext;