Cost changes depending on distance travelled

224 views
Skip to first unread message

Aniket Sharma

unread,
May 21, 2021, 3:47:52 AM5/21/21
to or-tools-discuss
Hi, I am working on a CVRPTW. In this the objective function is to minimize the cost of all the vehicles. Each vehicle will have a fixed cost and it will run for x distance for 0 running cost and then it will have a running cost after it has exceeded its x distance limit.

For example, I have a vehicle with fixed cost of 500 and it will cover 10 km distance in the fixed cost after that it will take 20 cost per km. So, if it covers 15 kilometer the total cost should be 500+(20*5) = 600

I know I can used SetFixedCostOfVehicle() function to add the 500 fixed cost but I don't know how to get the total distance travelled yet in the transit callback.

Laurent Perron

unread,
May 21, 2021, 5:30:06 AM5/21/21
to or-tools-discuss
The callback must be stateless.
Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00



--
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/102d36a2-7cfc-4e36-8ad0-c2236dbf3234n%40googlegroups.com.

Aniket Sharma

unread,
May 21, 2021, 5:38:28 AM5/21/21
to or-tools-discuss
Can you tell a bit more why that it should be stateless?

Laurent Perron

unread,
May 21, 2021, 6:28:14 AM5/21/21
to or-tools-discuss
1) callbacks are cached
2)s  stateful callbacks would slow down the solver by multiple orders of magnitude

Vincent Furnon

unread,
May 21, 2021, 6:35:23 AM5/21/21
to or-tools...@googlegroups.com
Suggestion: create a distance dimension, add a soft cost on vehicle end nodes after 10km.

--

Aniket Sharma

unread,
May 21, 2021, 8:15:03 AM5/21/21
to or-tools-discuss
Thanks, Laurent for the explanation.

And thank you so much Vincent it is exactly what I needed.

Prince Singh

unread,
Jun 8, 2021, 2:47:46 AM6/8/21
to or-tools-discuss
Hi Aniket,
I am also working on the CVRPTW problem. Is there any way we can connect, so that I can seek some help on the same?

Aniket Sharma

unread,
Jun 9, 2021, 3:06:26 AM6/9/21
to or-tools-discuss
Hey, I am not sure I should share my details here. We can discuss the problem here. I guess it should be fine.
Reply all
Reply to author
Forward
0 new messages