ComponentMap
(class from pyomo.common.collections.component_map
)
- class pyomo.common.collections.component_map.ComponentMap(*args, **kwds)[source]
Bases:
Mixin
,MutableMapping
This class is a replacement for dict that allows Pyomo modeling components to be used as entry keys. The underlying mapping 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 mappings from Pyomo components to values. The use of non-Pyomo components as entry keys should be avoided.
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() 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 the components for which it contains map entries (e.g., as part of a block). *
Methods
__init__
(*args, **kwds)clear
()get
(k[,d])items
()keys
()pop
(k[,d])If key is not found, d is returned if given, otherwise KeyError is raised.
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: for k in E: 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
()Attributes
hasher
Member Documentation
- items() a set-like object providing a view on D's items
- keys() a set-like object providing a view on D's keys
- 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.
- 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: 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