Select variables in feasRelax()
Dear community,
In the Model.feasRelax() documentation the model.getVars() is used to assign the set of variables whose bounds are allowed to violate when calling feasRelax().
But what if I want to select a subset of those variables, say 3 or 4 and ask feasRelax() to play around with them and get me the solution that minimizes the bound violations of only those variables? Can I do this with Gurobi 9.0? If so how?
Regards
Buddi

Hi Buddi,
Yes, you can do this by passing a list of the corresponding Var objects to the vars argument of Model.feasRelax(). In the example in the documentation, all variable bounds are allowed to be violated, hence the use of Model.getVars().
Here is a short example:
import gurobipy as gp
m = gp.Model()
n = 10
x = m.addVars(n, ub=1, name="x")
y = m.addVar(ub=1, name="y")
for i in range(n):
m.addConstr(x[i] + y >= 3)
m.optimize()
if m.status == gp.GRB.INFEASIBLE:
# Only relax x variables
ubpen = [1.0]*n
m.feasRelax(0, False, x, None, ubpen, None, None)
m.optimize()The best way to minimize the sum of the absolute values of the bound violations for this problem and satisfy the \( n \) constraints is to set \( x_i = 1 \) for \( i = 1, \ldots, n \) and \( y = 2 \). The total violation in this case is \( 1 \), since each variable has an upper bound of \( 1 \). However, because we restrict Model.feasRelax() to only allow bound violations for the \( x \) variables, the solution is to set \( x_i = 2 \) for \( i = 1, \ldots, n \) and \( y = 1 \). This is total violation of \( n \).
I hope this helps!
Eli
Please sign in to leave a comment.
Comments
1 comment