title: Pyomo: constraint with if statements
body: <p>I am currently trying to solve this problem. I need to maximize the profit of this company. </p>
  
  <p>That s the code I currently have: </p>
  
  <pre><code>from pyomo.environ import *
  from pyomo.opt import *
  opt = solvers.SolverFactory("ipopt")
  model = ConcreteModel()
  
  model.x1 = Var(within=NonNegativeIntegers)
  model.x2 = Var(within=NonNegativeIntegers)
  model.y1 = Var(within=NonNegativeIntegers)
  model.y2 = Var(within=NonNegativeIntegers)
  model.b1 = Var(within=Boolean)
  model.b2 = Var(within=Boolean)
  
  model.c1 = Constraint(expr = model.x1 + model.x2 + model.y1 + model.y2 &lt;=   7000)
  model.c2 = Constraint(expr = 2*model.x1 + 2*model.x2 + model.y1 + model.y2 &lt;= 10000)
  model.c3 = Constraint(expr = model.x1  &lt;= 2000)
  model.c4 = Constraint(expr = model.x2 &lt;= 1000)
  model.c5 = Constraint(expr = model.y1 &lt;= 2000)
  model.c6 = Constraint(expr = model.y2 &lt;= 3000)
  
  
  model.z = Objective(expr= (150*model.x1 + 180*model.x2*model.b1 + 100*model.y1 + 110*model.y2*model.b2), sense=maximize)
  results = opt.solve(model)
  </code></pre>
  
  <p>This is the code I tried to write for my constraint which is then only using the first slope as long as it does not exceed 2000 products: </p>
  
  <pre><code>def ObjRule(model):
   if model.x1 &gt;= 2000:
       return model.b1==1
   if model.x2 &gt;= 2000:
       return model.b2 == 1`
  </code></pre>
  
  <p>If someone would have a hint, how I could proceed that would be great.</p>
  
  <p>thank you in advance,
  Patrick</p>