Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
shermanjasonaf opened this issue Mar 14, 2024 · 0 comments
Open

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

shermanjasonaf opened this issue Mar 14, 2024 · 0 comments

Comments

@shermanjasonaf
Copy link
Contributor

shermanjasonaf commented Mar 14, 2024

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
1 participant