ScalarConstraint
(class from pyomo.core.base.constraint
)
- class pyomo.core.base.constraint.ScalarConstraint(*args, **kwds)[source]
Bases:
ConstraintData
,Constraint
ScalarConstraint is the implementation representing a single, non-indexed constraint.
Methods
__init__
(*args, **kwds)activate
()Set the active attribute to True
add
(index, expr)Add a constraint with a given index.
clear
()Clear the data in this component
clear_suffix_value
(suffix_or_name[, expand])Set the suffix value for this component data
cname
(*args, **kwds)DEPRECATED.
construct
([data])Construct the expression(s) for this constraint.
Set the active attribute to False
dim
()Return the dimension of the index
display
([prefix, ostream])Print component state information
get_suffix_value
(suffix_or_name[, default])Get the suffix value for this component data
Get the expression on this constraint.
getname
([fully_qualified, name_buffer, ...])Return a string with the component name and index
has_lb
()Returns
False
when the lower bound isNone
or negative infinityhas_ub
()Returns
False
when the upper bound isNone
or positive infinityReturn an dictionary id->index for all ComponentData instances.
index
()Returns the index of this ComponentData instance relative to the parent component index set.
Return the index set
Return True if this class is a Pyomo component
Return True if this class has been constructed
is_expression_type
([expression_system])Return True if this numeric value is an expression
Return true if this component is indexed
Return True if this class is a Pyomo Boolean object.
Return True if this numeric value is a named expression
Return True if this class is a Pyomo numeric object
Return False unless this class is a parameter object
Return True if this component is a reference, where "reference" is interpreted as any component that does not own its own data.
Return False unless this class is a variable object
items
([sort, ordered])Return an iterator of (index,data) component data tuples
DEPRECATED.
iterkeys
()DEPRECATED.
DEPRECATED.
keys
([sort, ordered])Return an iterator over the component data keys
lslack
()Returns the value of f(x)-L for constraints of the form:
model
()Return the model of the component that owns this data.
Return the parent of the component that owns this data.
Returns the component associated with this object.
pprint
([ostream, verbose, prefix])Print component information
reconstruct
([data])REMOVED: reconstruct() was removed in Pyomo 6.0.
Return self.model()
set_suffix_value
(suffix_or_name, value[, expand])Set the suffix value for this component data
set_value
(expr)Set the expression on this constraint.
slack
()Returns the smaller of lslack and uslack values
to_bounded_expression
([evaluate_bounds])Convert this constraint to a tuple of 3 expressions (lb, body, ub)
TODO
type
()DEPRECATED.
uslack
()Returns the value of U-f(x) for constraints of the form:
Return True if this can be used as a model component.
values
([sort, ordered])Return an iterator of the component data objects
Attributes
Return the active attribute
The body (variable portion) of a constraint expression.
Return the class type for this component
True if this is an equality constraint.
Return the expression associated with this constraint.
the value of the lower bound of a constraint expression.
Get the component name only within the context of the immediate parent container.
The lower bound of a constraint expression.
Get the fully qualified component name.
True if this constraint has a strict lower bound.
True if this constraint has a strict upper bound.
the value of the upper bound of a constraint expression.
Access the upper bound of a constraint expression.
Member Documentation
- activate()
Set the active attribute to True
- clear_suffix_value(suffix_or_name, expand=True)
Set the suffix value for this component data
- cname(*args, **kwds)
DEPRECATED.
Deprecated since version 5.0: The cname() method has been renamed to getname(). The preferred method of obtaining a component name is to use the .name property, which returns the fully qualified component name. The .local_name property will return the component name only within the context of the immediate parent container.
- construct(data=None)
Construct the expression(s) for this constraint.
- deactivate()
Set the active attribute to False
- dim()
Return the dimension of the index
- display(prefix='', ostream=None)
Print component state information
This duplicates logic in Component.pprint()
- get_suffix_value(suffix_or_name, default=None)
Get the suffix value for this component data
- get_value()
Get the expression on this constraint.
- getname(fully_qualified=False, name_buffer=None, relative_to=None)
Return a string with the component name and index
- has_lb()
Returns
False
when the lower bound isNone
or negative infinity
- has_ub()
Returns
False
when the upper bound isNone
or positive infinity
- id_index_map()
Return an dictionary id->index for all ComponentData instances.
- index()
Returns the index of this ComponentData instance relative to the parent component index set. None is returned if this instance does not have a parent component, or if - for some unknown reason - this instance does not belong to the parent component’s index set.
- index_set()
Return the index set
- is_component_type()
Return True if this class is a Pyomo component
- is_constructed()
Return True if this class has been constructed
- is_expression_type(expression_system=None)
Return True if this numeric value is an expression
- is_indexed()
Return true if this component is indexed
- is_logical_type()
Return True if this class is a Pyomo Boolean object.
Boolean objects include constants, variables, or logical expressions.
- is_named_expression_type()
Return True if this numeric value is a named expression
- is_numeric_type()
Return True if this class is a Pyomo numeric object
- is_parameter_type()
Return False unless this class is a parameter object
- is_reference()
Return True if this component is a reference, where “reference” is interpreted as any component that does not own its own data.
- is_variable_type()
Return False unless this class is a variable object
- items(sort=<SortComponents.UNSORTED: 0>, ordered=NOTSET)
Return an iterator of (index,data) component data tuples
- Parameters:
sort (bool or SortComponents) – Iterate over the declared component items in a specified sorted order. See
SortComponents
for valid options and descriptions.ordered (bool) – DEPRECATED: Please use sort=SortComponents.ORDERED_INDICES. If True, then the items are returned in a deterministic order (using the underlying set’s ordered_iter().
- iteritems()
DEPRECATED.
Return a list (index,data) tuples from the dictionary
Deprecated since version 6.0: The iteritems method is deprecated. Use dict.items().
- iterkeys()
DEPRECATED.
Return a list of keys in the dictionary
Deprecated since version 6.0: The iterkeys method is deprecated. Use dict.keys().
- itervalues()
DEPRECATED.
Return a list of the component data objects in the dictionary
Deprecated since version 6.0: The itervalues method is deprecated. Use dict.values().
- keys(sort=<SortComponents.UNSORTED: 0>, ordered=NOTSET)
Return an iterator over the component data keys
This method sets the ordering of component data objects within this IndexedComponent container. For consistency,
__init__()
,values()
, anditems()
all leverage this method to ensure consistent ordering.- Parameters:
sort (bool or SortComponents) – Iterate over the declared component keys in a specified sorted order. See
SortComponents
for valid options and descriptions.ordered (bool) – DEPRECATED: Please use sort=SortComponents.ORDERED_INDICES. If True, then the keys are returned in a deterministic order (using the underlying set’s ordered_iter()).
- lslack()
- Returns the value of f(x)-L for constraints of the form:
L <= f(x) (<= U) (U >=) f(x) >= L
- model()
Return the model of the component that owns this data.
- parent_block()
Return the parent of the component that owns this data.
- parent_component()
Returns the component associated with this object.
- pprint(ostream=None, verbose=False, prefix='')
Print component information
- reconstruct(data=None)
REMOVED: reconstruct() was removed in Pyomo 6.0.
Re-constructing model components was fragile and did not correctly update instances of the component used in other components or contexts (this was particularly problemmatic for Var, Param, and Set). Users who wish to reproduce the old behavior of reconstruct(), are comfortable manipulating non-public interfaces, and who take the time to verify that the correct thing happens to their model can approximate the old behavior of reconstruct with:
component.clear() component._constructed = False component.construct()
- root_block()
Return self.model()
- set_suffix_value(suffix_or_name, value, expand=True)
Set the suffix value for this component data
- slack()
Returns the smaller of lslack and uslack values
- to_bounded_expression(evaluate_bounds=False)
Convert this constraint to a tuple of 3 expressions (lb, body, ub)
This method “standardizes” the expression into a 3-tuple of expressions: (lower_bound, body, upper_bound). Upon conversion, lower_bound and upper_bound are guaranteed to be None, numeric constants, or fixed (not necessarily constant) expressions.
Note
As this method operates on the current state of the expression, any required expression manipulations (and by extension, the result) can change after fixing / unfixing
Var
objects.- Parameters:
evaluate_bounds (bool) – If True, then the lower and upper bounds will be evaluated to a finite numeric constant or None.
- Raises:
ValueError – Raised if the expression cannot be mapped to this: form (i.e.,
RangedExpression
constraints with variable lower or upper bounds.
- to_dense_data()
TODO
- type()
DEPRECATED.
Return the class type for this component
Deprecated since version 5.7: Component.type() method has been replaced by the .ctype property.
- uslack()
- Returns the value of U-f(x) for constraints of the form:
(L <=) f(x) <= U U >= f(x) (>= L)
- valid_model_component()
Return True if this can be used as a model component.
- values(sort=<SortComponents.UNSORTED: 0>, ordered=NOTSET)
Return an iterator of the component data objects
- Parameters:
sort (bool or SortComponents) – Iterate over the declared component values in a specified sorted order. See
SortComponents
for valid options and descriptions.ordered (bool) – DEPRECATED: Please use sort=SortComponents.ORDERED_INDICES. If True, then the values are returned in a deterministic order (using the underlying set’s ordered_iter().
- property active
Return the active attribute
- property body
The body (variable portion) of a constraint expression.
- property ctype
Return the class type for this component
- property expr
Return the expression associated with this constraint.
- property local_name
Get the component name only within the context of the immediate parent container.
- property lower
The lower bound of a constraint expression.
This is the fixed lower bound of a Constraint as a Pyomo expression. This may contain potentially variable terms that are currently fixed. If there is no lower bound, this will return None.
- property name
Get the fully qualified component name.
- property upper
Access the upper bound of a constraint expression.
This is the fixed upper bound of a Constraint as a Pyomo expression. This may contain potentially variable terms that are currently fixed. If there is no upper bound, this will return None.