Skip to content

Add lslack() and uslack() methods for Var objects #3197

Open
@shermanjasonaf

Description

@shermanjasonaf

Summary

Add lslack() and uslack() methods for Var objects to faciliate quick evaluation of variable lower and upper bound slacks (or violations).

Rationale

Pyomo Constraint objects already have lslack() and uslack() methods available for quickly evaluating constraint lower and upper bound slacks. The availability of similar methods for Var objects would be convenient.

Description

Consider the following setup:

>>> import pyomo.environ as pyo
>>> m = pyo.ConcreteModel()
>>> m.v = pyo.Var(initialize=1, bounds=(0, None))
>>> m.con = pyo.Constraint(expr=m.v ** 2 <= 2)
>>> m.pprint()
1 Var Declarations
    v : Size=1, Index=None
        Key  : Lower : Value : Upper : Fixed : Stale : Domain
        None :     0 :     1 :  None : False : False :  Reals

1 Constraint Declarations
    con : Size=1, Index=None, Active=True
        Key  : Lower : Body : Upper : Active
        None :  -Inf : v**2 :   2.0 :   True

2 Declarations: v con

The lower and upper bound slacks for the constraint m.con can be evaluated using the lslack() and uslack() methods as follows:

>>> m.con.lslack()
inf
>>> m.con.uslack()
1

It would be convenient if variable bound slacks could be evaluated similarly, to the effect of:

>>> m.v.lslack()
1
>>> m.v.uslack()
inf

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions