rename_components

(function from pyomo.util.components)

pyomo.util.components.rename_components(model, component_list, prefix)[source]

Rename components in component_list using the prefix AND unique_component_name

Parameters:
  • model (Pyomo model (or Block)) – The variables, constraints and objective will be renamed on this model

  • component_list (list) – List of components to rename

  • prefix (str) – The prefix to use when building the new names

Examples

>>> model = pyo.ConcreteModel()
>>> model.x = pyo.Var()
>>> model.y = pyo.Var()
>>> c_list = list(model.component_objects(ctype=pyo.Var, descend_into=True))
>>> new = rename_components(model, component_list=c_list, prefix='special_')
>>> str(new)
"ComponentMap({'special_x (key=...)': 'x', 'special_y (key=...)': 'y'})"
Returns:

ComponentMap – to a string that provides their old fully qualified names

Return type:

maps the renamed Component objects

Todo

  • need to add a check to see if someone accidentally passes a generator since this can lead to an infinite loop