title: Gurobi: Relaxing Infeasible Model in Python
body: <p>I have the following constraint set in the mathematical notation of Gurobi. <code>x</code> variables are binary. <code>sigmaplus</code> and <code>sigmaminus</code> variables are positive and continuous.</p>
  
  <pre><code>Subject To
   858 x[1,_2] + 1092 x[1,_3] - sigmaplus[1] + sigmaminus[1] = -200  # Constraint 1
   858 x[1,_2] + 1092 x[1,_3] &gt;= -1800 # Constraint 2
   858 x[1,_2] + 1092 x[1,_3] &lt;= 0 # Constraint 3
   x[1,_2] + x[1,_3] = 1 # Constraint 4
   720 x[2,_1] + 990 x[2,_2] - sigmaplus[2] + sigmaminus[2] = 2000 # Constraint 5
   720 x[2,_1] + 990 x[2,_2] &gt;= -500 # Constraint 6
   720 x[2,_1] + 990 x[2,_2] &lt;= 3000 # Constraint 7
   x[2,_1] + x[2,_2] = 1 # Constraint 8
   ...
   ...
  </code></pre>
  
  <p>As you can notice, <code>constraint 2</code> and <code>constraint 3</code> make the solution infeasible. When, such a situation occurs with my <code>x</code> variables, I want Gurobi to do the optimization by setting those conflicting <code>x</code> values equal to 0. So, for this example, I want x<code>[1,2]</code> and <code>x[1,3]</code> to be equal to 0 in order to find a feasible solution without those variables. Is there any way to code this for <code>Gurobi 7.0.2</code>.</p>
  
  <p>Also, I am using <code>2.7.12 Anaconda 4.2.0(64-bit)</code>. Following is the code that I use for relaxing the problem to find a solution.</p>
  
  <pre><code>if m.status == GRB.INFEASIBLE:
      m.feasRelaxS(1, False, False, True)
  </code></pre>
  
  <p>This works fine in some situation. I mean, it sets those infeasibility creating variables to 0. However, in some other cases where <code>constraints 1,2,</code> and <code>3</code> do not create any infeasibility, <code>constraint 4</code> creates an infeasibility, the solver increases the right-hand side of <code>Constraint 4</code>. So, I need to find a way to set them 0 in such cases. Any suggestion appreciated.</p>