B u `2@s8ddlmZddlmZddlmZddlmZddl m Z m Z m Z ddl mZmZmZmZddlmZddlmZdd lmZmZmZmZdd lZed Zed d ZddZGdddeZ e!dGdddeZ"Gddde e"Z#edddhGddde#Z$Gddde"Z%e!dGdd d e%Z&d S)!) iteritems) namedtuple)ConstructionTimer)current) ZeroConstantnative_numeric_types as_numeric) ConstraintVarBlockSet)ModelComponentFactory) _BlockData)disable_methods InitializerIndexedCallInitializerCountedCallInitializerNz pyomo.coreComplementarityTuple)arg0arg1cCs t||S)z Return a named 2-tuple )r)abr>/tmp/pip-unpacked-wheel-n62dbgi3/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__EXPRZEqualityExpressionargrZis_fixedrZInequalityExpressionZRangedExpression)selfeZe__errr_canonical_expression)s   z*_ComplementarityData._canonical_expressioncCsV||jd}||jd}t|dkrsz1_ComplementarityData.set_value..z,Unexpected value for Complementarity %s: %sN)rrrrrr'tupler( ValueErrorr+ComplementaritySkipparent_componentindexlist set_value)r!ccrrrr9s     z_ComplementarityData.set_valueN)__name__ __module__ __qualname__r$r.r9rrrrr'sArzComplementarity conditions.csDeZdZeZfddZeddZddZddZ d d Z Z S) r4csD|tkrtt||S|dkr0tt|tStt|tSdS)Nr)r4super__new__AbstractSimpleComplementarityIndexedComplementarity)clsargskwds)rrrr?s zComplementarity.__new__cGsJ|j}|dkrdS|||}|dkr.Z initializeZruler%rzcDuplicate initialization: Complementarity() only accepts one of 'initialize=', 'rule=', and 'expr='rT)Ztreat_sequences_as_mappingsZallow_generators) setdefaultr4r2popr(r3rrErIr __init__rrr)r!rCkwargs_initrrrrMs(          zComplementarity.__init__cCs$|tjkrdS||}|||S)zI Add a complementarity condition with a specified index. N)r4r5r9)r!r7r:_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)ZostreamrGdata) _transformedr!rr_conditional_block_printersz;Complementarity._pprint.._conditional_block_printerSizeZIndexNActive)ZArg0ZArg1rY) issubclassrJr4r(Z is_indexed_indexrRr_data)r!Z _table_datarWr)rVr!r_pprints  zComplementarity._pprint) r;r<r=rZ_ComponentDataClassr? staticmethodrIrMrQr] __classcell__rr)rrr4s     r4c@seZdZddZdS)SimpleComplementaritycOs,t||tj|f||||jd<dS)N)rrMr4r\)r!rCrDrrrrMs zSimpleComplementarity.__init__N)r;r<r=rMrrrrr`sr`rQr9r.c@s eZdZdS)r@N)r;r<r=rrrrr@sr@c@s eZdZdS)rAN)r;r<r=rrrrrA srAz%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)r _nconditionsr4rMrH)r!rNrCrrrrM.szComplementarityList.__init__cCs,|jd7_|j|jt||j|S)zI Add a complementarity condition with an implicit index. r)rbr[rQr4)r!r%rrrrQ8szComplementarityList.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 _constructedrrErFiterraEndr4r5rQreport)r!rUZgenerate_debug_messagesZtimerrOr:rrr construct@s    zComplementarityList.construct)N)r;r<r=__doc__rirMrQrkrrrrra$s  ra)'sixr collectionsrZpyomo.common.timingrZpyomo.core.exprrrZpyomo.core.expr.numvaluerrrZ pyomo.corer r r r Zpyomo.core.base.pluginr Zpyomo.core.base.blockrZpyomo.core.base.utilrrrrre getLoggerrcrrrregisterr4r`r@rArarrrr s*        ~m