B @`E@sddlZddlZddlZddlmZmZddlmZddl m Z ddl m Z ddl mZddlmZddlmZmZmZmZmZmZmZmZmZmZdd lmZmZmZdd l m!Z!mZdd l"m#Z#dd l$m%Z%dd l&m'Z'e(dZ)dZ*Gddde Z+Gddde,Z-Gddde#Z.e/dGdddeZ0Gddde.e0Z1Gddde0Z2e3e4e0e._5GdddeZ6e/dGd d!d!e'Z7Gd"d#d#e6e7Z8Gd$d%d%e7Z9dS)&N) iteritems itervalues)ref)PyomoException) is_debug_set)unique_component_name)ConstructionTimer) BooleanVarModelComponentFactoryBinaryBlockVarConstraintListAnyLogicalConstraintList BooleanValuevalue)ActiveComponentActiveComponentData ComponentData) native_typesr) _BlockData)apply_indexed_rule)ActiveIndexedComponentz pyomo.gdpaDisjunction '%s': rule returned None. Disjunction rules must return an iterable containing Disjuncts or individual expressions, or Disjunction.Skip. The most common cause of this error is forgetting to include the "return" statement at the end of your rule. c@seZdZdZdS) GDP_Errorz,Exception raised while processing GDP ModelsN)__name__ __module__ __qualname____doc__rr6/tmp/pip-unpacked-wheel-bi3529v6/pyomo/gdp/disjunct.pyr,src@s,eZdZdZdZdZdZdZeddZ dS) _InitializeraA simple function to process an argument to a Component constructor. This checks the incoming initializer type and maps it to a static identifier so that when constructing indexed Components we can avoid a series of isinstance calls. Eventually this concept should be promoted to pyomo.core so that all Components can leverage a standardized approach to processing "flexible" arguments (POD data, rules, dicts, generators, etc).rcCsht|tkrtjt|fSt|tjkr2tj|fSt|t rFtj |fSt |drZtj |fStj |fSdS)N __getitem__) typerr!rbooltypes FunctionTypefunction isinstancerdeferred_valuehasattr dict_like)argrrr processAs      z_Initializer.processN) rrrrrr,r*r. staticmethodr0rrrr r!2s r!csZeZdZeZeddZddZfddZfddZ fd d Z fd d Z Z S) _DisjunctDatacCs|jS)N)_transformation_block)selfrrr transformation_blockTsz"_DisjunctData.transformation_blockcCs"t||ttd|_d|_dS)N)Zwithin)r__init__r r indicator_varr3)r4 componentrrr r6Xs  z_DisjunctData.__init__cstt||jdS)N)superr2activater7Zunfix)r4) __class__rr r:_sz_DisjunctData.activatecstt||jddS)Nr)r9r2 deactivater7Zfix)r4)r;rr r<csz_DisjunctData.deactivatecstt|dS)N)r9r2r<)r4)r;rr $_deactivate_without_fixing_indicatorgsz2_DisjunctData._deactivate_without_fixing_indicatorcstt|dS)N)r9r2r:)r4)r;rr $_activate_without_unfixing_indicatorjsz2_DisjunctData._activate_without_unfixing_indicator) rrrset_Block_reserved_wordspropertyr5r6r:r<r=r> __classcell__rr)r;r r2Ps    r2zDisjunctive blocks.cs0eZdZeZfddZddZddZZS)Disjunctcs8|tkrtt||S|dkr*ttSttSdS)Nr)rCr9__new__SimpleDisjunctIndexedDisjunct)clsargskwds)r;rr rDss  zDisjunct.__new__cOs2|ddrdS|dttj|f||dS)NZ _deep_copyingctype)pop setdefaultrCr r6)r4rHkwargsrrr r6{s  zDisjunct.__init__cCs0t||r,xt|D] }|qWdS)N)rr: is_indexedrr>)r4Zcomponent_datarrr r>s z-Disjunct._activate_without_unfixing_indicator) rrrr2_ComponentDataClassrDr6r>rBrr)r;r rCns rCc@seZdZddZdS)rEcOs:d|_t|_t||tj|f||||jd<dS)NT)Z_defer_constructionr?Z_suppress_ctypesr2r6rC_data)r4rHrIrrr r6s  zSimpleDisjunct.__init__N)rrrr6rrrr rEsrEc@seZdZeddZdS)rFcCstddt|jDS)Ncss|] }|jVqdS)N)active).0drrr sz)IndexedDisjunct.active..)anyrrP)r4rrr rQszIndexedDisjunct.activeN)rrrrArQrrrr rFsrFcsBeZdZdZdZeddZd ddZfdd Zd d Z Z S) _DisjunctionData) disjunctsxor_algebraic_constraint)rcCs|jS)N)rY)r4rrr algebraic_constraintsz%_DisjunctionData.algebraic_constraintNcCs2|dk rt|nd|_d|_g|_d|_d|_dS)NT) weakref_refZ _component_activerWrXrY)r4r8rrr r6s z_DisjunctionData.__init__cs0tt|}xtjD]}t||||<qW|S)zL This method must be defined because this class uses slots. )r9rV __getstate__ __slots__getattr)r4resulti)r;rr r]s z_DisjunctionData.__getstate__c Csx|D]}t|tr&|j|qg}t|dr:|}n|g}x|D]}y |}Wntk rnd}YnX|r~|s(y |}Wntk rd}YnX|r|r||qFy | }Wntk rd}YnX|r||qF||kr dt |fnd} t d|j t || fqF||qFW| } | jdkr|} tt| _| t| | jd| j| j| jt| j} t| _} t| _}x0|D](}t|tr||n | |qW|j| qWdS)N__iter__Fz in %szUnexpected term for Disjunction %s. Expected a Disjunct object, relational expression, or iterable of relational expressions but got %s%sZ _disjuncts)r+r2rWappendr-Zis_expression_typeAttributeErrorZ is_relationalZis_variable_typeZis_logical_typer& ValueErrornameZparent_component_autodisjuncts parent_blockrCrZ add_componentrZ local_name constructlenr constraintrZ propositionsradd)r4expreZ expressionsZe_iterZ_tmpeZisexprZisvarZisboolmsgcompbZdisjunctcprrr set_valuesb                     z_DisjunctionData.set_value)N) rrrr^Z _NoArgumentrArZr6r]rurBrr)r;r rVs    rVzDisjunction expressions.csZeZdZeZfddZfddZddZfddZd d Z dd d Z ddZ Z S) Disjunctioncs8|tkrtt||S|dkr*ttSttSdS)Nr)rvr9rDSimpleDisjunctionIndexedDisjunction)rGrHrI)r;rr rD%s  zDisjunction.__new__cs|dd|_|dd|_t|dd|_d|_d|_|dt t t |j |||jdk r~|jdk r~t d|j fdS)NZrulernrXTrJz6Cannot specify both rule= and expr= for Disjunction %s)rK _init_rule _init_exprr!r0 _init_xorrhrYrLrvr9r6rfrg)r4rHrM)r;rr r6-s zDisjunction.__init__cCs&|tjkr||=dS|||SdS)N)rvSkipru)r4indexobjrrrr _setitem_implDs   zDisjunction._setitem_implcs6|tjkrdStt|j||d}||f|SdS)N)r}r)rvr|r9_setitem_when_not_present_initialize_members)r4r}rZans)r;rr rLs     z%Disjunction._setitem_when_not_presentcCs|jdtjkr6|jd}x|D]}||j|_q Wn|jdtjkrttt|jd}x|D]}||j|_q^Wn|jdtjkr|jd}xr|D]&}ttt||| ||j|_qWnB|jdtj kr|jd}x$|D]}tt|||j|_qWdS)Nrr") r{r!rrPrXr,r'r*r_parentr.)r4Zinit_setvalkeyZfcnrrr rUs"     "  zDisjunction._initialize_membersNc Csttrtd|j|jr"dSt|}d|_|}|s|jdk rV||}n|j dk rh|j }n | dS|dkrt t |jf|t jkr| dS||jd<|d|n|j dk rtd|jfn|jdk r|j}x|jD]}yt||||}WnFtk rLtd}td|jt|t|j|fYnX|dkrxd|jt|f}t t |f|t jkrq|||qW| dS)NzConstructing disjunction %sTzdDisjunction '%s': Cannot initialize multiple indices of a disjunction with a single disjunction listr"zORule failed when generating expression for disjunction %s with index %s: %s: %sz%s[%s])rloggerdebugrg _constructedrrirNryrzreportrf_rule_returned_none_errorrvr|rPr IndexError_indexr Exceptionsysexc_infoerrorstrr&r) r4dataZtimerZ _self_parentrnryZndxerr_namerrr rjhsd              zDisjunction.constructcCs:dt|fd|r|jndfd|jfgt|dddfS)zF Return data that will be printed for this component. SizeZIndexNActive)Z DisjunctsrZXORcSsdd|jD|j|jgS)NcSsg|] }|jqSr)rg)rRxrrr sz9Disjunction._pprint....)rWrQrX)kvrrr z%Disjunction._pprint..)rkrNrrQr)r4rrr _pprints   zDisjunction._pprint)N) rrrrVrOrDr6rrrrjrrBrr)r;r rv!s    9rvcs$eZdZddZfddZZS)rwcOs$tj||dtj|f||dS)N)r8)rVr6rv)r4rHrIrrr r6szSimpleDisjunction.__init__csP|jstd|jt|jdkr,||jd<|tjkr@|d=dStt| |S)z'Set the expression on this disjunction.zxSetting the value of disjunction '%s' before the Disjunction has been constructed (there is currently no object to set).rN) rrfrgrkrPrvr|r9rwru)r4rn)r;rr rus   zSimpleDisjunction.set_value)rrrr6rurBrr)r;r rwsrwc@seZdZeddZdS)rxcCstddt|jDS)Ncss|] }|jVqdS)N)rQ)rRrSrrr rTsz,IndexedDisjunction.active..)rUrrP)r4rrr rQszIndexedDisjunction.activeN)rrrrArQrrrr rxsrx):loggingrr(sixrrweakrefrr[Zpyomo.common.errorsrZpyomo.common.logrZpyomo.common.modelingrZpyomo.common.timingrZ pyomo.corer r r r r rrrrrZpyomo.core.base.componentrrrZpyomo.core.base.numvaluerZpyomo.core.base.blockrZpyomo.core.base.miscrZ!pyomo.core.base.indexed_componentr getLoggerrrrobjectr!r2registerrCrErFr?dirr@rVrvrwrxrrrr  s<     0    / h!