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

Variable constraint

回答済み

コメント

4件のコメント

  • Marika Karbstein
    • Gurobi Staff

    Your third for-loop looks not correct: 

    for j in range(j)
    0
  • Rayan SAAD
    • Gurobi-versary
    • Investigator
    • Conversationalist

    thanks a lot !

    But now i want to add conditions like this 

    But i dont know how to write in python

    thank you !

    0
  • Marika Karbstein
    • Gurobi Staff

    It is not easy to understand what you really want to do with these code snippets and what is not working. But the following is possible:

    I=range(3)
    T=range(5)
    J=range(4)
    x = model.addVars(I, J, T, name='u')

    for i in I:
      for t in T:
          for j in J:
              if j==1:
                  model.addConstr(x[i, j, t] <= 4)
              elif j==2:
                  model.addConstr(x[i, j, t] <= 3)
              else:
                    model.addConstr(x[i, j, t] <= 1)  

    What kind of problem do you have?

    0
  • Rayan SAAD
    • Gurobi-versary
    • Investigator
    • Conversationalist

    Perfect, i just forgot the loop for j

    thank youu !!

    0

サインインしてコメントを残してください。