Class ConstraintManager

java.lang.Object
com.graphhopper.jsprit.core.problem.constraint.ConstraintManager
All Implemented Interfaces:
Constraint, HardActivityConstraint, HardConstraint, HardRouteConstraint, SoftActivityConstraint, SoftConstraint, SoftRouteConstraint

Manager that manage hard- and soft constraints, both on route and activity level.
Author:
schroeder
  • Constructor Details

  • Method Details

    • hasHardActivityConstraints

      public boolean hasHardActivityConstraints()
    • getHardRouteConstraints

      public Collection<HardRouteConstraint> getHardRouteConstraints()
    • getCriticalHardActivityConstraints

      public Collection<HardActivityConstraint> getCriticalHardActivityConstraints()
    • getHighPrioHardActivityConstraints

      public Collection<HardActivityConstraint> getHighPrioHardActivityConstraints()
    • getLowPrioHardActivityConstraints

      public Collection<HardActivityConstraint> getLowPrioHardActivityConstraints()
    • getDependencyTypes

      public DependencyType[] getDependencyTypes()
    • setDependencyType

      public void setDependencyType(String jobId, DependencyType dependencyType)
    • getDependencyType

      public DependencyType getDependencyType(String jobId)
    • addTimeWindowConstraint

      public void addTimeWindowConstraint()
    • addLoadConstraint

      public void addLoadConstraint()
    • addSkillsConstraint

      public void addSkillsConstraint()
    • addConstraint

      public void addConstraint(HardActivityConstraint actLevelConstraint, ConstraintManager.Priority priority)
    • addConstraint

      public void addConstraint(HardRouteConstraint routeLevelConstraint)
    • addConstraint

      public void addConstraint(SoftActivityConstraint softActivityConstraint)
    • addConstraint

      public void addConstraint(SoftRouteConstraint softRouteConstraint)
    • fulfilled

      public boolean fulfilled(JobInsertionContext insertionContext)
      Description copied from interface: HardRouteConstraint
      Returns whether a job can be inserted in route.
      Specified by:
      fulfilled in interface HardRouteConstraint
      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: HardActivityConstraint
      Returns 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:
      fulfilled in interface HardActivityConstraint
      Parameters:
      iFacts - JobInsertionContext provides additional information that might be important when evaluating the insertion of newAct
      prevAct - the previous activity, i.e. the activity before the new activity
      newAct - the new activity to be inserted in between prevAct and nextAct
      nextAct - the next activity, i.e. the activity after the new activity
      prevActDepTime - the departure time at previous activity (prevAct) with the new vehicle (iFacts.getNewVehicle())
      Returns:
      fulfilled if hard constraint is met, other not fulfilled.
    • getConstraints

      public Collection<Constraint> getConstraints()
    • getSoftRouteConstraints

      public Collection<SoftRouteConstraint> getSoftRouteConstraints()
      Get all registered soft route constraints. These influence insertion decisions at the route level (e.g., which route to insert into).
    • getSoftActivityConstraints

      public Collection<SoftActivityConstraint> getSoftActivityConstraints()
      Get all registered soft activity constraints. These influence insertion decisions at the activity level (e.g., where in the route to insert).
    • getRouteCostsBreakdown

      public InsertionCostBreakdown getRouteCostsBreakdown(JobInsertionContext context)
      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 context
      prevAct - Previous activity
      newAct - New activity being inserted
      nextAct - Next activity
      depTime - Departure time at previous activity
      Returns:
      Breakdown of costs per constraint
    • getCosts

      public double getCosts(JobInsertionContext insertionContext)
      Specified by:
      getCosts in interface SoftRouteConstraint
    • getCosts

      public double getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime)
      Specified by:
      getCosts in interface SoftActivityConstraint