Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
122 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...