### Comments

1 comment

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 gpm = gp.Model()n = 10x = 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.