From 8ec2e7459af426e9d45ab508c2cb9298f1bbf147 Mon Sep 17 00:00:00 2001 From: oblonski <4sschroeder@gmail.com> Date: Mon, 2 Jun 2014 12:18:25 +0200 Subject: [PATCH] added internal doc --- .../constraint/TimeWindowConstraint.java | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/jsprit-core/src/main/java/jsprit/core/problem/constraint/TimeWindowConstraint.java b/jsprit-core/src/main/java/jsprit/core/problem/constraint/TimeWindowConstraint.java index 982b4f97..87d7ed47 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/constraint/TimeWindowConstraint.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/constraint/TimeWindowConstraint.java @@ -28,25 +28,53 @@ import jsprit.core.util.CalculationUtils; @Override public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { double latestVehicleArrival = iFacts.getNewVehicle().getLatestArrival(); + /* + * if latest arrival of vehicle (at its end) is smaller than earliest operation start times of activities, + * then vehicle can never conduct activities. + * + * |--- vehicle's operation time ---| + * |--- prevAct or newAct or nextAct ---| + */ if(latestVehicleArrival < prevAct.getTheoreticalEarliestOperationStartTime() || latestVehicleArrival < newAct.getTheoreticalEarliestOperationStartTime() || latestVehicleArrival < nextAct.getTheoreticalEarliestOperationStartTime()){ return ConstraintsStatus.NOT_FULFILLED_BREAK; } + /* + * if the latest operation start-time of new activity is smaller than the earliest start of prev. activity, + * then + * + * |--- prevAct ---| + * |--- newAct ---| + */ if(newAct.getTheoreticalLatestOperationStartTime() < prevAct.getTheoreticalEarliestOperationStartTime()){ return ConstraintsStatus.NOT_FULFILLED_BREAK; } + + /* + * |--- prevAct ---| + * |- earliest arrival of vehicle + * |--- nextAct ---| + */ double arrTimeAtNextOnDirectRouteWithNewVehicle = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocationId(), nextAct.getLocationId(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle()); if(arrTimeAtNextOnDirectRouteWithNewVehicle > nextAct.getTheoreticalLatestOperationStartTime()){ return ConstraintsStatus.NOT_FULFILLED_BREAK; } + /* + * |--- newAct ---| + * |--- nextAct ---| + */ if(newAct.getTheoreticalEarliestOperationStartTime() > nextAct.getTheoreticalLatestOperationStartTime()){ return ConstraintsStatus.NOT_FULFILLED; } // log.info("check insertion of " + newAct + " between " + prevAct + " and " + nextAct + ". prevActDepTime=" + prevActDepTime); double arrTimeAtNewAct = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocationId(), newAct.getLocationId(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle()); double latestArrTimeAtNewAct = states.getActivityState(newAct, StateFactory.LATEST_OPERATION_START_TIME, Double.class); - + /* + * |--- prevAct ---| + * |--- vehicle's arrival @newAct + * latest arrival of vehicle @newAct ---| + */ if(arrTimeAtNewAct > latestArrTimeAtNewAct){ return ConstraintsStatus.NOT_FULFILLED; } @@ -54,9 +82,15 @@ import jsprit.core.util.CalculationUtils; double endTimeAtNewAct = CalculationUtils.getActivityEndTime(arrTimeAtNewAct, newAct); double arrTimeAtNextAct = endTimeAtNewAct + routingCosts.getTransportTime(newAct.getLocationId(), nextAct.getLocationId(), endTimeAtNewAct, iFacts.getNewDriver(), iFacts.getNewVehicle()); double latestArrTimeAtNextAct = states.getActivityState(nextAct, StateFactory.LATEST_OPERATION_START_TIME, Double.class); + /* + * |--- newAct ---| + * |--- vehicle's arrival @nextAct + * latest arrival of vehicle @nextAct ---| + */ if(arrTimeAtNextAct > latestArrTimeAtNextAct){ return ConstraintsStatus.NOT_FULFILLED; } + // if vehicle cannot even manage direct-route - break if(arrTimeAtNextOnDirectRouteWithNewVehicle > latestArrTimeAtNextAct){ return ConstraintsStatus.NOT_FULFILLED_BREAK;