Defining nodes that do not have to be visited

淺唱寂寞╮ 提交于 2019-12-11 13:08:02

问题


I'd like to define a routing problem using RoutingModel including nodes that are freed from the must-visit constraint, but have an influence on a capacity dimension if visited. Do you have any suggestions how to do this?


回答1:


You can use disjunction constraints to make your nodes optional. You should add each node to its own disjunction group, each having a single element:

    for node in [0, 1, 2, 3, 4]:
        routing.AddDisjunction(
            nodes=[node],
            penalty=1)

Why does this work?

In a disjunction group, the solver will try to include in the solution exactly max_cardinality nodes from that group.

  • If penalty is negative, this will be treated as a hard constraint, which means that the solver will not return a valid solution if the constraint is not satisfied.
  • However, if penalty is positive, this will be a soft constraint, meaning that a violation will add a penalty to the global cost variable.

Therefore, in order to minimize the penalties, the solver will attempt to include in the solution as many nodes as possible, while still being allowed to leave some of them out.



来源:https://stackoverflow.com/questions/53104283/defining-nodes-that-do-not-have-to-be-visited

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!