Reduce time/distance travelled per item in vehicle

84 views
Skip to first unread message

Songyan

unread,
Dec 19, 2021, 11:57:34 PM12/19/21
to or-tools-discuss
Hi, I noticed that based on my current pickup/delivery implementation does not take in the time/distance travelled of each item in the vehicle.

The case study is
Item 1: A -> B
Item 2: C -> B

And on the map it is
A -----50km-------> B <--------------200km----------> C
A ----------------------------240km ------------------------> C

Currently the optimization returns A->C->B because of the shortest distance, which is 440km.
However, the item is heavy thus the cost of fuel also increases based on the distance travelled.

May I know whether it is possible to add additional cost to the objective so that we include the distance travel with N coefficient, thus 

Case 1: A->B->C->B
Distance: 450km
Total distance travelled for each item: 250km (A->B +C->B)

Case 2: A->C->B
Distance: 440km
Total distance travelled for each item: 640km (A->C +2*(B->B))

Is it possible to calculate the total distance travelled for each item in dimension?

Thank you.

Mizux Seiha

unread,
Dec 20, 2021, 4:16:13 AM12/20/21
to or-tools-discuss
I see two options:
1) In C++ you could use AddDimensionDependentDimension() i.e. create a "distance * load" dimension which depend on the "Load" Dimension.

2) Since you carry items from Pickup to Delivery using only one vehicle, you have the guaranty that both locations are on the same route thus you can compute the difference of distance dimension CumulVar between the delivery and pickup.
So, you just need to create a new dummy dimension with a constant transit cost == 0 and a large slackvar domain.
Then for each delivery index you can add the constraint:
routing.solver().Add(dim.SlackVar(delivery_index) == distance_dimension.CumulVar(delivery_index) - distance_dimension.CumulVar(pickup_index))
so at the end, the CumulVar of each vehicle's end node should contains the sum of all item traveled distance of this vehicle.
Then you can use some SetCumulVarSoftUpperBound() to add this cost to the objective function...
Reply all
Reply to author
Forward
0 new messages