Gurobi: Relaxing Infeasible Model in Python

215 views
Skip to first unread message

Taner Cokyasar

unread,
Jun 9, 2017, 12:31:13 AM6/9/17
to Gurobi Optimization
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 in such cases.

    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.

Edgar Alan Avila Gomez

unread,
Jun 10, 2017, 4:17:04 AM6/10/17
to gur...@googlegroups.com
Hi Taner... 

At first sight it seems that there is no search process, in restriction number 4 indicate that only one variable in the list X [1, J] can be selected, therefore restriction 3 and 4 is based on the search of a parameter Actually, the parameter that is under a range ... restriction 1 is redundant, the deviation variables will have a certain value, after finding the parameter in restriction 3 and 4 ...

The problem is not feasible by restriction 4, since you are forcing that at least one is selected, when in fact, you must give him the opportunity to have the value of 0 and 1 ...

  X [1, _2] + x [1, _3] <= 1 # Constraint 4

So if there is no value "parameter" that is within the range, its associated decay variable, it will have the value of "0" ... everything depends on your objective function.

On the other hand, it is not necessary to formulate these restrictions to know the result. At the moment of wanting only one parameter selected, that this within a range. The only choices are: (at a glance.)

1- Do not take any parameter
2- Take the maximum
3- Take the minimum

For this it is not necessary to make a model, and it is possible to iterate the values ​​of your parameters.

Restriction = False
For i in parameter_list [i]
..... if i> = lower_bound and i <= upper bound:
............ restriction = True

Then if at least one meets this condition .. you can create your series of restrictions.

If restriction == True:
M.addContrss

Or set these variables to zero ..

If restriction == False:
... for j in range ....
....... m.addConstr (x [i, j] == 0)

Of course, you must improve this code ... and evaluate if it really is necessary.

--

---
You received this message because you are subscribed to the Google Groups "Gurobi Optimization" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gurobi+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
MII. Edgar Alan Ávila Gómez 
6671678109

Reply all
Reply to author
Forward
0 new messages