Set

(class from pyomo.core.base.set)

class pyomo.core.base.set.Set(*args, **kwds)[source]

Bases: IndexedComponent

A component used to index other Pyomo components.

This class provides a Pyomo component that is API-compatible with Python set objects, with additional features, including:

  1. Member validation and filtering. The user can declare domains and provide callback functions to validate set members and to filter (ignore) potential members.

  2. Set expressions. Operations on Set objects (&,|,*,-,^) produce Set expressions that preserve their references to the original Set objects so that updating the argument Sets implicitly updates the Set operator instance.

  3. Support for set operations with RangeSet instances (both finite and non-finite ranges).

Parameters:
  • initialize (initializer(iterable), optional) – The initial values to store in the Set when it is constructed. Values passed to initialize may be overridden by data passed to the construct() method.

  • dimen (initializer(int), optional) – Specify the Set’s arity (the required tuple length for all members of the Set), or None if no arity is enforced

  • ordered (bool or Set.InsertionOrder or Set.SortedOrder or function) –

    Specifies whether the set is ordered. Possible values are:

    False

    Unordered

    True

    Ordered by insertion order

    Set.InsertionOrder

    Ordered by insertion order [default]

    Set.SortedOrder

    Ordered by sort order

    <function>

    Ordered with this comparison function

  • within (initialiser(set), optional) – A set that defines the valid values that can be contained in this set. If the latter is indexed, the former can be indexed or non-indexed, in which case it applies to all indices.

  • domain (initializer(set), optional) – A set that defines the valid values that can be contained in this set

  • bounds (initializer(tuple), optional) – A tuple that specifies the bounds for valid Set values (accepts 1-, 2-, or 3-tuple RangeSet arguments)

  • filter (initializer(rule), optional) –

    A rule for determining membership in this set. This has the functional form:

    f: Block, *data -> bool

    and returns True if the data belongs in the set. Set will quietly ignore any values where filter returns False.

  • validate (initializer(rule), optional) –

    A rule for validating membership in this set. This has the functional form:

    f: Block, *data -> bool

    and returns True if the data belongs in the set. Set will raise a ValueError for any values where validate returns False.

  • name (str, optional) – The name of the set

  • doc (str, optional) – A text string describing this component

Notes

Note

domain=, within=, and bounds= all provide restrictions on the valid set values. If more than one is specified, Set values will be restricted to the intersection of domain, within, and bounds.

__init__(*args, **kwds)[source]

Methods

__init__(*args, **kwds)

check_values()

DEPRECATED.

clear()

Clear the data in this component

clear_suffix_value(suffix_or_name[, expand])

Clear the suffix value for this component data

cname(*args, **kwds)

DEPRECATED.

construct([data])

API definition for constructing components

dim()

Return the dimension of the index

display([ostream, verbose, prefix])

get_suffix_value(suffix_or_name[, default])

Get the suffix value for this component data

getname([fully_qualified, name_buffer, ...])

Returns the component name associated with this object.

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

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.

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, ordered])

Return an iterator of (index,data) component data tuples

iteritems()

DEPRECATED.

iterkeys()

DEPRECATED.

itervalues()

DEPRECATED.

keys([sort, ordered])

Return an iterator over the component data keys

model()

Returns the model associated with this object.

parent_block()

Returns the parent of this object.

parent_component()

Returns the component associated with this object.

pprint([ostream, verbose, prefix])

Print component information

reconstruct([data])

REMOVED: reconstruct() was removed in Pyomo 6.0.

root_block()

Return self.model()

set_suffix_value(suffix_or_name, value[, expand])

Set the suffix value for this component data

set_value(value)

Set the value of a scalar component.

to_dense_data()

TODO

type()

DEPRECATED.

valid_model_component()

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

values([sort, ordered])

Return an iterator of the component data objects

Attributes

active

Return the active attribute

ctype

Return the class type for this component

local_name

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

name

Get the fully qualified component name.

Member Documentation

check_values()[source]

DEPRECATED.

Verify that the values in this set are valid.

Deprecated since version 5.7: check_values() is deprecated: Sets only contain valid members

clear()

Clear the data in this component

clear_suffix_value(suffix_or_name, expand=True)

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

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:
  • fully_qualified (bool) – Generate full name from nested block names

  • relative_to (Block) – Generate fully_qualified names relative to the specified 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(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(), and items() 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()

Returns the model associated with this object.

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)

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

Set the value of a scalar component.

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.

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 ctype

Return the class type for this component

property local_name

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

property name

Get the fully qualified component name.