Additional cost based on total distance #2388
Unanswered
hrushk
asked this question in
Routing (and legacy CP) questions
Replies: 2 comments 5 replies
-
|
Beta Was this translation helpful? Give feedback.
3 replies
-
|
You can have as many dimensions as you want.
One will be time, and have time windows if needed on them.
One will be your modified cost structure, and can be used for the objective.
Does it answer your question?
Laurent Perron | Operations Research | [email protected] | (33) 1 42 68 53
00
Le mer. 10 févr. 2021 à 09:48, hrushk <[email protected]> a écrit :
… Sorry for brevity. Allow me explain what I am trying to do.
if a route for a vehicle is 0-->2-->5-->7-->0 [0 being the depot],
`# Create and register a transit callback.
def time_callback(from_index, to_index):
"""Returns the travel time between the two nodes."""
# Convert from routing variable Index to time matrix NodeIndex.
from_node = manager.IndexToNode(from_index)
to_node = manager.IndexToNode(to_index)
return data['time_matrix'][from_node][to_node]
transit_callback_index = routing.RegisterTransitCallback(time_callback)
# Define cost of each arc.
routing.SetArcCostEvaluatorOfAllVehicles(transit_callback_index)
# Define cost of each arc.
routing.SetArcCostEvaluatorOfAllVehicles(transit_callback_index)`
Using this the time_callback takes from and to node to calculate the cost
between each pair of visits by the vehicle. The cost for entire route will
indeed be the sum of individual cost. But as this time_callback takes to
and from nodes as inputs, is there a way to modify this one to only include
the first and last node and then feed the modified cost to
SetArcCostEvaluatorOfAllVehicles?
You mentioned that I can sum of individual time_callback, but then how do
I feed it to SetArcCostEvaluatorOfAllVehicles as it takes to and from node
irrespective of the position of the node in the route.
def SetArcCostEvaluatorOfAllVehicles(self, evaluator_index: int) -> 'void'
Sets the cost function of the model such that the cost of a segment of a
route between node 'from' and 'to' is evaluator(from, to), whatever the
route or vehicle performing the route.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#2388 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACUPL3NF2CHPXFH4TK7QIJDS6JB67ANCNFSM4XMNDSYA>
.
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
What language and solver does this apply to?
Python
Describe the problem you are trying to solve.
(VRPTW) Currently working in adding a cost based on total distance travelled by the vehicle --> Rounding off the travel time to the next multiple of 10.
Describe the solution you'd like
A way to modify the optimization objective as per the need. Specifically modify the travel cost of each vehicle to the nearest multiple of 10.
Describe alternatives you've considered
I tried implementing the above using AddDistanceDependentDimension, but I could not find a correct method to do so in Python. Is there any example that I can refer to.
Additional context
What I am trying to do is to optimize route cost in unit of 10.
Eg. If a vehicle travel from time 11 to 34, the usual cost should be 23 units, but since I want to do in units of 10, the cost will be from 10 to 30 which is 20 units. Can anyone please tell me the correct way to do this?
Any help would be really appreciated.
Beta Was this translation helpful? Give feedback.
All reactions