SimpleVar
(class from pyomo.core.base.var
)
- class pyomo.core.base.var.SimpleVar(*args, **kwargs)[source]
Bases:
ScalarVar
- __init__(*args, **kwd)
Methods
__init__
(*args, **kwd)add
(index)Add a variable with a particular 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 VarData objects for this variable
copy
(src)dim
()Return the dimension of the index
display
([ostream, verbose, prefix])extract_values
([include_fixed_values])Return a dictionary of index-value pairs.
fix
([value, skip_validation])Fix the value of this variable (treat as nonvariable)
Set the 'stale' attribute of every variable data object to True.
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.
get_values
([include_fixed_values])Return a dictionary of index-value pairs.
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
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.
Return True if this class has been constructed
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 component is a reference, where "reference" is interpreted as any component that does not own its own data.
DEPRECATED.
Returns True because this is a variable.
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
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
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
(val[, skip_validation])Set the current variable value.
set_values
(new_values[, skip_validation])Set the values of a dictionary.
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).
TODO
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)
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
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
- add(index)
Add a variable with a particular index.
- clear()
Clear the data in this component
- 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 VarData objects for this variable
- dim()
Return the dimension of the index
- extract_values(include_fixed_values=True)
Return a dictionary of index-value pairs.
- fix(value=NOTSET, skip_validation=False)
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()
.
- flag_as_stale()
Set the ‘stale’ attribute of every variable data object to True.
- get_suffix_value(suffix_or_name, default=None)
Get the suffix value for this component data
- get_units()
Return the units for this variable entry.
- get_values(include_fixed_values=True)
Return a dictionary of index-value pairs.
- 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_binary()
Returns True when the domain is restricted to Binary values.
- is_component_type()
Return True if this class is a Pyomo component
- is_constant()
Returns False because this is not a constant in an expression.
- is_constructed()
Return True if this class has been constructed
- is_continuous()
Returns True when the domain is a continuous real range
- is_expression_type(expression_system=None)
Return True if this numeric value is an expression
- is_fixed()
Returns True if this variable is fixed, otherwise returns False.
- is_indexed()
Return true if this component is indexed
- is_integer()
Returns True when the domain is a contiguous integer range.
- 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_potentially_variable()
Returns True because this is a variable.
- 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_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)
- is_variable_type()
Returns True because this is a variable.
- 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()).
- 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
- 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
- set_value(val, skip_validation=False)
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
.
- set_values(new_values, skip_validation=False)
Set the values of a dictionary.
The default behavior is to validate the values in the dictionary.
- 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_dense_data()
TODO
- 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()
Unfix this variable (treat as variable in solver interfaces)
This sets the
fixed
indicator to False.
- 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 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.