Adding Constraint
回答済みHow can I write code for this constraint ?
Xtk >= Xpk, all t and k, p is from t to last range.
I mean; for t in range 3
X11 >= X12
X11 >= X22
X11 >= X32
X21 >= X22
X21 >= X32
X31 >= X32
0
-
正式なコメント
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?. -
Hi Musa,
This is not really a Gurobi related question but rather a Python question. Nevertheless, you can use one of the following codes to model your inequalities:
T = [1,2,3]
K = [1,2]
X = m.addVars(T, K, vtype=GRB.BINARY, name="X")
for t in T:
for p in T:
if p>=t:
for k1 in K:
for k2 in K:
if k2>k1:
m.addConstr(X[t,k1] >= X[p,k2], name="constrX[%g,%g,%g,%g]"%(t,k1,p,k2))You can also use the addConstrs function
m.addConstrs((X[t,k1] >= X[p,k2] for t in T for p in T if p>=t for k1 in K for k2 in K if k2>k1), name="constrX")
Best regards,
Jaromił0
投稿コメントは受け付けていません。
コメント
2件のコメント