Max distance traveled by vehicle between depots

289 views
Skip to first unread message

Anurag

unread,
Mar 8, 2017, 2:26:45 AM3/8/17
to or-tools-discuss
Hi All,

I am trying to solve a VRP by using python version of ortools and facing problem in applying one of the business constraints on max distance traveled by vehicle between depot/customer locations.

The constraint I have is that the vehicle should not travel more than 200 km after the first unloading as the goods can get damaged in long distance in a partially loaded vehicle. I think it is possible to put this constraint between 2 locations by eliminating all the locations which are more than 200 km far from the nexts_ domain of a depot variable but I am stuck at how to put this condition between 3 or more locations?

Any ideas on how to accommodate this using any of the current constraints?


Best regards,
Anurag

Sylvain Ducomman

unread,
Mar 8, 2017, 2:35:55 AM3/8/17
to or-tools...@googlegroups.com
Hi,
If the condition of te max distance traveled is for the complete tour of vehicle (back to the depot at the end of the tour), you can add a a constraint on the CumulVar of the endNode for the dimension distance.
Or if it is for any visit possible, add a constraint on the CumulVar for the distance dimension.
So for each node in the graph distanceDimension.CumulVar(node) <= 200 for example.

Best regards,
--
Sylvain Ducomman




--
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.
For more options, visit https://groups.google.com/d/optout.

Anurag

unread,
Mar 9, 2017, 4:11:59 AM3/9/17
to or-tools-discuss
Thanks for the reply Sylvain.

I want to put a constraint from first node (after the depot) onwards so i think putting a constraint like distanceDimension.CumulVar(node)<=200 will include distance from depot to first node also.

Is it possible to put measure the cumulative distance after the first node. something like -

distanceDimension.Cumul(node)-distanceDimension.CumulVar(firstnodeafterDepot)<=200.

Thanks for all the help in advance!

Best regards,
Anurag

Sylvain Ducomman

unread,
Mar 9, 2017, 4:16:19 AM3/9/17
to or-tools...@googlegroups.com
Hello,
I think is it possible to have access of the first node after depot.
But you should create an extra variable to capture this cumul var.
So the extra variable use the constraint element, CumulVarFirstNode = Element(CumulVars, NextVar(Depot)).
With this variable, you can add your constraint.

I hope this helps,
Best regards,
--
Sylvain Ducomman




Vincent Furnon

unread,
Mar 9, 2017, 5:18:05 AM3/9/17
to or-tools...@googlegroups.com
A more efficient solution would be to create an extra km dimension which has the same distance callback as the current km dimension except that all distances leaving the start depot are equal to zero. Then you can just constrain the cumul at the last (depot) node to be <= 200. I wonder if you would still need the normal km dimension anymore.

Vincent

To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discuss+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
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-discuss+unsubscribe@googlegroups.com.

Anurag

unread,
Mar 10, 2017, 3:26:08 AM3/10/17
to or-tools-discuss
Thanks a lot Sylvain and Vincent!

I think the modification in the distance call back function is a brilliant solution!! I am stuck with this problem for so long but never thought the solution would be so simple!! 

Will try this solution and would write back to you guys in case of any further queries.

Best regards,
Anurag
Reply all
Reply to author
Forward
0 new messages