メインコンテンツへスキップ

Adding Constraint

回答済み

コメント

2件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff
    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?.
  • Jaromił Najman
    • Gurobi Staff

    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

投稿コメントは受け付けていません。