Class ConstraintManager
- All Implemented Interfaces:
Constraint,HardActivityConstraint,HardConstraint,HardRouteConstraint,SoftActivityConstraint,SoftConstraint,SoftRouteConstraint
- Author:
- schroeder
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface com.graphhopper.jsprit.core.problem.constraint.HardActivityConstraint
HardActivityConstraint.ConstraintsStatus -
Constructor Summary
ConstructorsConstructorDescriptionConstraintManager(VehicleRoutingProblem vrp, RouteAndActivityStateGetter stateManager) ConstraintManager(VehicleRoutingProblem vrp, RouteAndActivityStateGetter stateManager, Collection<Constraint> constraints) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddConstraint(HardActivityConstraint actLevelConstraint, ConstraintManager.Priority priority) voidaddConstraint(HardRouteConstraint routeLevelConstraint) voidaddConstraint(SoftActivityConstraint softActivityConstraint) voidaddConstraint(SoftRouteConstraint softRouteConstraint) voidvoidvoidbooleanfulfilled(JobInsertionContext insertionContext) Returns whether a job can be inserted in route.fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) Returns whether newAct can be inserted in between prevAct and nextAct.getActivityCostsBreakdown(JobInsertionContext context, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double depTime) Get activity-level soft constraint costs with breakdown by constraint.doublegetCosts(JobInsertionContext insertionContext) doublegetCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) getDependencyType(String jobId) Get route-level soft constraint costs with breakdown by constraint.Get all registered soft activity constraints.Get all registered soft route constraints.booleanvoidsetDependencyType(String jobId, DependencyType dependencyType)
-
Constructor Details
-
ConstraintManager
-
ConstraintManager
public ConstraintManager(VehicleRoutingProblem vrp, RouteAndActivityStateGetter stateManager, Collection<Constraint> constraints)
-
-
Method Details
-
hasHardActivityConstraints
public boolean hasHardActivityConstraints() -
getHardRouteConstraints
-
getCriticalHardActivityConstraints
-
getHighPrioHardActivityConstraints
-
getLowPrioHardActivityConstraints
-
getDependencyTypes
-
setDependencyType
-
getDependencyType
-
addTimeWindowConstraint
public void addTimeWindowConstraint() -
addLoadConstraint
public void addLoadConstraint() -
addSkillsConstraint
public void addSkillsConstraint() -
addConstraint
public void addConstraint(HardActivityConstraint actLevelConstraint, ConstraintManager.Priority priority) -
addConstraint
-
addConstraint
-
addConstraint
-
fulfilled
Description copied from interface:HardRouteConstraintReturns whether a job can be inserted in route.- Specified by:
fulfilledin interfaceHardRouteConstraint- Parameters:
insertionContext- provides context information about inserting a new job, i.e. the new job (insertionContext.getJob()), the route where the new job should be inserted (insertionContext.getRoute()), the new vehicle that should operate the route plus the new job (insertionContext.getNewVehicle()) and the new departure time at this vehicle's start location (insertionContext.getNewDepartureTime()).- Returns:
- true if constraint is met, false otherwise
-
fulfilled
public HardActivityConstraint.ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) Description copied from interface:HardActivityConstraintReturns whether newAct can be inserted in between prevAct and nextAct.When you check activities, you need to understand the following:
Let us assume an existing route;
start, ..., i-1, i, j, j+1, ..., end
When inserting a shipment, two activities will be inserted, pickupShipment k_pick and deliverShipment k_deliver, i.e. jsprit loops through this route (activity sequence) and checks hard and soft constraints and calculates (marginal) insertion costs. For the activity sequence above, it means:
start, k_pick, start+1 (prevAct, newAct, nextAct)
...
i-1, k_pick, i
i, k_pick, j
...
accordingly:
start, k_pick, k_delivery (prevAct, newAct, nextAct)
...
i-1, k_delivery, i
i, k_delivery, j
...
You specify a hard activity constraint, you to check whether for example k_pick can be inserted between prevActivity and nextActivity at all. If so, your hard constraint should return ConstraintsStatus.FULFILLED.
If not, you can return ConstraintsStatus.NOT_FULFILLED or ConstraintsStatus.NOT_FULFILLED_BREAK.
Latter should be used, if your constraint can never be fulfilled anymore when looping further through your route.
Since constraint checking at activity level is rather time consuming (you need to do this thousand/millions times), you can memorize states behind activities to avoid additional loopings through your activity sequence and thus to check your constraint locally (only by looking at prevAct, newAct, nextAct) in constant time.
- Specified by:
fulfilledin interfaceHardActivityConstraint- Parameters:
iFacts- JobInsertionContext provides additional information that might be important when evaluating the insertion of newActprevAct- the previous activity, i.e. the activity before the new activitynewAct- the new activity to be inserted in between prevAct and nextActnextAct- the next activity, i.e. the activity after the new activityprevActDepTime- the departure time at previous activity (prevAct) with the new vehicle (iFacts.getNewVehicle())- Returns:
- fulfilled if hard constraint is met, other not fulfilled.
-
getConstraints
-
getSoftRouteConstraints
Get all registered soft route constraints. These influence insertion decisions at the route level (e.g., which route to insert into). -
getSoftActivityConstraints
Get all registered soft activity constraints. These influence insertion decisions at the activity level (e.g., where in the route to insert). -
getRouteCostsBreakdown
Get route-level soft constraint costs with breakdown by constraint.- Parameters:
context- The job insertion context- Returns:
- Breakdown of costs per constraint
-
getActivityCostsBreakdown
public InsertionCostBreakdown getActivityCostsBreakdown(JobInsertionContext context, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double depTime) Get activity-level soft constraint costs with breakdown by constraint.- Parameters:
context- The job insertion contextprevAct- Previous activitynewAct- New activity being insertednextAct- Next activitydepTime- Departure time at previous activity- Returns:
- Breakdown of costs per constraint
-
getCosts
- Specified by:
getCostsin interfaceSoftRouteConstraint
-
getCosts
public double getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) - Specified by:
getCostsin interfaceSoftActivityConstraint
-