ankane / or-tools-ruby

Operations research tools for Ruby

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[VRP] Add add_constant_dimension and set_cumul_var_soft_lower/upper_bound APIs?

spinosa opened this issue · comments

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?

  1. 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.

Happy to add any missing methods that are needed.