Sign of slack variables

502 views
Skip to first unread message

Arthur Delarue

unread,
Jul 24, 2015, 11:19:16 AM7/24/15
to Gurobi Optimization
This is a very simple question, but I couldn't find a straightforward answer online. When you enter an inequality constraint into a Gurobi model, under the hood it seems to rewrite it as an equality constraint with a slack variable.I'm not sure what convention is used for the sign of the slack variable.

For instance, if I have a constraint of the form
x <= y
I don't know if Gurobi reformulates it as
x + z == y, z >= 0
or as
x == y + z, z <= 0
and the same goes for a constraint of the form
x >= y

After optimizing, when I query the value of a nonzero slack variable, will it always be positive or will its sign depend on the direction of the original inequality for which this slack variable was created ?

Thanks for your help!

Renan Garcia

unread,
Jul 24, 2015, 11:34:54 AM7/24/15
to gur...@googlegroups.com
The Slack constraint attribute is always non-negative for <= constraints, and non-positive for >= constraints. For example:

  gurobi> setParam('OutputFlag', 0)
  gurobi> m=Model()
  gurobi> x=m.addVar(lb=3, ub=3)
  gurobi> m.update()
  gurobi> c=m.addConstr(x <= 5)
  gurobi> m.optimize()
  gurobi> print c.slack
  2.0
  gurobi> c.sense='>'
  gurobi> c.rhs=1
  gurobi> m.optimize()
  gurobi> print c.slack
  -2.0

--

---
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.

Reply all
Reply to author
Forward
0 new messages