Names of violated constraints when using feasRelax

1,054 views
Skip to first unread message

Pradeep J

unread,
Oct 12, 2015, 1:38:03 AM10/12/15
to Gurobi Optimization

I am using feasRelax to assign a penalty for violating each constraint in my ILP model.
After calling model.optimize(), is there a way to find the names of the constraints that were violated during the optimization?

Renan Garcia

unread,
Oct 12, 2015, 10:27:32 AM10/12/15
to gur...@googlegroups.com
The easiest way to do this is if your variables and constraints have unique names. Then, each original variable gets its own artificial variable(s) (1 for each finite bound) with its unique name prefixed by 'ArtL_' or 'ArtU_'. Each original constraint gets its own artificial variable(s) (2 for equality constraints) with its unique name prefixed by 'ArtP_' or 'ArtN_'. Therefore, you can map the artificial variable and its value in the final solution to the original element that must be relaxed. If you don't have variable names, Gurobi will create default ones.

On Oct 12, 2015, at 12:21 AM, Pradeep J <pradee...@gmail.com> wrote:

I am using feasRelax to assign a penalty for violating each constraint in my ILP model.
After calling model.optimize(), is there a way to find the names of the constraints that were violated during the optimization?


--

---
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+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pradeep J

unread,
Oct 26, 2015, 1:56:14 AM10/26/15
to Gurobi Optimization
Thanks Renan. Just found the time to get back to you.

Just to be clear, I use `model.feasRelax(relaxobjtype=2, minrelax=False, vars=None, lbpen=None, rbpen=None, constrs=constraints, rhspen=penalty)` to relax the constraints.
This minimizes the sum of penalties specified in `rhspen` for each violated constraint in `constraints`.

I have assigned a unique name to each constraint and Gurobi prefixes them with `Art_P` or `Art_N`, but I'm still unclear on how to check for violation.

For example, if a model is infeasible, a flag called `GRB.INFEASIBLE` is set in `model.status`.
I was thinking if there was something available along these lines in the API to check if a constraint is violated.

P.S. I use Gurobi 6.0.4's Python API.

Best regards,
- Pradeep

Renan Garcia

unread,
Oct 26, 2015, 11:46:34 AM10/26/15
to gur...@googlegroups.com
Just query the values of the artificial variables

  artVars = [ v for v in model.getVars() if v.varname.startswith('ArtP_') or v.varname.startswith('ArtN_') ]

after solving the relaxation. For example, if you want to know if any constraints are violated, check whether the max violation

  max(v.x for v in artVars)

is greater than the setting for FeasibilityTol (see http://www.gurobi.com/documentation/6.0/refman/feasibilitytol.html).

Pradeep J

unread,
Oct 29, 2015, 11:25:30 PM10/29/15
to Gurobi Optimization
Thanks Renan, that works.
Reply all
Reply to author
Forward
0 new messages