If Constraint
AnsweredHello,
i have a binary variables W[i,c,j,t], and i want to expres this constraint:
If for a given j and a given t W[i,c,j,t]=1 so all other W for the same j and t most be equal to 0.
For example if W[2,0,0,2]=1 so for i in I for c in C, W[i,c,0,2]=0.
Thank you
-
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. -
is it correct to express it like this :
model.addConstrs( (W[i,c,k,t] ==1) >> (gp.quicksum( W[j,d,k,t] for j in range(I) for d in range(C) if j != i if d !=c) == 0 ) for i in range(I) for k in range(K) for t in range(T)for c in range(C))
0 -
Hi Rayan,
The constraint looks correct. However, you don't necessarily need an indicator constraint for that.
If your \(\texttt{W}\) are binary then the constraints
\[\begin{align*}
\sum_{i \in I, c \in C} W_{i,c,k,t} = 1 \quad \forall k \in K, t \in T
\end{align*}\]already make sure that exactly one \(W_{i,c,k,t}\) is \(1\) over all \(i,c\) for a fixed \(k,t\).
Best regards,
Jaromił0 -
Hello Jaromi,
than you for your response,
i wrote the constraint like this :
for k in range(K):
for t in range(t):
model.addConstr(gp.quicksum(W[i,c,k,t] for i in range(I) for c in range(C))<=1)
and i found W[1,1,0,2] AND W[1,0,0,2] equal to 1.
i don't where is my error
Thank you0 -
I would guess that
for t in range(t):is a typo and should read
for t in range(T):0 -
Thnak you !!
0
Post is closed for comments.
Comments
6 comments