CachingNumericSuffixFinder

(class from pyomo.repn.plugins.nl_writer)

class pyomo.repn.plugins.nl_writer.CachingNumericSuffixFinder(name, default=None, context=None)[source]

Bases: SuffixFinder

__init__(name, default=None, context=None)[source]

This provides an efficient utility for finding suffix values on a (hierarchical) Pyomo model.

Parameters:
  • name (str) – Name of Suffix to search for.

  • default – Default value to return from .find() if no matching Suffix is found.

  • context (BlockData) – The root of the Block hierarchy to use when searching for Suffix components. Suffixes outside this hierarchy will not be interrogated and components that are queried (with find(component_data)() will return the default value.

Methods

__init__(name[, default, context])

This provides an efficient utility for finding suffix values on a (hierarchical) Pyomo model.

find(component_data)

Find suffix value for a given component data object in model tree

Attributes

scale

Member Documentation

find(component_data)

Find suffix value for a given component data object in model tree

If the component_data is attached to a block within the context (that is, part of the model hierarchy rooted by the context BlockData), then Suffix components are searched by traversing the model hierarchy in three passes:

  1. Search for a Suffix matching the specific component_data, starting at the root (context block) and descending down the tree to the component_data. Return the first match found.

  2. Search for a Suffix matching the component_data’s container, starting at the root and descending down the tree to the component_data. Return the first match found.

  3. Search for a Suffix with key None, starting from the component_data and working up the tree to the root. Return the first match found.

If the component_data is not part of the context hierarchy, then only the Suffix attached to the root context is checked for the component_data, its container, and None (in order).

If no valid value is found by searching Suffix components, then the default value is returned.

Parameters:

component_data (ComponentBase) – Component or component data object to find suffix value for.

Returns:

The value for Suffix associated with component data if found, else None.

Return type:

Any