tabulated values for a gurobi variable
AnsweredDear all,
I am trying to assign to a continuous variable (vtype = gp.GRB.CONTINUOUS) a value chosen from a series of pre-calculated values. This decision/attribution takes place in light of the decision made, during the optimization process, about a set of binary decision variables.
In particular, I will therefore have decision variables such as:
z = {}
for k in K:
z[k] = m.addVar(vtype = gp.GRB.BINARY, name = 'z_%s' % (k))
and the variables
x = {}
for q in Q:
x[q] = m.addVar(vtype = gp.GRB.CONTINUOUS, name = 'z_%s' % (q))
take values extracted from a dictionary Q_vals[{x}].
Is it possible to model such a system in gurobi?
-
Official comment
This post is more than two 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 try Gurobot, our chatbot interface offering instant, expert-level support. -
Hi Federico,
I am not sure I fully understood your question. I guess you mean that the continuous variable \(x\) can be assigned to a value from the set \(\{a_1, a_2, \ldots, a_k\}\). To model this, you can define binary decision variables \(z_i\) which equals 1 if the value \(a_i\) is assigned to variable \(x\) and equals 0 otherwise. You would then need to define the constraints below:
\[\begin{align} & \sum_{i=1}^{k} z_i = 1 & \\ & x = \sum_{i=1}^{k} a_i z_i & \end{align}\]
The first constraint ensures that exactly one of the \(z\) variables is assigned to 1 and the second constraint ensures that \(x\) variable is assigned to exactly one value from the predetermined set.
Hope this helps. Let me know if I misunderstood your question.
Best regards,
Maliheh
0
Post is closed for comments.
Comments
2 comments