Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
144 views
in Technique[技术] by (71.8m points)

python - How to set minimum locations per route in Google OR-Tools?

I am trying to limit the minimum locations visit per vehicle, I have implemented the maximum location constraint successfully but having issues in figuring out minimum locations. My code for maximum location:

def counter_callback(from_index):
    """Returns 1 for any locations except depot."""
    # Convert from routing variable Index to user NodeIndex.
    from_node = manager.IndexToNode(from_index)
    return 1 if (from_node != 0) else 0;

counter_callback_index = routing.RegisterUnaryTransitCallback(counter_callback)

routing.AddDimensionWithVehicleCapacity(
    counter_callback_index,
    0,  # null slack
    [16,16,16],  # maximum locations per vehicle
    True,  # start cumul to zero
    'Counter')
question from:https://stackoverflow.com/questions/65880767/how-to-set-minimum-locations-per-route-in-google-or-tools

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should not put a hard limit on the number of nodes as it easily makes the model unfeasible.

The recommended way is to create a new dimension which just counts the number of visits (the evaluator always returns 1), then push a soft lower bound on the cumulvar of this dimension at the end of each vehicle.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...