Class ShipmentPickupsFirstConstraint

java.lang.Object
com.graphhopper.jsprit.core.problem.constraint.ShipmentPickupsFirstConstraint
All Implemented Interfaces:
Constraint, HardActivityConstraint, HardConstraint

public class ShipmentPickupsFirstConstraint extends Object implements HardActivityConstraint
  • Constructor Details

    • ShipmentPickupsFirstConstraint

      public ShipmentPickupsFirstConstraint()
  • Method Details

    • 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.