ComponentSet

(class from pyomo.common.collections.component_set)

class pyomo.common.collections.component_set.ComponentSet(iterable=None)[source]

Bases: Mixin, MutableSet

This class is a replacement for set that allows Pyomo modeling components to be used as entries. The underlying hash is based on the Python id() of the object, which gets around the problem of hashing subclasses of NumericValue. This class is meant for creating sets of Pyomo components. The use of non-Pyomo components as entries should be avoided (as the behavior is undefined).

References to objects are kept around as long as they are entries in the container, so there is no need to worry about id() clashes.

We also override __setstate__ so that we can rebuild the container based on possibly updated object ids after a deepcopy or pickle.

* An instance of this class should never be deepcopied/pickled unless it is done so along with its component entries (e.g., as part of a block). *

__init__(iterable=None)[source]

Methods

__init__([iterable])

add(val)

Add an element.

clear()

Remove all elements from this set.

discard(val)

Remove an element.

isdisjoint(other)

Return True if two sets have a null intersection.

pop()

Return the popped value.

remove(val)

Remove an element.

update(iterable)

Update a set with the union of itself and others.

Attributes

hasher

Member Documentation

add(val)[source]

Add an element.

clear()[source]

Remove all elements from this set.

discard(val)[source]

Remove an element. Do not raise an exception if absent.

isdisjoint(other)

Return True if two sets have a null intersection.

pop()

Return the popped value. Raise KeyError if empty.

remove(val)[source]

Remove an element. If not a member, raise a KeyError.

update(iterable)[source]

Update a set with the union of itself and others.