AML Library Reference

The following modeling components make up the core of the Pyomo Algebraic Modeling Language (AML). These classes are all available through the pyomo.environ namespace.

ConcreteModel(*args, **kwds) A concrete optimization model that does not defer construction of components.
AbstractModel(*args, **kwds) An abstract optimization model that defers construction of components.
Block(*args, **kwargs) Blocks are indexed components that contain other components (including blocks).
Set(*args, **kwds) A set object that is used to index other Pyomo objects.
RangeSet(*args, **kwds) A set that represents a list of numeric values.
Param(*args, **kwd) A parameter value, which may be defined over an index.
Var(*args, **kwd) A numeric variable, which may be defined over an index.
Objective(*args, **kwargs) This modeling component defines an objective expression.
Constraint(*args, **kwargs) This modeling component defines a constraint expression using a rule function.
Reference(reference[, ctype]) Creates a component that references other components

AML Component Documentation

class pyomo.environ.ConcreteModel(*args, **kwds)[source]

Bases: pyomo.core.base.PyomoModel.Model

A concrete optimization model that does not defer construction of components.

activate()

Set the active attribute to True

active

Return the active attribute

add_component(name, val)

Add a component ‘name’ to the block.

This method assumes that the attribute is not in the model.

block_data_objects(active=None, sort=False, descend_into=True, descent_order=None)

This method returns a generator that iterates through the current block and recursively all sub-blocks. This is semantically equivalent to

component_data_objects(Block, …)
clear()

Clear the data in this component

clear_suffix_value(suffix_or_name, expand=True)

Set the suffix value for this component data

clone()

TODO

collect_ctypes(active=None, descend_into=True)

Count all component types stored on or under this block.

Parameters:
  • active (True/None) – Set to True to indicate that only active components should be counted. The default value of None indicates that all components (including those that have been deactivated) should be counted.
  • descend_into (bool) – Indicates whether or not component types should be counted on sub-blocks. Default is True.

Returns: A set of component types.

component(name_or_object)

Return a child component of this block.

If passed a string, this will return the child component registered by that name. If passed a component, this will return that component IFF the component is a child of this block. Returns None on lookup failure.

component_data_iterindex(ctype=None, active=None, sort=False, descend_into=True, descent_order=None)

Return a generator that returns a tuple for each component data object in a block. By default, this generator recursively descends into sub-blocks. The tuple is

((component name, index value), _ComponentData)
component_data_objects(ctype=None, active=None, sort=False, descend_into=True, descent_order=None)

Return a generator that iterates through the component data objects for all components in a block. By default, this generator recursively descends into sub-blocks.

component_map(ctype=None, active=None, sort=False)

Returns a PseudoMap of the components in this block.

ctype
None - All components ComponentType - A single ComponentType Iterable - Iterate to generate ComponentTypes
active is None, True, False
None - All True - Active False - Inactive
sort is True, False
True - Maps to Block.alphabetizeComponentAndIndex False - Maps to Block.declarationOrder
component_objects(ctype=None, active=None, sort=False, descend_into=True, descent_order=None)

Return a generator that iterates through the component objects in a block. By default, the generator recursively descends into sub-blocks.

compute_statistics(active=True)

Compute model statistics

construct(data=None)

Initialize the block

contains_component(ctype)

Return True if the component type is in _ctypes and … TODO.

create(filename=None, **kwargs)

Create a concrete instance of this Model, possibly using data read in from a file.

create_instance(filename=None, data=None, name=None, namespace=None, namespaces=None, profile_memory=0, report_timing=False, **kwds)

Create a concrete instance of an abstract model, possibly using data read in from a file.

Parameters:
  • filename (str, optional) – The name of a Pyomo Data File that will be used to load data into the model.
  • data (dict, optional) – A dictionary containing initialization data for the model to be used if there is no filename
  • name (str, optional) – The name given to the model.
  • namespace (str, optional) – A namespace used to select data.
  • namespaces (list, optional) – A list of namespaces used to select data.
  • profile_memory (int, optional) – A number that indicates the profiling level.
  • report_timing (bool, optional) – Report timing statistics during construction.
deactivate()

Set the active attribute to False

del_component(name_or_object)

Delete a component from this block.

dim()

Return the dimension of the index

display(filename=None, ostream=None, prefix='')

Display values in the block

find_component(label_or_component)

Return a block component given a name.

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

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. This method is not intended to be a fast method; it should be used rarely, primarily in cases of label formulation.

index_set()

Return the index set

is_component_type()

Return True if this class is a Pyomo component

is_constructed()

A boolean indicating whether or not all active components of the input model have been properly constructed.

is_indexed()

Return true if this component is indexed

items()

Return a list (index,data) tuples from the dictionary

iteritems()

Return an iterator of (index,data) tuples from the dictionary

iterkeys()

Return an iterator of the keys in the dictionary

itervalues()

Return an iterator of the component data objects in the dictionary

keys()

Return a list of keys in the dictionary

load(arg, namespaces=[None], profile_memory=0, report_timing=None)

Load the model with data from a file, dictionary or DataPortal object.

local_name

Get the component name only within the context of the immediate parent container.

model()

Return the model of the component that owns this data.

name

Get the fully qualifed component name.

parent_block()

Return the parent of the component that owns this data.

parent_component()

Returns the component associated with this object.

pprint(filename=None, ostream=None, verbose=False, prefix='')

Print block information

preprocess(preprocessor=None)

Apply the preprocess plugins defined by the user

preprocessor_ep = <ExtensionPoint IPyomoPresolver env=pyomo>
reclassify_component_type(name_or_object, new_ctype, preserve_declaration_order=True)

TODO

reconstruct(data=None)

Re-construct model expressions

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)

Set the value of a scalar component.

to_dense_data()

TODO

to_string(verbose=None, labeler=None, smap=None, compute_values=False)

Return a string representation of this component, applying the labeler if passed one.

type()

Return the class type for this component

valid_model_component()

Return True if this can be used as a model component.

valid_problem_types()

This method allows the pyomo.opt convert function to work with a Model object.

values()

Return a list of the component data objects in the dictionary

write(filename=None, format=None, solver_capability=None, io_options={})

Write the model to a file, with a given format.

class pyomo.environ.AbstractModel(*args, **kwds)[source]

Bases: pyomo.core.base.PyomoModel.Model

An abstract optimization model that defers construction of components.

activate()

Set the active attribute to True

active

Return the active attribute

add_component(name, val)

Add a component ‘name’ to the block.

This method assumes that the attribute is not in the model.

block_data_objects(active=None, sort=False, descend_into=True, descent_order=None)

This method returns a generator that iterates through the current block and recursively all sub-blocks. This is semantically equivalent to

component_data_objects(Block, …)
clear()

Clear the data in this component

clear_suffix_value(suffix_or_name, expand=True)

Set the suffix value for this component data

clone()

TODO

collect_ctypes(active=None, descend_into=True)

Count all component types stored on or under this block.

Parameters:
  • active (True/None) – Set to True to indicate that only active components should be counted. The default value of None indicates that all components (including those that have been deactivated) should be counted.
  • descend_into (bool) – Indicates whether or not component types should be counted on sub-blocks. Default is True.

Returns: A set of component types.

component(name_or_object)

Return a child component of this block.

If passed a string, this will return the child component registered by that name. If passed a component, this will return that component IFF the component is a child of this block. Returns None on lookup failure.

component_data_iterindex(ctype=None, active=None, sort=False, descend_into=True, descent_order=None)

Return a generator that returns a tuple for each component data object in a block. By default, this generator recursively descends into sub-blocks. The tuple is

((component name, index value), _ComponentData)
component_data_objects(ctype=None, active=None, sort=False, descend_into=True, descent_order=None)

Return a generator that iterates through the component data objects for all components in a block. By default, this generator recursively descends into sub-blocks.

component_map(ctype=None, active=None, sort=False)

Returns a PseudoMap of the components in this block.

ctype
None - All components ComponentType - A single ComponentType Iterable - Iterate to generate ComponentTypes
active is None, True, False
None - All True - Active False - Inactive
sort is True, False
True - Maps to Block.alphabetizeComponentAndIndex False - Maps to Block.declarationOrder
component_objects(ctype=None, active=None, sort=False, descend_into=True, descent_order=None)

Return a generator that iterates through the component objects in a block. By default, the generator recursively descends into sub-blocks.

compute_statistics(active=True)

Compute model statistics

construct(data=None)

Initialize the block

contains_component(ctype)

Return True if the component type is in _ctypes and … TODO.

create(filename=None, **kwargs)

Create a concrete instance of this Model, possibly using data read in from a file.

create_instance(filename=None, data=None, name=None, namespace=None, namespaces=None, profile_memory=0, report_timing=False, **kwds)

Create a concrete instance of an abstract model, possibly using data read in from a file.

Parameters:
  • filename (str, optional) – The name of a Pyomo Data File that will be used to load data into the model.
  • data (dict, optional) – A dictionary containing initialization data for the model to be used if there is no filename
  • name (str, optional) – The name given to the model.
  • namespace (str, optional) – A namespace used to select data.
  • namespaces (list, optional) – A list of namespaces used to select data.
  • profile_memory (int, optional) – A number that indicates the profiling level.
  • report_timing (bool, optional) – Report timing statistics during construction.
deactivate()

Set the active attribute to False

del_component(name_or_object)

Delete a component from this block.

dim()

Return the dimension of the index

display(filename=None, ostream=None, prefix='')

Display values in the block

find_component(label_or_component)

Return a block component given a name.

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

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. This method is not intended to be a fast method; it should be used rarely, primarily in cases of label formulation.

index_set()

Return the index set

is_component_type()

Return True if this class is a Pyomo component

is_constructed()

A boolean indicating whether or not all active components of the input model have been properly constructed.

is_indexed()

Return true if this component is indexed

items()

Return a list (index,data) tuples from the dictionary

iteritems()

Return an iterator of (index,data) tuples from the dictionary

iterkeys()

Return an iterator of the keys in the dictionary

itervalues()

Return an iterator of the component data objects in the dictionary

keys()

Return a list of keys in the dictionary

load(arg, namespaces=[None], profile_memory=0, report_timing=None)

Load the model with data from a file, dictionary or DataPortal object.

local_name

Get the component name only within the context of the immediate parent container.

model()

Return the model of the component that owns this data.

name

Get the fully qualifed component name.

parent_block()

Return the parent of the component that owns this data.

parent_component()

Returns the component associated with this object.

pprint(filename=None, ostream=None, verbose=False, prefix='')

Print block information

preprocess(preprocessor=None)

Apply the preprocess plugins defined by the user

preprocessor_ep = <ExtensionPoint IPyomoPresolver env=pyomo>
reclassify_component_type(name_or_object, new_ctype, preserve_declaration_order=True)

TODO

reconstruct(data=None)

Re-construct model expressions

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)

Set the value of a scalar component.

to_dense_data()

TODO

to_string(verbose=None, labeler=None, smap=None, compute_values=False)

Return a string representation of this component, applying the labeler if passed one.

type()

Return the class type for this component

valid_model_component()

Return True if this can be used as a model component.

valid_problem_types()

This method allows the pyomo.opt convert function to work with a Model object.

values()

Return a list of the component data objects in the dictionary

write(filename=None, format=None, solver_capability=None, io_options={})

Write the model to a file, with a given format.

class pyomo.environ.Block(*args, **kwargs)[source]

Bases: pyomo.core.base.indexed_component.ActiveIndexedComponent

Blocks are indexed components that contain other components (including blocks). Blocks have a global attribute that defines whether construction is deferred. This applies to all components that they contain except blocks. Blocks contained by other blocks use their local attribute to determine whether construction is deferred.

activate()

Set the active attribute to True

active

Return the active attribute

clear()

Clear the data in this component

clear_suffix_value(suffix_or_name, expand=True)

Clear the suffix value for this component data

construct(data=None)[source]

Initialize the block

deactivate()

Set the active attribute to False

dim()

Return the dimension of the index

display(filename=None, ostream=None, prefix='')[source]

Display values in the block

find_component(label_or_component)[source]

Return a block component given a name.

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)

Returns the component name associated with this object.

Parameters:
  • Generate full name from nested block names (fully_qualified) –
  • Can be used to optimize iterative name (name_buffer) – generation (using a dictionary)
  • When generating a fully qualified name, (relative_to) – stop at this block.
id_index_map()

Return an dictionary id->index for all ComponentData instances.

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_indexed()

Return true if this component is indexed

items()

Return a list (index,data) tuples from the dictionary

iteritems()

Return an iterator of (index,data) tuples from the dictionary

iterkeys()

Return an iterator of the keys in the dictionary

itervalues()

Return an iterator of the component data objects in the dictionary

keys()

Return a list of keys in the dictionary

local_name

Get the component name only within the context of the immediate parent container.

model()

Returns the model associated with this object.

name

Get the fully qualifed component name.

parent_block()

Returns the parent of this object.

parent_component()

Returns the component associated with this object.

pprint(filename=None, ostream=None, verbose=False, prefix='')[source]

Print block information

reconstruct(data=None)

Re-construct model expressions

root_block()

Return self.model()

set_suffix_value(suffix_or_name, value, expand=True)

Set the suffix value for this component data

set_value(value)

Set the value of a scalar component.

to_dense_data()

TODO

to_string(verbose=None, labeler=None, smap=None, compute_values=False)

Return the component name

type()

Return the class type for this component

valid_model_component()

Return True if this can be used as a model component.

values()

Return a list of the component data objects in the dictionary

class pyomo.environ.Constraint(*args, **kwargs)[source]

Bases: pyomo.core.base.indexed_component.ActiveIndexedComponent

This modeling component defines a constraint expression using a rule function.

Constructor arguments:
expr
A Pyomo expression for this constraint
rule
A function that is used to construct constraint expressions
doc
A text string describing this component
name
A name for this component
Public class attributes:
doc
A text string describing this component
name
A name for this component
active
A boolean that is true if this component will be used to construct a model instance
rule
The rule used to initialize the constraint(s)
Private class attributes:
_constructed
A boolean that is true if this component has been constructed
_data
A dictionary from the index set to component data objects
_index
The set of valid indices
_implicit_subsets
A tuple of set objects that represents the index set
_model
A weakref to the model that owns this component
_parent
A weakref to the parent block that owns this component
_type
The class type for the derived subclass
activate()

Set the active attribute to True

active

Return the active attribute

clear()

Clear the data in this component

clear_suffix_value(suffix_or_name, expand=True)

Clear the suffix value for this component data

construct(data=None)[source]

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)[source]

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

getname(fully_qualified=False, name_buffer=None, relative_to=None)

Returns the component name associated with this object.

Parameters:
  • Generate full name from nested block names (fully_qualified) –
  • Can be used to optimize iterative name (name_buffer) – generation (using a dictionary)
  • When generating a fully qualified name, (relative_to) – stop at this block.
id_index_map()

Return an dictionary id->index for all ComponentData instances.

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_indexed()

Return true if this component is indexed

items()

Return a list (index,data) tuples from the dictionary

iteritems()

Return an iterator of (index,data) tuples from the dictionary

iterkeys()

Return an iterator of the keys in the dictionary

itervalues()

Return an iterator of the component data objects in the dictionary

keys()

Return a list of keys in the dictionary

local_name

Get the component name only within the context of the immediate parent container.

model()

Returns the model associated with this object.

name

Get the fully qualifed component name.

parent_block()

Returns the parent of this object.

parent_component()

Returns the component associated with this object.

pprint(ostream=None, verbose=False, prefix='')

Print component information

reconstruct(data=None)

Re-construct model expressions

root_block()

Return self.model()

set_suffix_value(suffix_or_name, value, expand=True)

Set the suffix value for this component data

set_value(value)

Set the value of a scalar component.

to_dense_data()

TODO

to_string(verbose=None, labeler=None, smap=None, compute_values=False)

Return the component name

type()

Return the class type for this component

valid_model_component()

Return True if this can be used as a model component.

values()

Return a list of the component data objects in the dictionary

class pyomo.environ.Objective(*args, **kwargs)[source]

Bases: pyomo.core.base.indexed_component.ActiveIndexedComponent

This modeling component defines an objective expression.

Note that this is a subclass of NumericValue to allow objectives to be used as part of expressions.

Constructor arguments:
expr
A Pyomo expression for this objective
rule
A function that is used to construct objective expressions
sense
Indicate whether minimizing (the default) or maximizing
doc
A text string describing this component
name
A name for this component
Public class attributes:
doc
A text string describing this component
name
A name for this component
active
A boolean that is true if this component will be used to construct a model instance
rule
The rule used to initialize the objective(s)
sense
The objective sense
Private class attributes:
_constructed
A boolean that is true if this component has been constructed
_data
A dictionary from the index set to component data objects
_index
The set of valid indices
_implicit_subsets
A tuple of set objects that represents the index set
_model
A weakref to the model that owns this component
_parent
A weakref to the parent block that owns this component
_type
The class type for the derived subclass
activate()

Set the active attribute to True

active

Return the active attribute

clear()

Clear the data in this component

clear_suffix_value(suffix_or_name, expand=True)

Clear the suffix value for this component data

construct(data=None)[source]

Construct the expression(s) for this objective.

deactivate()

Set the active attribute to False

dim()

Return the dimension of the index

display(prefix='', ostream=None)[source]

Provide a verbose display of this object

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)

Returns the component name associated with this object.

Parameters:
  • Generate full name from nested block names (fully_qualified) –
  • Can be used to optimize iterative name (name_buffer) – generation (using a dictionary)
  • When generating a fully qualified name, (relative_to) – stop at this block.
id_index_map()

Return an dictionary id->index for all ComponentData instances.

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_indexed()

Return true if this component is indexed

items()

Return a list (index,data) tuples from the dictionary

iteritems()

Return an iterator of (index,data) tuples from the dictionary

iterkeys()

Return an iterator of the keys in the dictionary

itervalues()

Return an iterator of the component data objects in the dictionary

keys()

Return a list of keys in the dictionary

local_name

Get the component name only within the context of the immediate parent container.

model()

Returns the model associated with this object.

name

Get the fully qualifed component name.

parent_block()

Returns the parent of this object.

parent_component()

Returns the component associated with this object.

pprint(ostream=None, verbose=False, prefix='')

Print component information

reconstruct(data=None)

Re-construct model expressions

root_block()

Return self.model()

set_suffix_value(suffix_or_name, value, expand=True)

Set the suffix value for this component data

set_value(value)

Set the value of a scalar component.

to_dense_data()

TODO

to_string(verbose=None, labeler=None, smap=None, compute_values=False)

Return the component name

type()

Return the class type for this component

valid_model_component()

Return True if this can be used as a model component.

values()

Return a list of the component data objects in the dictionary

class pyomo.environ.Param(*args, **kwd)[source]

Bases: pyomo.core.base.indexed_component.IndexedComponent

A parameter value, which may be defined over an index.

Constructor Arguments:
name
The name of this parameter
index
The index set that defines the distinct parameters. By default, this is None, indicating that there is a single parameter.
domain
A set that defines the type of values that each parameter must be.
within
A set that defines the type of values that each parameter must be.
validate
A rule for validating this parameter w.r.t. data that exists in the model
default
A scalar, rule, or dictionary that defines default values for this parameter
initialize
A dictionary or rule for setting up this parameter with existing model data
active

Return the active attribute

clear()

Clear the data in this component

clear_suffix_value(suffix_or_name, expand=True)

Clear the suffix value for this component data

construct(data=None)[source]

Initialize this component.

A parameter is constructed using the initial data or the data loaded from an external source. We first set all the values based on self._rule, and then allow the data dictionary to overwrite anything.

Note that we allow an undefined Param value to be constructed. We throw an exception if a user tries to use an uninitialized Param.

default()[source]

Return the value of the parameter default.

Possible values:
None
No default value is provided.
Numeric
A constant value that is the default value for all undefined parameters.
Function
f(model, i) returns the value for the default value for parameter i
dim()

Return the dimension of the index

extract_values()[source]

A utility to extract all index-value pairs defined for this parameter, returned as a dictionary.

This method is useful in contexts where key iteration and repeated __getitem__ calls are too expensive to extract the contents of a parameter.

extract_values_sparse()[source]

A utility to extract all index-value pairs defined with non-default values, returned as a dictionary.

This method is useful in contexts where key iteration and repeated __getitem__ calls are too expensive to extract the contents of a parameter.

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)

Returns the component name associated with this object.

Parameters:
  • Generate full name from nested block names (fully_qualified) –
  • Can be used to optimize iterative name (name_buffer) – generation (using a dictionary)
  • When generating a fully qualified name, (relative_to) – stop at this block.
id_index_map()

Return an dictionary id->index for all ComponentData instances.

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()[source]

Returns False because this is not an expression

is_indexed()

Return true if this component is indexed

items()

Return a list (index,data) tuples from the dictionary

iteritems()

Return an iterator of (index,data) tuples from the dictionary

iterkeys()

Return an iterator of the keys in the dictionary

itervalues()

Return an iterator of the component data objects in the dictionary

keys()

Return a list of keys in the dictionary

local_name

Get the component name only within the context of the immediate parent container.

model()

Returns the model associated with this object.

name

Get the fully qualifed component name.

parent_block()

Returns the parent of this object.

parent_component()

Returns the component associated with this object.

pprint(ostream=None, verbose=False, prefix='')

Print component information

reconstruct(data=None)[source]

Reconstruct this parameter object. This is particularly useful for cases where an initialize rule is provided. An initialize rule can return an expression that is a function of other parameters, so reconstruction can account for changes in dependent parameters.

Only mutable parameters can be reconstructed. Otherwise, the changes would not be propagated into expressions in objectives or constraints.

root_block()

Return self.model()

set_default(val)[source]

Perform error checks and then set the default value for this parameter.

NOTE: this test will not validate the value of function return values.

set_suffix_value(suffix_or_name, value, expand=True)

Set the suffix value for this component data

set_value(value)

Set the value of a scalar component.

sparse_items()[source]

Return a list (index,data) tuples for defined parameters

sparse_iteritems()[source]

Return an iterator of (index,data) tuples for defined parameters

sparse_iterkeys()[source]

Return an iterator for the keys in the defined parameters

sparse_itervalues()[source]

Return an iterator for the defined param data objects

sparse_keys()[source]

Return a list of keys in the defined parameters

sparse_values()[source]

Return a list of the defined param data objects

store_values(new_values, check=True)[source]

A utility to update a Param with a dictionary or scalar.

If check=True, then both the index and value are checked through the __getitem__ method. Using check=False should only be used by developers!

to_dense_data()

TODO

to_string(verbose=None, labeler=None, smap=None, compute_values=False)

Return the component name

type()

Return the class type for this component

valid_model_component()

Return True if this can be used as a model component.

values()

Return a list of the component data objects in the dictionary

class pyomo.environ.RangeSet(*args, **kwds)[source]

Bases: pyomo.core.base.sets.OrderedSimpleSet

A set that represents a list of numeric values.

active

Return the active attribute

add(*args)

Add one or more elements to a set.

bounds()

Return bounds information. The default value is ‘None’, which indicates that this set does not contain bounds. Otherwise, this is assumed to be a tuple: (lower, upper).

check_values()

Verify that the values in this set are valid.

clear()

Clear that data in this component.

clear_suffix_value(suffix_or_name, expand=True)

Clear the suffix value for this component data

construct(values=None)[source]

Initialize set data

cross(*args)

Return the cross-product between this set and one or more sets

data()[source]

The underlying set data.

difference(*args)

Return the difference between this set with one or more sets

dim()

Return the dimension of the index

discard(element)

Remove an element from the set.

If the element is not a member, do nothing.

first()[source]

The first element is the lower bound

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)

Returns the component name associated with this object.

Parameters:
  • Generate full name from nested block names (fully_qualified) –
  • Can be used to optimize iterative name (name_buffer) – generation (using a dictionary)
  • When generating a fully qualified name, (relative_to) – stop at this block.
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. This method is not intended to be a fast method; it should be used rarely, primarily in cases of label formulation.

index_set()

Return the index set

intersection(*args)

Return the intersection of this set with one or more sets

is_component_type()

Return True if this class is a Pyomo component

is_constructed()

Return True if this class has been constructed

is_indexed()

Return true if this component is indexed

isdisjoint(other)

Return True if the set has no elements in common with ‘other’. Sets are disjoint if and only if their intersection is the empty set.

issubset(other)

Return True if the set is a subset of ‘other’.

issuperset(other)

Return True if the set is a superset of ‘other’.

Note that we do not simply call other.issubset(self) because ‘other’ may not be a Set instance.

items()

Return a list (index,data) tuples from the dictionary

iteritems()

Return an iterator of (index,data) tuples from the dictionary

iterkeys()

Return an iterator of the keys in the dictionary

itervalues()

Return an iterator of the component data objects in the dictionary

keys()

Return a list of keys in the dictionary

last()[source]

The last element is the upper bound

local_name

Get the component name only within the context of the immediate parent container.

member(key)[source]

Return the value associated with this key.

model()

Returns the model associated with this object.

name

Get the fully qualifed component name.

next(match_element, k=1)

Return the next element in the set. The default behavior is to return the very next element. The k option can specify how many steps are taken to get the next element.

If the next element is beyond the end of the set, then an exception is raised.

nextw(match_element, k=1)

Return the next element in the set. The default behavior is to return the very next element. The k option can specify how many steps are taken to get the next element.

If the next element goes beyond the end of the list of elements in the set, then this wraps around to the beginning of the list.

ord(match_element)

Return the position index of the input value. The position indices start at 1.

parent_block()

Returns the parent of this object.

parent_component()

Returns the component associated with this object.

pprint(ostream=None, verbose=False, prefix='')

Print component information

prev(match_element, k=1)

Return the previous element in the set. The default behavior is to return the element immediately prior to the specified element. The k option can specify how many steps are taken to get the previous element.

If the previous element is before the start of the set, then an exception is raised.

prevw(match_element, k=1)

Return the previous element in the set. The default behavior is to return the element immediately prior to the specified element. The k option can specify how many steps are taken to get the previous element.

If the previous element is before the start of the set, then this wraps around to the end of the list.

reconstruct(data=None)

Re-construct model expressions

remove(element)

Remove an element from the set.

If the element is not a member, raise an error.

root_block()

Return self.model()

set_suffix_value(suffix_or_name, value, expand=True)

Set the suffix value for this component data

set_value(value)

Set the value of a scalar component.

symmetric_difference(*args)

Return the symmetric difference of this set with one or more sets

to_dense_data()

TODO

to_string(verbose=None, labeler=None, smap=None, compute_values=False)

Return the component name

type()

Return the class type for this component

union(*args)

Return the union of this set with one or more sets.

valid_model_component()

Return True if this can be used as a model component.

values()

Return a list of the component data objects in the dictionary

pyomo.environ.Reference(reference, ctype=<object object>)[source]

Creates a component that references other components

Reference generates a reference component; that is, an indexed component that does not contain data, but instead references data stored in other components as defined by a component slice. The ctype parameter sets the Component.type() of the resulting indexed component. If the ctype parameter is not set and all data identified by the slice (at construction time) share a common Component.type(), then that type is assumed. If either the ctype parameter is None or the data has more than one ctype, the resulting indexed component will have a ctype of IndexedComponent.

If the indices associated with wildcards in the component slice all refer to the same Set objects for all data identifed by the slice, then the resulting indexed component will be indexed by the product of those sets. However, if all data do not share common set objects, or only a subset of indices in a multidimentional set appear as wildcards, then the resulting indexed component will be indexed by a SetOf containing a _ReferenceSet for the slice.

Parameters:
  • reference (_IndexedComponent_slice) – component slice that defines the data to include in the Reference component
  • ctype (type [optional]) – the type used to create the resulting indexed component. If not specified, the data’s ctype will be used (if all data share a common ctype). If multiple data ctypes are found or type is None, then IndexedComponent will be used.

Examples

>>> from pyomo.environ import *
>>> m = ConcreteModel()
>>> @m.Block([1,2],[3,4])
... def b(b,i,j):
...     b.x = Var(bounds=(i,j))
...
>>> m.r1 = Reference(m.b[:,:].x)
>>> m.r1.pprint()
r1 : Size=4, Index=r1_index
    Key    : Lower : Value : Upper : Fixed : Stale : Domain
    (1, 3) :     1 :  None :     3 : False :  True :  Reals
    (1, 4) :     1 :  None :     4 : False :  True :  Reals
    (2, 3) :     2 :  None :     3 : False :  True :  Reals
    (2, 4) :     2 :  None :     4 : False :  True :  Reals

Reference components may also refer to subsets of the original data:

>>> m.r2 = Reference(m.b[:,3].x)
>>> m.r2.pprint()
r2 : Size=2, Index=b_index_0
    Key : Lower : Value : Upper : Fixed : Stale : Domain
      1 :     1 :  None :     3 : False :  True :  Reals
      2 :     2 :  None :     3 : False :  True :  Reals

Reference components may have wildcards at multiple levels of the model hierarchy:

>>> from pyomo.environ import *
>>> m = ConcreteModel()
>>> @m.Block([1,2])
... def b(b,i):
...     b.x = Var([3,4], bounds=(i,None))
...
>>> m.r3 = Reference(m.b[:].x[:])
>>> m.r3.pprint()
r3 : Size=4, Index=r3_index
    Key    : Lower : Value : Upper : Fixed : Stale : Domain
    (1, 3) :     1 :  None :  None : False :  True :  Reals
    (1, 4) :     1 :  None :  None : False :  True :  Reals
    (2, 3) :     2 :  None :  None : False :  True :  Reals
    (2, 4) :     2 :  None :  None : False :  True :  Reals

The resulting reference component may be used just like any other component. Changes to the stored data will be reflected in the original objects:

>>> m.r3[1,4] = 10
>>> m.b[1].x.pprint()
x : Size=2, Index=b[1].x_index
    Key : Lower : Value : Upper : Fixed : Stale : Domain
      3 :     1 :  None :  None : False :  True :  Reals
      4 :     1 :    10 :  None : False : False :  Reals
class pyomo.environ.Set(*args, **kwds)[source]

Bases: pyomo.core.base.indexed_component.IndexedComponent

A set object that is used to index other Pyomo objects.

This class has a similar look-and-feel as a Python set class. However, the set operations defined in this class return another abstract Set object. This class contains a concrete set, which can be initialized by the load() method.

Constructor Arguments:
name
The name of the set
doc
A text string describing this component
within
A set that defines the type of values that can be contained in this set
domain
A set that defines the type of values that can be contained in this set
initialize
A dictionary or rule for setting up this set with existing model data
validate
A rule for validating membership in this set. This has the functional form: f(data) -> bool, and returns true if the data belongs in the set
dimen
Specify the set’s arity, or None if no arity is enforced
virtual
If true, then this is a virtual set that does not store data using the class dictionary
bounds
A 2-tuple that specifies the range of possible set values.
ordered

Specifies whether the set is ordered. Possible values are

  • False: Unordered
  • True: Ordered by insertion order
  • InsertionOrder: Ordered by insertion order
  • SortedOrder: Ordered by sort order
  • <function>: Ordered with this comparison function
filter
A function that is used to filter set entries.
Public class attributes:
concrete
If True, then this set contains elements.(TODO)
dimen
The dimension of the data in this set.
doc
A text string describing this component
domain
A set that defines the type of values that can be contained in this set
filter
A function that is used to filter set entries.
initialize
A dictionary or rule for setting up this set with existing model data
ordered
Specifies whether the set is ordered.
validate
A rule for validating membership in this set.
virtual
If True, then this set does not store data using the class dictionary
active

Return the active attribute

clear()

Clear the data in this component

clear_suffix_value(suffix_or_name, expand=True)

Clear the suffix value for this component data

construct(data=None)

API definition for constructing components

dim()

Return the dimension of the index

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)

Returns the component name associated with this object.

Parameters:
  • Generate full name from nested block names (fully_qualified) –
  • Can be used to optimize iterative name (name_buffer) – generation (using a dictionary)
  • When generating a fully qualified name, (relative_to) – stop at this block.
id_index_map()

Return an dictionary id->index for all ComponentData instances.

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_indexed()

Return true if this component is indexed

items()

Return a list (index,data) tuples from the dictionary

iteritems()

Return an iterator of (index,data) tuples from the dictionary

iterkeys()

Return an iterator of the keys in the dictionary

itervalues()

Return an iterator of the component data objects in the dictionary

keys()

Return a list of keys in the dictionary

local_name

Get the component name only within the context of the immediate parent container.

model()

Returns the model associated with this object.

name

Get the fully qualifed component name.

parent_block()

Returns the parent of this object.

parent_component()

Returns the component associated with this object.

pprint(ostream=None, verbose=False, prefix='')

Print component information

reconstruct(data=None)

Re-construct model expressions

root_block()

Return self.model()

set_suffix_value(suffix_or_name, value, expand=True)

Set the suffix value for this component data

set_value(value)

Set the value of a scalar component.

to_dense_data()

TODO

to_string(verbose=None, labeler=None, smap=None, compute_values=False)

Return the component name

type()

Return the class type for this component

valid_model_component()

Return True if this can be used as a model component.

values()

Return a list of the component data objects in the dictionary

class pyomo.environ.Var(*args, **kwd)[source]

Bases: pyomo.core.base.indexed_component.IndexedComponent

A numeric variable, which may be defined over an index.

Parameters:
  • domain (Set or function, optional) – A Set that defines valid values for the variable (e.g., Reals, NonNegativeReals, Binary), or a rule that returns Sets. Defaults to Reals.
  • within (Set or function, optional) – An alias for domain.
  • bounds (tuple or function, optional) – A tuple of (lower, upper) bounds for the variable, or a rule that returns tuples. Defaults to (None, None).
  • initialize (float or function, optional) – The initial value for the variable, or a rule that returns initial values.
  • rule (float or function, optional) – An alias for initialize.
  • dense (bool, optional) – Instantiate all elements from index_set() when constructing the Var (True) or just the variables returned by initialize/rule (False). Defaults to True.
active

Return the active attribute

add(index)[source]

Add a variable with a particular index.

clear()

Clear the data in this component

clear_suffix_value(suffix_or_name, expand=True)

Clear the suffix value for this component data

construct(data=None)[source]

Construct this component.

dim()

Return the dimension of the index

extract_values(include_fixed_values=True)

Return a dictionary of index-value pairs.

flag_as_stale()[source]

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_values(include_fixed_values=True)[source]

Return a dictionary of index-value pairs.

getname(fully_qualified=False, name_buffer=None, relative_to=None)

Returns the component name associated with this object.

Parameters:
  • Generate full name from nested block names (fully_qualified) –
  • Can be used to optimize iterative name (name_buffer) – generation (using a dictionary)
  • When generating a fully qualified name, (relative_to) – stop at this block.
id_index_map()

Return an dictionary id->index for all ComponentData instances.

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()[source]

Returns False because this is not an expression

is_indexed()

Return true if this component is indexed

items()

Return a list (index,data) tuples from the dictionary

iteritems()

Return an iterator of (index,data) tuples from the dictionary

iterkeys()

Return an iterator of the keys in the dictionary

itervalues()

Return an iterator of the component data objects in the dictionary

keys()

Return a list of keys in the dictionary

local_name

Get the component name only within the context of the immediate parent container.

model()

Returns the model associated with this object.

name

Get the fully qualifed component name.

parent_block()

Returns the parent of this object.

parent_component()

Returns the component associated with this object.

pprint(ostream=None, verbose=False, prefix='')

Print component information

reconstruct(data=None)

Re-construct model expressions

root_block()

Return self.model()

set_suffix_value(suffix_or_name, value, expand=True)

Set the suffix value for this component data

set_value(value)

Set the value of a scalar component.

set_values(new_values, valid=False)[source]

Set the values of a dictionary.

The default behavior is to validate the values in the dictionary.

to_dense_data()

TODO

to_string(verbose=None, labeler=None, smap=None, compute_values=False)

Return the component name

type()

Return the class type for this component

valid_model_component()

Return True if this can be used as a model component.

values()

Return a list of the component data objects in the dictionary