Hard Constraint for pickup from vehicle's depot

Hi everyone,

I am trying to add a hard constraint such that a pickup is performed only if the vehicle’s start location and pickup’s location are the same. In short, every vehicle performs pickups only from its start location. I added a hard constraint as shown in the code.

public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {

    if(newAct instanceof PickupShipment) {

        if (newAct.getLocation().getId().equals(iFacts.getNewVehicle().getStartLocation().getId()))
            return HardActivityConstraint.ConstraintsStatus.FULFILLED;
        else
            return HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED;
   }

    return HardActivityConstraint.ConstraintsStatus.FULFILLED;
}

This somehow does not take the constraint into consideration. Can I know what could be the reason?

Thanks in advance :slight_smile:

Hi,

Jsprit switches vehicle during route building phase. Hence this constraint will be true during insertion of of a activity but might be violated during insertion of next activity (Due to vehicle switching)

You can disable vehicle switching by

Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.VEHICLE_SWITCH, "False");

Or make sure start Location of new vehicle is same as start location of existing vehicle.
if(!(iFacts.getRoute().getVehicle() instanceof VehicleImpl.NoVehicle) && !iFacts.getRoute().isEmpty()){ iFacts.getNewVehicle().getStartLocation().equals(iFacts.getRoute().getVehicle().getStartLocation()); }

1 Like

Thanks Bhoumik. I get it now.
Solved my concern :slight_smile:
Cheers!

1 Like

Solved similar problem using skills. I mean setting skill on vehicles in particular depot and required skills at corresponding jobs to specific depot id

1 Like