B _@sHddlmZmZmZddlmZddlmZddZddZ dd Z d S) )BlockVar Reference) SubclassOf)IndexedComponent_slicec #sD|}ddg}dxx|D]p}||kr<d7q"|jdk rtx t|jD]}||qRW|j7q"dkrd7q"tdq"WrkrfddtD}dd|D}|i}}t||||} g} xN| D]B} t | t k r| f} t fdd t | D} t|| | dVqWdS) Nrz/We can only handle a single Set with dimen=Nonecs g|]}|kr|n|qSr).0i) ellipsis_idxidxr5/tmp/pip-unpacked-wheel-d4p3hk07/pyomo/dae/flatten.py -sz-generate_time_only_slices..cSsi|]}td|qS)N)slice)r r rrr 1sz-generate_time_only_slices..c3s.|]&\}}|kr||fn |d|fVqdS)rNr)r r val)time_idxrr >sz,generate_time_only_slices..) index_setsubsetsZdimenrangeappend RuntimeErrorZ fixed_idxfirstrZ wildcard_keystypetupledict enumerate) objtimeZo_setsZ regular_idxsZsub_idxZ tmp_slicedZ tmp_fixedZ tmp_ellipsis_sliceZ time_slicedkeyZ time_fixedr)r r rr generate_time_only_slicessH           r#c cstt||}x|r|d}tt|}x>|jtddD],}|j}x |D]}|| ||qJWq:Wx:|j|ddD](} | j}x| D]}| ||VqWqzWqWdS)NrF) descend_into) listr#popnextitercomponent_objectsrZ local_namer component) blockrctypequeuer!bZsub_b_namer vrrr "generate_time_indexed_block_slicesDs    r1c Cs||kst|g}g}g}x|r |d}|}||krnx"t|||D]}|t|qVWq$x$|D]} | | j t ddqxWxr|D]f} x`| j t |ddD]J} | } || krx0t | |D]}|t|qWq| | qWqWq$W||fS)a  This function takes in a (hierarchical, block-structured) Pyomo model and a `ContinuousSet` and returns two lists of "flattened" components. The first is a list of all `_ComponentData` that are not indexed by the `ContinuousSet` and the second is a list of `Reference` components such that each reference is indexed only by the specified `ContinuousSet`. This function is convenient for identifying components that are implicitly indexed by the `ContinuousSet`, for example, a singleton `Component` living on a `Block` that is indexed by the `ContinuousSet`. Parameters ---------- model : Concrete Pyomo model time : ``pyomo.dae.ContinuousSet`` ctype : Pyomo Component type Returns ------- Two lists rF)r$)modelAssertionErrorr&rrr1rrvaluesextendr)rrr#) r2rr,Z block_queueZ regular_compsZtime_indexed_compsr.Zb_setsr!Zblkdatar0Zv_setsrrr flatten_dae_components\s.     r6N) Zpyomo.core.baserrrZpyomo.core.base.blockrZ'pyomo.core.base.indexed_component_slicerr#r1r6rrrr  s   5