Skip to main content

Variable constraint

Answered

Comments

5 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    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.
  • 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

Post is closed for comments.