When overriding the getCosts method implementing a soft route constraint, how do I know if the current job retrieved by getJob() from the JobsInsertionContext object is the Pickup or Delivery of a shipment? Do I have to parse the context route and check if there is a pickup for the given shipment inside the route object? Is there a better/lighter way get this information?
They might want to reduce the usages of instanceof (Job/Activity refactor (general discussion)) but currently the code has a lot of those usages.
Thanks for the answer.
The doubt I have is when the soft route constraint is being evaluated for a shipment, how do I know if it is being evaluated for the pickup or the delivery part. Getting the current job from the insertionContext returns a Shipment from core.problem.job which contains both the pickup and delivery address but doesn’t specify which part is in question (delivery or pickup) unlike when evaluating activities from route coming from com.graphhopper.jsprit.core.problem.solution.route.activity, in which that is clear from having DeliverShipment and PickupShipment instances. Maybe I am getting this wrong and I am using the wrong kind of constraint for evaluating them separately.
A route constraint evaluates what happens if a specified job is inserted into an existing route (along with a specified vehicle), so basically it does not go to the activity level of the job.
If you look at the shipment insertion calculator, you will see that the soft route constraints are checked before it goes into the activity level loops.
If you want to evaluate at the activity level, you should use an activity constraint, and there you can use instanceof on the newAct to check whether it is a DeliverShipment or PickupShipment.