VRP disjunction/penalties drop for multiple constraints

519 views
Skip to first unread message

冷凌玉

unread,
Jul 20, 2021, 2:22:55 AM7/20/21
to or-tools-discuss

I read over the the method for penalty drop if solution is not feasible (e.g. total demand exceed total capacity) https://developers.google.com/optimization/routing/penalties
the example only takes account into one dimsion of constraint which is the vehicle capacity. Hence the disjunction method is added under the "add_capacity_constaint" method. If I have multiple constaints: weight limit, space limit, driving distance limit, driving time limit, and time window for each location, do I have to add the disjunction method multiple times to all of them?

I tested, if I just add disjunction under demand_callback, but the constraint violation happens in max driving distance, it won't work. If I further add below disjunction to "add_distance_constraint" method, it works to omit the locations far beyond the driving distance limit.

  # Allow to drop nodes. penalty = 1000 for node in range(1, len(data['distance_matrix'])): routing.AddDisjunction([manager.NodeToIndex(node)], penalty)  

Mizux Seiha

unread,
Jul 20, 2021, 3:27:23 AM7/20/21
to or-tools-discuss
1)  For each dimension you'll create, you'll have to set a vehicle capacity along this dimension. Here capacity stands for the "max CumulVar value" a vehicle is allowed to accumulate along the road.
ref: https://github.com/google/or-tools/blob/b37d9c786b69128f3505f15beca09e89bf078a89/ortools/constraint_solver/routing.h#L424-L456

2) Adding disjunction simply allow solver to drop nodes. It is independent of the dimension aka you only need to do it once then solver will drop the node if at least one dimension's cumulVar would be above the vehicle capacity for this dimension if solver wants to visit this node.

```python
def allow_dropping():
    # Allow to drop nodes.
    penalty = 1000
    for node in range(1, len(data['distance_matrix'])):
        routing.AddDisjunction([manager.NodeToIndex(node)], penalty)
```

3) I'm really surprised by the behavior you describe, may we have a small sample so we can reproduce it ?

冷凌玉

unread,
Jul 20, 2021, 5:01:53 AM7/20/21
to or-tools-discuss
Dear  Mizux,

where should I place the function  "allow_dropping()". In the Main before call solver (i.e. routing.SolveWithParameters)?

Corentin "Mizux" Le Molgat

unread,
Jul 20, 2021, 5:08:37 AM7/20/21
to or-tools-discuss
yes seems a good place.

冷凌玉

unread,
Jul 20, 2021, 5:15:31 AM7/20/21
to or-tools-discuss
I have make a standalone function allow_dropping() to be executed in the Main, and it works now. Many thanks
Reply all
Reply to author
Forward
0 new messages