B u `” ã@s,ddlmZddlmZdd„Zdd„ZdS)é)Ú ComponentMap)Úunique_component_namecCsTtƒ}xH|D]@}| ¡}|j}t|||jƒ}| |¡| ||¡|||<q W|S)a; 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 -------- >>> c_list = list(model.component_objects(ctype=Var, descend_into=True)) >>> rename_components(model, component_list=c_list, prefix='special_') Returns ------- ComponentMap : maps the renamed Component objects to a string that provides their old fully qualified names ToDo ---- - need to add a check to see if someone accidentally passes a generator since this can lead to an infinite loop )rZ parent_blockÚnamerZ local_nameZ del_componentZ add_component)ÚmodelZcomponent_listÚprefixZname_mapÚcÚparentZold_nameÚnew_name©r ú9/tmp/pip-unpacked-wheel-n62dbgi3/pyomo/util/components.pyÚrename_componentss    r cCsJy t| ¡ƒStk r YnXyt|ƒStk rDt|fƒSXdS)aš Yield "child" objects from a component that is defined with either the `base` or `kernel` APIs. If the component is not indexed, it returns itself. Parameters ---------- obj : ComponentType eg. `TupleContainer`, `ListContainer`, `DictContainer`, `IndexedComponent`, or `Component` Returns ------- Iterator[ComponentType] : Iterator of the component data objects. N)ÚiterÚvaluesÚAttributeErrorÚ TypeError)Úobjr r r Úiter_component:s rN)Zpyomo.common.collectionsrZpyomo.common.modelingrr rr r r r Ú s  +