ComponentMap

(class from pyomo.common.collections.component_map)

class pyomo.common.collections.component_map.ComponentMap(*args, **kwargs)[source]

Bases: Mixin, MutableMapping

Mapping that admits unhashable objects as keys

This class is a replacement for :py:`dict` that allows Pyomo modeling components to be used as keys. The underlying mapping 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 mappings from Pyomo components to values.

A reference to the object is kept around as long as it has a corresponding entry 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__(*args, **kwargs)[source]

Methods

__init__(*args, **kwargs)

clear()

get(k[,d])

items()

keys()

pop(k[,d])

value.

popitem()

as a 2-tuple; but raise KeyError if D is empty.

setdefault(k[,d])

update([E, ]**F)

If E present and has a .keys() method, does:

values()

Attributes

hasher

Member Documentation

clear() → None.  Remove all items from D.[source]
get(k[, d]) → D[k] if k in D, else d.  d defaults to None.[source]
items() → a set-like object providing a view on D's items[source]
keys() → a set-like object providing a view on D's keys[source]
pop(k[, d]) → v, remove specified key and return the corresponding

value. If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() → (k, v), remove and return some (key, value) pair

as a 2-tuple; but raise KeyError if D is empty.

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D[source]
update([E, ]**F) → None.  Update D from mapping/iterable E and F.[source]
If E present and has a .keys() method, does:

for k in E.keys(): D[k] = E[k]

If E present and lacks .keys() method, does:

for (k, v) in E: D[k] = v

In either case, this is followed by:

for k, v in F.items(): D[k] = v

values() → an object providing a view on D's values[source]