Adding a variable to routing solver on two different dimensions to minimize the cost.

565 views
Skip to first unread message

Hanu

unread,
Jul 27, 2021, 8:33:28 AM7/27/21
to or-tools-discuss

I have two dimensions, one for node capacities and another dimension for node costs.

I want to add variable to AddVariableMinimizedByFinalizer() such that new variable should have product of capacity dimensions cumul value and maximum cost of nodes or end node cost in current vehicle route.

This product should be minimized by the solver to get the optimised solution.

 I am trying as below but unable to get max cost or end node cost of the nodes in the current route:

 total_cost = MakeIntVar(0, 99999999, "total");

for vehicle in range(max_vehicles):

AddConstraint(

                MakeProd(capacity_dimension.CumulVar(routing.End(vehicle), cost_dimension.CumulVar(routing.End(vehicle)),

                total_cost)

AddVariableMinimizedByFinalizer(total_cost)

 Instead of cumul value of the cost dimension, is there a way we can get the max cost of the nodes in current vehicle route? Or cost of the end node in the route?

 

Thanks in advance

Mizux Seiha

unread,
Jul 27, 2021, 8:39:17 AM7/27/21
to or-tools-discuss

Laurent Perron

unread,
Jul 27, 2021, 9:22:53 AM7/27/21
to or-tools-discuss
A variable added to the minimizer will not be added to the cost. Search will just try to assign its min value first when completing a solution. 

--
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/2fa82b41-d119-4f10-9845-e21a3f2bd518n%40googlegroups.com.

Hanu

unread,
Jul 27, 2021, 10:49:26 AM7/27/21
to or-tools-discuss

Thanks for pointing to the sample. This is not there in old version 8.0.  

Based on the example   https://github.com/google/or-tools/blob/b37d9c786b69128f3505f15beca09e89bf078a89/ortools/constraint_solver/samples/vrp_node_max.py#L245-L276 
we can get the max cost along the route.  Now we have both max cost(by slack dimension) along the route and total accumulated capacities (by capacity dimension) along the route.

If AddVariableMinimizedByFinalizer cannot be used for adding costs, then What other function can be used for adding product of slackMax and Capacity cumuls to the cost function so that solver can minimize the overall cost of the routes?

Thanks

Mizux Seiha

unread,
Jul 28, 2021, 4:02:07 AM7/28/21
to or-tools-discuss
you can use the CumulVarSoftUpperBound() to inject the CumulVar of the end node into the objective ;)

Dheeraj Vasudeva Rao Velaga

unread,
Jan 10, 2024, 1:47:19 AM1/10/24
to or-tools-discuss
Hi, I am trying to solve for 2 dimensions, one is travel time and other is cost on each node. I want the algorithm to take take both these factors into account, time should be minimized but cost should be maximum, thats the priority criteria for a node. I want the algorithm to give an optimized route based on this cirteria. Any idea on how i should proceed with this? I was trying to set a combined cost evaluator but the solution isnt being generated properly.
Reply all
Reply to author
Forward
0 new messages