B u `E@sddlZddlZddlZddlmZmZddlmZddl m Z ddl m Z ddl mZddlmZmZmZmZmZmZmZmZmZmZddlmZmZmZdd lmZmZdd l m!Z!dd l"m#Z#dd l$m%Z%e&d Z'dZ(Gddde Z)Gddde*Z+Gddde!Z,e-dGdddeZ.Gddde,e.Z/Gddde.Z0e1e2e.e,_3GdddeZ4e-dGdd d e%Z5Gd!d"d"e4e5Z6Gd#d$d$e5Z7dS)%N) iteritems itervalues)ref)PyomoException)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-n62dbgi3/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)argrrrprocess@s      z_Initializer.processN) rrrrrr+r)r- staticmethodr/rrrrr 1s r csZeZdZeZeddZddZfddZfddZ fd d Z fd d Z Z S) _DisjunctDatacCs|jS)N)_transformation_block)selfrrrtransformation_blockSsz"_DisjunctData.transformation_blockcCs"t||ttd|_d|_dS)N)Zwithin)r__init__r r indicator_varr2)r3 componentrrrr5Ws  z_DisjunctData.__init__cstt||jdS)N)superr1activater6Zunfix)r3) __class__rrr9^sz_DisjunctData.activatecstt||jddS)Nr)r8r1 deactivater6Zfix)r3)r:rrr;bsz_DisjunctData.deactivatecstt|dS)N)r8r1r;)r3)r:rr$_deactivate_without_fixing_indicatorfsz2_DisjunctData._deactivate_without_fixing_indicatorcstt|dS)N)r8r1r9)r3)r:rr$_activate_without_unfixing_indicatorisz2_DisjunctData._activate_without_unfixing_indicator) rrrset_Block_reserved_wordspropertyr4r5r9r;r<r= __classcell__rr)r:rr1Os    r1zDisjunctive blocks.cs0eZdZeZfddZddZddZZS)Disjunctcs8|tkrtt||S|dkr*ttSttSdS)Nr)rBr8__new__SimpleDisjunctIndexedDisjunct)clsargskwds)r:rrrCrs  zDisjunct.__new__cOs2|ddrdS|dttj|f||dS)NZ _deep_copyingctype)pop setdefaultrBr r5)r3rGkwargsrrrr5zs  zDisjunct.__init__cCs0t||r,xt|D] }|qWdS)N)rr9 is_indexedrr=)r3Zcomponent_datarrrr=s z-Disjunct._activate_without_unfixing_indicator) rrrr1_ComponentDataClassrCr5r=rArr)r:rrBms rBc@seZdZddZdS)rDcOs:d|_t|_t||tj|f||||jd<dS)NT)Z_defer_constructionr>Z_suppress_ctypesr1r5rB_data)r3rGrHrrrr5s  zSimpleDisjunct.__init__N)rrrr5rrrrrDsrDc@seZdZeddZdS)rEcCstddt|jDS)Ncss|] }|jVqdS)N)active).0drrr sz)IndexedDisjunct.active..)anyrrO)r3rrrrPszIndexedDisjunct.activeN)rrrr@rPrrrrrEsrEcsBeZdZdZdZeddZd ddZfdd Zd d Z Z S) _DisjunctionData) disjunctsxor_algebraic_constraint)rcCs|jS)N)rX)r3rrralgebraic_constraintsz%_DisjunctionData.algebraic_constraintNcCs2|dk rt|nd|_d|_g|_d|_d|_dS)NT) weakref_refZ _component_activerVrWrX)r3r7rrrr5s z_DisjunctionData.__init__cs0tt|}xtjD]}t||||<qW|S)zL This method must be defined because this class uses slots. )r8rU __getstate__ __slots__getattr)r3resulti)r:rrr\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*r1rVappendr,Zis_expression_typeAttributeErrorZ is_relationalZis_variable_typeZis_logical_typer% ValueErrornameZparent_component_autodisjuncts parent_blockrBrZ add_componentrZ local_name constructlenr constraintrZ propositionsradd)r3expreZ expressionsZe_iterZ_tmpeZisexprZisvarZisboolmsgcompbZdisjunctcprrr set_valuesb                     z_DisjunctionData.set_value)N) rrrr]Z _NoArgumentr@rYr5r\rtrArr)r:rrUs    rUzDisjunction expressions.csZeZdZeZfddZfddZddZfddZd d Z dd d Z ddZ Z S) Disjunctioncs8|tkrtt||S|dkr*ttSttSdS)Nr)rur8rCSimpleDisjunctionIndexedDisjunction)rFrGrH)r:rrrC$s  zDisjunction.__new__cs|dd|_|dd|_t|dd|_d|_d|_|dt t t |j |||jdk r~|jdk r~t d|j fdS)NZrulermrWTrIz6Cannot specify both rule= and expr= for Disjunction %s)rJ _init_rule _init_exprr r/ _init_xorrgrXrKrur8r5rerf)r3rGrL)r:rrr5,s zDisjunction.__init__cCs&|tjkr||=dS|||SdS)N)ruSkiprt)r3indexobjrrrr _setitem_implCs   zDisjunction._setitem_implcs6|tjkrdStt|j||d}||f|SdS)N)r|r)rur{r8_setitem_when_not_present_initialize_members)r3r|rZans)r:rrrKs     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!) rzr rrOrWr+r&r)r_parentr-)r3Zinit_setvalkeyZfcnrrrrTs"     "  zDisjunction._initialize_membersNc Csttjrtd|j|jr&dSt|}d|_|}| s|j dk rZ| |}n|j dk rl|j }n | dS|dkrt t|jf|tjkr| dS||jd<|d|n|j dk rtd|jfn|j dk r|j }x|jD]}yt||||}WnFtk rPtd}td|jt|t|j|fYnX|dkr|d|jt|f}t t|f|tjkrq|||qW| dS)NTzConstructing disjunction %szdDisjunction '%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])logger isEnabledForloggingDEBUGdebugrf _constructedrrhrMrxryreportre_rule_returned_none_errorrur{rOr IndexError_indexr Exceptionsysexc_infoerrorstrr%r) r3dataZtimerZ _self_parentrmrxZndxerr_namerrrrigsd               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)rf)rQxrrr sz9Disjunction._pprint....)rVrPrW)kvrrrz%Disjunction._pprint..)rjrMrrPr)r3rrr_pprints   zDisjunction._pprint)N) rrrrUrNrCr5r~rrrirrArr)r:rru s    9rucs$eZdZddZfddZZS)rvcOs$tj||dtj|f||dS)N)r7)rUr5ru)r3rGrHrrrr5szSimpleDisjunction.__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) rrerfrjrOrur{r8rvrt)r3rm)r:rrrts   zSimpleDisjunction.set_value)rrrr5rtrArr)r:rrvsrvc@seZdZeddZdS)rwcCstddt|jDS)Ncss|] }|jVqdS)N)rP)rQrRrrrrSsz,IndexedDisjunction.active..)rTrrO)r3rrrrPszIndexedDisjunction.activeN)rrrr@rPrrrrrwsrw)8rrr'sixrrweakrefrrZZpyomo.common.errorsrZpyomo.common.modelingrZpyomo.common.timingrZ pyomo.corerr r r r r rrrrZpyomo.core.base.componentrrrZpyomo.core.base.numvaluerZpyomo.core.base.blockrZpyomo.core.base.miscrZ!pyomo.core.base.indexed_componentr getLoggerrrrobjectr r1registerrBrDrEr>dirr?rUrurvrwrrrr s:    0    / h!