ComponentSet

(class from pyomo.common.collections.component_set)

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

Bases: Mixin, MutableSet

Set that admits unhashable objects.

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

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

This class leverages AutoSlots to update any id() keys during pickling, restoration, or deepcopying.

Warning

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(*iterables)

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

Update a set with the union of itself and others.