pythongurobifeasibility

Gurobi: Relaxing Infeasible Model in Python


I have the following constraint set in the mathematical notation of Gurobi. x variables are binary. sigmaplus and sigmaminus variables are positive and continuous.

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] >= -1800 # Constraint 2
 858 x[1,_2] + 1092 x[1,_3] <= 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] >= -500 # Constraint 6
 720 x[2,_1] + 990 x[2,_2] <= 3000 # Constraint 7
 x[2,_1] + x[2,_2] = 1 # Constraint 8
 ...
 ...

As you can notice, constraint 2 and constraint 3 make the solution infeasible. When, such a situation occurs with my x variables, I want Gurobi to do the optimization by setting those conflicting x values equal to 0. So, for this example, I want x[1,2] and x[1,3] to be equal to 0 in order to find a feasible solution without those variables. Is there any way to code this for Gurobi 7.0.2.

Also, I am using 2.7.12 Anaconda 4.2.0(64-bit). Following is the code that I use for relaxing the problem to find a solution.

if m.status == GRB.INFEASIBLE:
    m.feasRelaxS(1, False, False, True)

This works fine in some situation. I mean, it sets those infeasibility creating variables to 0. However, in some other cases where constraints 1,2, and 3 do not create any infeasibility, constraint 4 creates an infeasibility, the solver increases the right-hand side of Constraint 4. So, I need to find a way to set them 0 in such cases. Any suggestion appreciated.


Solution

  • feasRelaxS ( relaxobjtype, minrelax, vrelax, crelax )
    

    Arguments:

    relaxobjtype: The cost function used when finding the minimum cost relaxation.

    minrelax: The type of feasibility relaxation to perform.

    vrelax: Indicates whether variable bounds can be relaxed.

    crelax: Indicates whether constraints can be relaxed.

    This function modifies the Model object to create a feasibility relaxation. This method provides a number of options for specifying the relaxation. The minrelax argument is a boolean that controls the type of feasibility relaxation that is created. If minrelax=False, optimizing the returned model gives a solution that minimizes the cost of the violation. If minrelax=True, optimizing the returned model finds a solution that minimizes the original objective, but only from among those solutions that minimize the cost of the violation. If you want your model to relax variable value for which the constraint is infeasible, change vrelax from False to True. You can read the full description given on: https://www.gurobi.com/documentation/7.5/refman/py_model_feasrelaxs.html