VarData
(class from pyomo.core.base.var
)
- class pyomo.core.base.var.VarData(component=None)[source]
Bases:
ComponentData
,NumericValue
This class defines the data for a single variable.
Methods
__init__
([component])clear
()clear_suffix_value
(suffix_or_name[, expand])Set the suffix value for this component data
cname
(*args, **kwds)DEPRECATED.
copy
(src)fix
([value, skip_validation])Fix the value of this variable (treat as nonvariable)
free
()Alias for
unfix()
get_suffix_value
(suffix_or_name[, default])Get the suffix value for this component data
Return the units for this variable entry.
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 infinityindex
()Returns the index of this ComponentData instance relative to the parent component index set.
Returns True when the domain is restricted to Binary values.
Return True if this class is a Pyomo component
Returns False because this is not a constant in an expression.
Returns True when the domain is a continuous real range
is_expression_type
([expression_system])Return True if this numeric value is an expression
is_fixed
()Returns True if this variable is fixed, otherwise returns False.
Return true if this component is indexed
Returns True when the domain is a contiguous integer range.
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
Returns True because this is a variable.
Return True if this object is a reference.
DEPRECATED.
Returns True because this is a variable.
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.
Return the polynomial degree of the expression.
pprint
([ostream, verbose, prefix])Print component information
set_suffix_value
(suffix_or_name, value[, expand])Set the suffix value for this component data
set_value
(val[, skip_validation])Set the current variable value.
setlb
(val)Set the lower bound for this variable after validating that the value is fixed (or None).
setub
(val)Set the upper bound for this variable after validating that the value is fixed (or None).
to_string
([verbose, labeler, smap, ...])Return a string representation of the expression tree.
type
()DEPRECATED.
unfix
()Unfix this variable (treat as variable in solver interfaces)
Attributes
Return the active attribute
Returns (or set) the tuple (lower bound, upper bound).
Return the class type for this component
Return (or set) the domain for this variable.
Return (or set) the fixed indicator for this variable.
Return (or set) the numeric value of the variable lower bound.
Get the component name only within the context of the immediate parent container.
Return (or set) an expression for the variable lower bound.
Get the fully qualified component name.
The stale status for this variable.
Return (or set) the numeric value of the variable upper bound.
Return (or set) an expression for the variable upper bound.
Return (or set) the value for this variable.
Member Documentation
- 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.
- fix(value=NOTSET, skip_validation=False)[source]
Fix the value of this variable (treat as nonvariable)
This sets the
fixed
indicator to True. Ifvalue
is provided, the value (and theskip_validation
flag) are first passed toset_value()
.
- get_suffix_value(suffix_or_name, default=None)
Get the suffix value for this component data
- getname(fully_qualified=False, name_buffer=None, relative_to=None)
Return a string with the component name and index
- 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.
- is_component_type()
Return True if this class is a Pyomo component
- 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 object is a reference.
- is_relational()
DEPRECATED.
Return True if this numeric value represents a relational expression.
Deprecated since version 6.4.3: is_relational() is deprecated in favor of is_expression_type(ExpressionType.RELATIONAL)
- 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.
- polynomial_degree()
Return the polynomial degree of the expression.
- Returns:
None
- pprint(ostream=None, verbose=False, prefix='')
Print component information
Note that this method is generally only reachable through ComponentData objects in an IndexedComponent container. Components, including unindexed Component derivatives and both scalar and indexed IndexedComponent derivatives will see
Component.pprint()
- set_suffix_value(suffix_or_name, value, expand=True)
Set the suffix value for this component data
- set_value(val, skip_validation=False)[source]
Set the current variable value.
Set the value of this variable. The incoming value is converted to a numeric value (i.e., expressions are evaluated). If the variable has units, the incoming value is converted to the correct units before storing the value. The final value is checked against both the variable domain and bounds, and an exception is raised if the value is not valid. Domain and bounds checking can be bypassed by setting the
skip_validation
argument toTrue
.
- setlb(val)[source]
Set the lower bound for this variable after validating that the value is fixed (or None).
- setub(val)[source]
Set the upper bound for this variable after validating that the value is fixed (or None).
- to_string(verbose=None, labeler=None, smap=None, compute_values=False)
Return a string representation of the expression tree.
- Parameters:
verbose (bool) – If
True
, then the string representation consists of nested functions. Otherwise, the string representation is an infix algebraic equation. Defaults toFalse
.labeler – An object that generates string labels for non-constant in the expression tree. Defaults to
None
.smap – A SymbolMap instance that stores string labels for non-constant nodes in the expression tree. Defaults to
None
.compute_values (bool) – If
True
, then fixed expressions are evaluated and the string representation of the resulting value is returned.
- Returns:
A string representation for the expression tree.
- type()
DEPRECATED.
Return the class type for this component
Deprecated since version 5.7: Component.type() method has been replaced by the .ctype property.
- unfix()[source]
Unfix this variable (treat as variable in solver interfaces)
This sets the
fixed
indicator to False.
- property active
Return the active attribute
- property bounds
Returns (or set) the tuple (lower bound, upper bound).
This returns the current (numeric) values of the lower and upper bounds as a tuple. If there is no bound, returns None (and not +/-inf)
- property ctype
Return the class type for this component
- property domain
Return (or set) the domain for this variable.
- property fixed
Return (or set) the fixed indicator for this variable.
Alias for
is_fixed()
/fix()
/unfix()
.
- property lb
Return (or set) the numeric value of the variable lower bound.
- property local_name
Get the component name only within the context of the immediate parent container.
- property lower
Return (or set) an expression for the variable lower bound.
This returns a (not potentially variable) expression for the variable lower bound. This represents the tighter of the current domain and the constant or expression assigned to
lower
. Note that the expression will NOT automatically reflect changes to either the domain or the bound expression (e.g., because of assignment to eitherlower
ordomain
).
- property name
Get the fully qualified component name.
- property stale
The stale status for this variable.
Variables are “stale” if their current value was not updated as part of the most recent model update. A “model update” can be one of several things: a solver invocation, loading a previous solution, or manually updating a non-stale
Var
value.- Return type:
Notes
Fixed
Var
objects will be stale after invoking a solver (as their value was not updated by the solver).Updating a stale
Var
value will not cause other variable values to be come stale. However, updating the first non-staleVar
value after a solve or solution load will cause all other variables to be marked as stale
- property ub
Return (or set) the numeric value of the variable upper bound.
- property upper
Return (or set) an expression for the variable upper bound.
This returns a (not potentially variable) expression for the variable upper bound. This represents the tighter of the current domain and the constant or expression assigned to
upper
. Note that the expression will NOT automatically reflect changes to either the domain or the bound expression (e.g., because of assignment to eitherupper
ordomain
).
- property value
Return (or set) the value for this variable.