Hello!
Me and our team are currently trying to figure out the best way to implement pinned visits to our custom vehicle routing problem.
Our model is the following:
We have a Vehicle model that has a @PlanningListVariable List<Visit>
@PlanningListVariable(valueRangeProviderRefs = "visitRange")
protected List<Visit> visits = new ArrayList<>();
So each vehicle has a List of Visit objects that they need to serve. These Visit objects also hold a reference to the current vehicle they have been assigned:
@InverseRelationShadowVariable(sourceVariableName = "visits")
public Vehicle getVehicle() {
return vehicle;
}
Currently, we are just providing Visits to the solver which have no vehicle assigned, but we would like to somehow 'pin' some Visit objects to a certain Vehicle.
We tried using OptaPlanners @PlanningPin solution, but as we understood, this is only applied to @PlanningVariable variables, but the Visit objects themselves do not have any @PlanningVariables, but instead, Vehicle objects have a @PlanningListVariable.
The problem is, we do not want to pin down the whole Visit list of a Vehicle, but rather that if the Vehicle already has a list of Visit objects, we want those Visit objects not to be assigned to another Vehicle.
Is there any way of doing it as such that we can pin certain Visit objects to our Vehicle?
Currently, our workaround would be to create a new variable "originalVehicle" to the Visit and create a new HARD Constraint that will check if the Vehicle of the Visit has been changed to something else than the "originalVehicle", but we feel like this is not good for our engine's performance and if there's some out of the box way to do it in a better way then we should use that instead.