how to use value of a continuous variable as another variable's index?
AnsweredHi~
I have a integer variable a_int.
a_int = {(i, k): model.addVar(vtype=gp.GRB.INTEGER, name=f'a_int_{i}_{k}') for i in V for k in K}
And I have another continuous variable X[t,k], which t=a_int[i,k].
when a_int[i,k]!=0, the relationships below will established!!!
That is I hope X[t,d] can be written as X[a_int[i,k],k], but variable can't be an index.
How to written in gurobi python
P.S.
for example:
a_int[ 5,1]: 0.0
a_int[ 5,2]: 10.0
a_int[ 6,1]: 0.0
a_int[ 6,2]: 13.0
so two constraints will be established:
X[10,2]==customer 5's X coord
X[13,2]==customer 6's X coord
-
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,
Yes, variables as indices of other variables are not possible. Maybe you can reformulate your problem in a way to avoid this situation. But without knowing your problem, you might work with binary variables Y[i,k,t] for i in V, k in K, t in the domain of variable a_int[i,k]. Then,
a_int[i,k] == sum_{t} t * Y[i,k,t]
sum_{t} Y[i,k,t] == 1The continuous coordinate variables might also have another index, i.e., Z[i,k,t]. Together with the Y[i,k,t], you can ensure that only one Z[i,k,t] is non-zero:
LB * Y[i,k,t] <= Z[i,k,t] <= UB * Y[i,k,t]
X[t,k] = sum_{i} Z[i,k,t]Not sure if that works for your problem. Maybe you need more constraints to limit the number of non-zero 3-index variables.
Best regards,
Mario0
Post is closed for comments.
Comments
2 comments