ankane / or-tools-ruby

Operations research tools for Ruby
Apache License 2.0
179 stars 25 forks source link

[VRP] Add add_constant_dimension and set_cumul_var_soft_lower/upper_bound APIs? #34

Closed spinosa closed 2 years ago

spinosa commented 2 years ago

The VRP solver is working great. I am respectfully reaching out to request additional API coverage...

1) I would like to add soft bounds on time dimension of the locations. This API is available in python, where the implementation may look a bit like:

routing.AddDimension(transit_callback_index, 1000, 1000, false, 'Time')
time_dimension = routing.GetDimensionOrDie('Time')
time_dimension.SetCumulVarSoftLowerBound(index, time_window[0], TIME_WINDOW_BOUND_PENALTY)
time_dimension.SetCumulVarSoftUpperBound(index, time_window[1], TIME_WINDOW_BOUND_PENALTY)

ASK: Would it be possible to add set_cumul_var_soft_lower/upper_bound on a mutable_dimension?

2) I would like to use a constant dimension to count each stop and balance the number of stops between vehicles. While the constant dimension can handle this directly, I've found it beneficial to use soft bounds on the constant dimension. The API is available in python, where the implementation may look a bit like:

    routing.AddConstantDimension(
        1, 
        len(data['time_matrix']) // data['num_vehicles'] + 1,
        True,
        'stop_count')
    count_dimension = routing.GetDimensionOrDie('stop_count')
    num_visit = manager.GetNumberOfNodes() // manager.GetNumberOfVehicles()

    # From https://github.com/google/or-tools/discussions/2430
    for vehicle_id in range(manager.GetNumberOfVehicles()):
        index = routing.End(vehicle_id)
        count_dimension.SetCumulVarSoftLowerBound(index, num_visit, EVEN_WORKLOAD_PENALTY)
        count_dimension.SetCumulVarSoftUpperBound(index, num_visit + 1, EVEN_WORKLOAD_PENALTY)

ASK: Would it be possible to add add_constant_dimension to the routing model? And then, would it be possible to add set_cumul_var_soft_lower/upper_bound on a constant_dimension?

--

PS: FWIW, I tried to fork the repo and update the .cpp header myself. I did not succeed. My C skills have atrophied considerably... :-/. Your help with this is greatly appreciated!

PPS: My apologies for all the python -- I've more experience in Ruby -- but the python wrapper seems to have more comprehensive documentation and API coverage of the C libs.

ankane commented 2 years ago

Happy to add any missing methods that are needed.