tabulated values for a gurobi variable
回答済みDear 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?
-
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
サインインしてコメントを残してください。
コメント
1件のコメント