How to make AddSoftSameVehicleConstraint() trigger penalty when one node is dropped? #4883
Unanswered
zeldaxlove64
asked this question in
Routing (and legacy CP) questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
With
routing.AddSoftSameVehicleConstraint([index1, index2], penalty)I noticed that if one of the nodes is dropped (i.e., not assigned to any vehicle), the penalty does not get applied.
In other words:
What I want to achieve is:
The penalty should also apply when the two nodes are not on the same vehicle, including when one or two of them is dropped.
Is there any built-in way or parameter to make AddSoftSameVehicleConstraint behave like that?
Or do I need to manually add a custom constraint using solver().Add() to model this logic?
Any hints or recommended approaches would be greatly appreciated.
Supplementary Notes:
From the perspective of real business requirements, in my use case, there may be LAYOVER or NEARBY relationships between tasks. Both of these relationships tend to encourage assigning the related tasks to the same person. Each relationship has its own WEIGHT, which affects the penalty value.
AddSoftSameVehicleConstraint().For example:
DROP_WEIGHT=100000
Task-A LAYOVER with Task-B, no time conflict, LAYOVER_WEIGHT=1000
Task-B NEARBY with Task-C, time conflict, merge to Task-BC, NEARBY_WEIGHT=10
Task-C LAYOVER with Task-D, no time conflict, LAYOVER_WEIGHT=1000
Then I would construct the following constraints:
routing.AddSoftSameVehicleConstraint([Task-A, Task-B], 1000)
routing.AddSoftSameVehicleConstraint([Task-C, Task-D], 1000)
routing.AddDisjunction([Task-B, Task-BC], 0, 1)
routing.AddDisjunction([Task-C, Task-BC], 0, 1)
routing.AddDisjunction([Task-A], 100000)
routing.AddDisjunction([Task-B], 100000)
routing.AddDisjunction([Task-C], 100000)
routing.AddDisjunction([Task-D], 100000)
routing.AddDisjunction([Task-BC], 100000*2+10)
Ideally, Task-A and Task-B should be assigned to the same person, Task-C and Task-D should be assigned to the same person, Task-BC should be dropped.
But because the penalty of
AddSoftSameVehicleConstraint()will be skipped when task is dropped, selecting Task-BC and drop Task-B、Task-C causes the two LAYOVER_WEIGHT penalties to be excluded from calculation. So the final solution will choose Task-A, Task-BC, Task-D.Beta Was this translation helpful? Give feedback.
All reactions