VRP pinned entities

22 views
Skip to first unread message

Maiko Metsalu

unread,
Nov 2, 2022, 7:22:44 AM11/2/22
to OptaPlanner development
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. 

Lukáš Petrovický

unread,
Nov 2, 2022, 7:36:12 AM11/2/22
to optapla...@googlegroups.com
Hey there,

On Wed, Nov 2, 2022 at 12:22 PM Maiko Metsalu <mets...@gmail.com> wrote:
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. 

at the moment, planning list variable does not support pinning; it is still a new feature, and these advanced use cases are yet to be delivered. So, for the time being, you are on your own in implementing this in your domain. The approach you've outlined should work. 

--

Lukáš Petrovický

OptaPlanner Project Lead

lukas.pe...@redhat.com

My work week is Monday to Thursday.
No need to respond outside of your working hours.
Reply all
Reply to author
Forward
0 new messages