Does Different slack per node when using AddDimensionWithVehicleCapacity Exists

306 views
Skip to first unread message

youssef kaichouh

unread,
Jun 5, 2022, 3:48:21 PM6/5/22
to or-tools...@googlegroups.com
I'm solving a CVRP with heterogeneous fleet using AddDimensionWithVehicleCapacity method, and i'm trying to set a slackVar range per index (to implement Reload Vrp)
routing.AddDimensionWithVehicleCapacity(
        demand_callback_index,
        0,  # null capacity slack
        data['vehicle_capacities'],  # vehicle maximum capacities
        True,  # start cumul to zero
        'Capacity')
    capacity_dimension = routing.GetDimensionOrDie(capacite)
for node in nodes:
            index = manager.NodeToIndex(node)
            capacity_dimension.SlackVar(index).SetRange(0, slack_of_node(node))
But the slack variable seems to stay always zero 
I'm missing something plz ?

Laurent Perron

unread,
Jun 5, 2022, 4:04:03 PM6/5/22
to or-tools-discuss
You can always constrain the slack var manually. 

--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/CAOtwtKWNUgE10kCOKbRigP3BMNLV16w8xjqry2sdnUp6zXH6-w%40mail.gmail.com.

youssef kaichouh

unread,
Jun 5, 2022, 4:05:35 PM6/5/22
to or-tools...@googlegroups.com
What do you mean please ? it isn't done by capacity_dimension.SlackVar(index).SetRange(0, slack_of_node(node)) ? 

youssef kaichouh

unread,
Jun 5, 2022, 4:16:23 PM6/5/22
to or-tools...@googlegroups.com
I did replace capacity_dimension.SlackVar(index).SetRange(0, slack_of_node(node)) by
solver.Add(capacity_dimension.SlackVar(index) >= 0)
solver.Add(capacity_dimension.SlackVar(index) <= slack_of_node(node))
And the slack is always considered to be zero 
Any help please 

Laurent Perron

unread,
Jun 5, 2022, 4:26:31 PM6/5/22
to or-tools-discuss
The null capacity slack is an upper bound of all slack variables. Setting the range will not extend the domain of the slack variables. 

youssef kaichouh

unread,
Jun 5, 2022, 4:30:19 PM6/5/22
to or-tools...@googlegroups.com
I see, but how can i do please set the slack variable in (0, x) for some nodes with x depending on the node ? is it possible with a DimensionWithVehicleCapacity ?

Laurent Perron

unread,
Jun 5, 2022, 4:37:33 PM6/5/22
to or-tools-discuss
DimensionWithVehicleCapacity -> max cumulative transit on the path of each vehicle

For node n: 

index = manager.NodeToIndex(n)
slack_var = dimension.SlackVar(index)
slack_var.SetRange(0, max)
Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00



youssef kaichouh

unread,
Jun 5, 2022, 5:10:27 PM6/5/22
to or-tools...@googlegroups.com
This is exactly what i did by capacity_dimension.SlackVar(index).SetRange(0, slack_of_node(node)) and it's not working, the slack remains 0 

blind.line

unread,
Jun 5, 2022, 8:41:34 PM6/5/22
to or-tools...@googlegroups.com
You cannot start with slack=0 and then increase it

You must start with non-zero slack and then decrease/increase as needed. 


If you choose to create the dimension with zero slack, you will trigger an optimization that fixes the slack to zero always. 

James

On Jun 5, 2022, at 14:10, youssef kaichouh <youssef.k...@gmail.com> wrote:



youssef kaichouh

unread,
Jun 6, 2022, 7:13:31 AM6/6/22
to or-tools-discuss
yes It did work this way, thank you!
Reply all
Reply to author
Forward
0 new messages