B u `@sJddlZddlZddlmZddlmZddlmZmZm Z m Z ddl m Z ddl mZddlmZmZddlZedZd d Zd d Zd dZedkrFddlmZm Z mZeZddZeddgede_ddZedddgede_ eejdejdgde_!eej dej dej dgde_"eej!ej"ge_#e$dS)N) iteritems)xrange)BlockConstraintListSet Constraint) Reference)unique_component_name)Disjunct Disjunctionz pyomo.gdpcCs:dt|dtddit|j|ji}t||}d|_|S)z;Clone everything in a Disjunct except for the indicator_varZ__block_scope__TNF)id indicator_varcopydeepcopy_parent)selfmemoZ new_blockr8/tmp/pip-unpacked-wheel-n62dbgi3/pyomo/gdp/basic_step.py _pseudo_clones  rccs0x*|D]"}t|dkr"|dVq|VqWdS)z8Squish all singleton tuples into their non-tuple values.rN)len)Z tuple_itertuprrr_squish_singletons#s   rc stdd|D}tdd|D}x:|D]2}|jsDtd|jf|js*td|jfq*Wtddtt t |d_ tt |t t jtd d|Dd _tj_x<jD]0}tj j|_xj D]xt|jt|tr|n|}xNtt|D]:\}}|d kr.q||j|j||qWqWtj|_x|D]~}|rxl|D]<} j|j|| j|| j|| j f|| !qWn&j|j|j|j|j f|!qnWqWi} t_"xj D]xxt t |jD]b|jj#} j"| t$fd djDk| j%d| d } t&| t'| q WqWt(fddjDd_)x:j D]0|!x|jD]}|*qWqWS)Ncss|]}|jtkr|VqdS)N)ctyper ).0objrrr 0sz#apply_basic_step..css|]}|jtkr|VqdS)N)rr)rrrrrr2szQBasic steps can only be applied to XOR'd disjunctions (raised by disjunction %s)zIWarning: applying basic step to a previously deactivated disjunction (%s)T)Zconcrete) initializecss|]}tt|jVqdS)N)rr disjuncts)rdrrrrBs)Zdimenrr c3s4|],}t|tr|n|krj|jVqdS)N) isinstancetuplerr )ridx)ansijrrrrs)Zfully_qualifiedZ name_buffercsg|]}j|qSr)r)rr%)r$rr {sz$apply_basic_step..)expr)+listxor ValueErrornameactiveloggerwarningrrrrZ DISJUNCTIONSr itertoolsproductr"ZINDEXr rsrcrr!rZ component_mapZ del_componentZ add_componentrZimproper_constraintsZ is_indexedaddlowerbodyupperZ deactivateZindicator_linksr sumgetnamer rr Z disjunctionZ$_deactivate_without_fixing_indicator) Zdisjunctions_or_constraintsZ disjunctions constraintsr r#tmpkvZconstrZindxZ NAME_BUFFERZorig_varZ name_baser)r$r%r&rapply_basic_step,sn        "          r=__main__) ConcreteModelrVarcCs$tt||_t|j|kd|_dS)N)r()r@rxrr Zsilly)r r%rrr_dsrBr)ZrulecCsttd||_dS)NrC)r@ry)er%rrr_esrF)r()%rr0sixrZ six.movesrZ pyomo.corerrrrZpyomo.core.baserZpyomo.common.modelingr Zpyomo.gdp.disjunctr r logging getLoggerr.rrr=__name__Z pyomo.environr?r@mrBr rFrEddeeZpprintrrrr s.       \ $