Create a variable which is rounding of another variable
AnsweredHi,
I want to create a variable which is round of another variable or use the rounded variable for my objective function. Example as below
I have a flow variable which iterates on a key (flow_variable). I need to find the number of trucks for the flow based on the calculated variable. the max capacity of truck is 1500.
So number of trucks = round (flow_variable/1500). But gurobi shows an error unable to use the round function on the variable. Any suggestions on how to do this are welcome?
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
In addition to the real-valued variable flow_variable, you can define the integer-valued variable trucks (preferably with an upper bound based on the fleet).
Let capacity=1500 be the capacity of a single truck. Then, you can define the following functional constraints:
capacity * (trucks - 1) <= flow_variable <= capacity * trucks
Note: depending on the formulation of your model and/or optimality conditions, you may actually only require the second constraint.
With this in place, you can easily incorporate the decision variable trucks into the objective function.
0 -
Thanks for the suggestion. Juan Orozco
0
Post is closed for comments.
Comments
3 comments