B u `< @s|ddlmZmZmZddlmZddlmZddlmZm Z ddl m Z ddl Z e dZejdd d Gd d d e ZdS) ) Constraint ObjectiveBlock)generate_standard_repn)TransformationFactory)VarSet)Base_BilevelTransformationNz pyomo.corezbilevel.linear_dualzDualize a SubModel block)doccs4eZdZfddZddZddZddZZS) LinearDual_BilevelTransformationcstt|dS)N)superr __init__)self) __class__>/tmp/pip-unpacked-wheel-n62dbgi3/pyomo/bilevel/plugins/dual.pyr sz)LinearDual_BilevelTransformation.__init__c Ks|jd|f|}|t||jd|||j||jdtx*|j t dd D]\}}| q^W| | t||j}x8|j dd D]$\}}t|tst|ts| qWdS)Nzbilevel.linear_dualZ_dualT)active)Z _preprocessZ_fix_allsetattrZ _submodel_dualizeZ_unfixed_upper_varsZreclassify_component_typer_parent component_mapritemsZ deactivateZ _unfix_allgetattr isinstancerr) rinstancekwdssubmodelZonameodatasubnamedatarrr _apply_tos   z*LinearDual_BilevelTransformation._apply_tocCstd}|||S)z1 Generate the dual of a submodel zduality.linear_dual)rr)rrZunfixedZ transformrrrr:sz)LinearDual_BilevelTransformation._dualizec Csx|jtddD]\}}xx|D]p}||}|j}|dkrHd||dkr"t|j}x6t|jD](\}} td|t | t |j |fqfWq"WqWdS)zI Replace bilinear terms in constraints with disjunctions T)rz@RuntimeError: Cannot transform a model with polynomial degree %dz%s %s %sN) rrrbodyZpolynomial_degreer enumerateZquadratic_varsprintstrZquadratic_coefs) rZdualrr ZndxconZdegreeZtermsivarrrr_xfrm_bilinearitiesAs   z4LinearDual_BilevelTransformation._xfrm_bilinearities)__name__ __module__ __qualname__r r!rr* __classcell__rr)rrr s r )Zpyomo.core.baserrrZ pyomo.repnrZpyomo.core.base.pluginrrrZpyomo.bilevel.plugins.transformr logging getLoggerloggerregisterr rrrr s