B _3@s`ddlZddlZddlmZmZddlmZddlmZddl m Z ddl m Z mZmZmZddlTddlmZdd lm Z mZdd lmZmZdd lmZdd lmZmZmZmZddlZe d Z!eddZ"ddZ#GdddeZ$e%dGddde&Z'Gddde$e'Z(edddhGddde(Z)Gddde'Z*e%d Gd!d"d"e*Z+dS)#N) iteritemsStringIO) namedtuple)ConstructionTimer)current) ZeroConstant_subnative_numeric_types as_numeric)*)ModelComponentFactory)rr)apply_indexed_ruletabular_writer) _BlockData)disable_methods InitializerIndexedCallInitializerCountedCallInitializerz pyomo.coreComplementarityTuple)arg0arg1cCs t||S)z Return a named 2-tuple )r)abr>/tmp/pip-unpacked-wheel-d4p3hk07/pyomo/mpec/complementarity.py complements&src@s$eZdZddZddZddZdS)_ComplementarityDatacCs,d}|jtjkr^|djtks.|drD|d|df}nt|d|df}n|jtjkr|djtks|drd|d|df}nP|djtks|dr|d|ddf}nt|d|ddf}n6|jtjkr|d|d|df}n d|df}|S)Nr) __class__EXPRZEqualityExpressionargr Zis_fixedrZInequalityExpressionZRangedExpression)selfeZe__errr_canonical_expression-s   z*_ComplementarityData._canonical_expressioncCsV||jd}||jd}t|dkrsz1_ComplementarityData.set_value..z,Unexpected value for Complementarity %s: %sN)rrr rrr(tupler) ValueErrorr,ComplementaritySkipparent_componentindexlist set_value)r"ccrrrr:s     z_ComplementarityData.set_valueN)__name__ __module__ __qualname__r%r/r:rrrrr+sArzComplementarity conditions.csDeZdZeZfddZeddZddZddZ d d Z Z S) r5csD|tkrtt||S|dkr0tt|tStt|tSdS)Nr)r5super__new__AbstractSimpleComplementarityIndexedComplementarity)clsargskwds)rrrr@s zComplementarity.__new__cGsJ|j}|dkrdS|||}|dkr.Z initializeZruler&rzcDuplicate initialization: Complementarity() only accepts one of 'initialize=', 'rule=', and 'expr='rFT)Ztreat_sequences_as_mappingsZallow_generators) setdefaultr5r3popr)r4rrFrJBlock__init__rrr)r"rDkwargs_initrrrrOs&         zComplementarity.__init__cCs$|tjkrdS||}|||S)zI Add a complementarity condition with a specified index. N)r5r6r:)r"r8r;_blockrrradds   zComplementarity.addcs`dd}tjt fdd}dtfdr>jndfdjfgtjd ||ffS) zF Return data that will be printed for this component. cSs|jd|jd|jgS)Nrr)r(active)kr-rrrsz)Complementarity._pprint..cs"st|r|||dS)N)r)Z component_mapZ_pprint_callback)ZostreamrHdata) _transformedr"rr_conditional_block_printersz;Complementarity._pprint.._conditional_block_printerSizeZIndexNActive)ZArg0ZArg1r[) issubclassrKr5r)Z is_indexed_indexrTr_data)r"Z _table_datarYr)rXr"r_pprints  zComplementarity._pprint) r<r=r>rZ_ComponentDataClassr@ staticmethodrJrOrSr_ __classcell__rr)rrr5s    r5c@seZdZddZdS)SimpleComplementaritycOs,t||tj|f||||jd<dS)N)rrOr5r^)r"rDrErrrrOs zSimpleComplementarity.__init__N)r<r=r>rOrrrrrbsrbrSr:r/c@s eZdZdS)rAN)r<r=r>rrrrrAsrAc@s eZdZdS)rBN)r<r=r>rrrrrB#srBz%A list of complementarity conditions.c@s.eZdZdZdZddZddZd dd ZdS) ComplementarityListz A complementarity component that represents a list of complementarity conditions. Each condition can be indexed by its index, but when added an index value is not specified. )icKs*tf}d|_tj|f||d|_dS)Z ConstructorrN)Set _nconditionsr5rOrI)r"rPrDrrrrO1szComplementarityList.__init__cCs,|jd7_|j|jt||j|S)zI Add a complementarity condition with an implicit index. r)rer]rSr5)r"r&rrrrS;szComplementarityList.addNcCsdottj}|r"td|j|jr,dSt|}d|_|jdk r|| d}x2t |D]&}|t j krnP|t jkrzq^||q^W|dS)zQ Construct the expression(s) for this complementarity condition. Tz$Constructing complementarity list %sNr)logger isEnabledForloggingDEBUGdebugr,Z _constructedrrFrGiterrcEndr5r6rSreport)r"rWZgenerate_debug_messagesZtimerrQr;rrr constructCs    zComplementarityList.construct)N)r<r=r>__doc__rlrOrSrnrrrrrc's  rc),sysinspectsixrr collectionsrZpyomo.common.timingrZpyomo.core.exprrr Zpyomo.core.expr.numvaluerrr r Z pyomo.coreZpyomo.core.base.pluginr Zpyomo.core.base.numvalueZpyomo.core.base.miscr rZpyomo.core.base.blockrZpyomo.core.base.utilrrrrrh getLoggerrfrrrregisterrNr5rbrArBrcrrrr s2       ~l