Adding lazy constraint in python-Gurobi interface
<p>I am trying to add some lazy constraints to the first stage of a stochastic programming problem. For example, the optimal solution shows me that locations 16 and 20 are chosen together which I don't want to so I want to add a lazy constraint as follows:</p>

<pre><code>   First Stage
       x1 + x2 + ... + x40 = 5
       z_i,l &lt;= x_i   i=1,..,40  and l=1,2
   Second Stage
       ....
   def mycallback(model,where):
       if where == GRB.Callback.MIPSOL:
          sol = model.cbGetSolution([model._vars[s] for s in range(1,40)])
          if sol[16] + sol[20] == 2:
             Exp = LinExpr([(1,model._vars[16]),(1,model._vars[20])])
             model.cbLazy(Exp &lt;= 1)

  model._vars = x
  model.optimize(mycallback)
</code></pre>

<p>But after running this function, locations 16 and 20 are still in the optimal solution. Could you please let me know how should I attack this issue?</p>