B @`2@sDddlmZddlmZddlmZddlmZddlm Z ddl m Z m Z mZddlmZmZmZmZddlmZdd lmZdd lmZmZmZmZdd lZed Zed dZ ddZ!GdddeZ"e#dGdddeZ$Gddde"e$Z%edddhGddde%Z&Gddde$Z'e#dGd d!d!e'Z(d S)") iteritems) namedtuple) is_debug_set)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-bi3529v6/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)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='rT)Ztreat_sequences_as_mappingsZallow_generators) setdefaultr5r3popr)r4rrFrJr __init__rrr)r"rDkwargs_initrrrrNs(          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)ZArg0ZArg1rZ) issubclassrKr5r)Z is_indexed_indexrSr_data)r"Z _table_datarXr)rWr"r_pprints  zComplementarity._pprint) r<r=r>rZ_ComponentDataClassr@ staticmethodrJrNrRr^ __classcell__rr)rrr5s     r5c@seZdZddZdS)SimpleComplementaritycOs,t||tj|f||||jd<dS)N)rrNr5r])r"rDrErrrrNs zSimpleComplementarity.__init__N)r<r=r>rNrrrrrasrarRr: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)r _nconditionsr5rNrI)r"rOrDrrrrN/szComplementarityList.__init__cCs,|jd7_|j|jt||j|S)zI Add a complementarity condition with an implicit index. r)rcr\rRr5)r"r&rrrrR9szComplementarityList.addNcCsttrtd|j|jr dSt|}d|_|jdk r|||d}x2t|D]&}|t j krbP|t j krnqR| |qRW|dS)zQ Construct the expression(s) for this complementarity condition. z$Constructing complementarity list %sNTr)rloggerdebugr,Z _constructedrrFrGiterrbEndr5r6rRreport)r"rVZtimerrPr;rrr constructAs   zComplementarityList.construct)N)r<r=r>__doc__rgrNrRrirrrrrb%s  rb))sixr collectionsrZpyomo.common.logrZpyomo.common.timingrZpyomo.core.exprrr Zpyomo.core.expr.numvaluerrr Z pyomo.corer r r r Zpyomo.core.base.pluginrZpyomo.core.base.blockrZpyomo.core.base.utilrrrrlogging getLoggerrdrrrregisterr5rarArBrbrrrr s,         ~m