B u `j@sHddlmZmZmZddlmZddlmZddZddZ dd Z d S) )BlockVar Reference) SubclassOf)IndexedComponent_slicec#sp|}ddg}dxx|D]p}||kr<d7q"|jdk rtx t|jD]}||qRW|j7q"dkrd7q"tdq"WrkrfddtD}dd|D}x&|D]jtk rf}PqW|i}} t |||| } t di} xP| D]D} t | tk r<| f} t fdd t| D} t || | dVq$WdS) Nrz/We can only handle a single Set with dimen=Nonecs g|]}|kr|n|qSr).0i) ellipsis_idxidxr5/tmp/pip-unpacked-wheel-n62dbgi3/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 Isz,generate_time_only_slices..) index_setsubsetsZdimenrangeappend RuntimeErrorZ fixed_idx __class__tuplerrZ wildcard_keystypedict enumerate)objtimeZo_setsZ regular_idxsZsub_idxZ tmp_slicedtZ tmp_fixedZ tmp_ellipsis_sliceZ time_slicedkeyZ time_fixedr)r r rr generate_time_only_slicessR             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_slicesOs    r2c 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'rrr2rrvaluesextendr*rrr$) r3rr-Z block_queueZ regular_compsZtime_indexed_compsr/Zb_setsr"Zblkdatar1Zv_setsrrr flatten_dae_componentsgs.     r7N) Zpyomo.core.baserrrZpyomo.core.base.blockrZ'pyomo.core.base.indexed_component_slicerr$r2r7rrrr  s   @