B _ @szddlmZddlTddlmZddlmZddlmZm Z ddlmZe j dddGd d d eZ Gd d d e Zd S)) deprecated)*)IsomorphicTransformation) StandardForm)partialprocess_canonical_repnzcore.lagrangian_dualzCreate the LP dual model.)doccs4eZdZdZedddfddZddZZS) DualTransformationa5 Creates a standard form Pyomo model that is equivalent to another model Options dual_constraint_suffix Defaults to _constraint dual_variable_prefix Defaults to p_ slack_names Defaults to auxiliary_slack excess_names Defaults to auxiliary_excess lb_names Defaults to _lower_bound ub_names Defaults to _upper_bound pos_suffix Defaults to _plus neg_suffix Defaults to _minus a7Use of the pyomo.duality package is deprecated. There are known bugs in pyomo.duality, and we do not recommend the use of this code. Development of dualization capabilities has been shifted to the Pyomo Adversarial Optimization (PAO) library. Please contact William Hart for further details (wehart@sandia.gov).z5.6.2)versionc sd|d<tt|jf|dS)NZ linear_dualname)superr __init__)selfkwds) __class__A/tmp/pip-unpacked-wheel-d4p3hk07/pyomo/duality/lagrangian_dual.pyr &szDualTransformation.__init__c sl|dd}|dd}i}|dd|d<|dd|d<|d d |d <|d d |d <|d d|d <|dd|d<t}||f|}tdd}td} td} x|jtddD]\} xfddjDD]} d|| jf} tt | j }| | |dd8<td}x.|D]"\}}|d||f|7<q(Wtt | j }| | |dd7<x.|D]"\}}|d||f|8<q~W||| <qWqWx|jt ddD]n\}xbfddjDD]J}tt |j }x4|D](\}}| d||f|j7<qWqWqWt}g}xT|jtddD]>\}x2fddjDD]}|d|j|fqvWqXWg}g}x`|jtddD]J\} x>fddjDD]&} || j|d|| jfqWqWt|d|_t|d|_t|j|_dd}t|jt||| d |_d!d"}t t|| td#|_|S)$z: Tranform a model to its Lagrangian dual. Zdual_constraint_suffixZ _constraintZdual_variable_prefixZp_Z slack_namesZauxiliary_slackZ excess_namesZauxiliary_excessZlb_namesZ _lower_boundZub_namesZ _upper_boundZ pos_suffixZ_plusZ neg_suffixZ_minuscSstdS)Nr)_sparserrrrRz2DualTransformation._create_using..rT)activec3s|]}|VqdS)Nr).0ndx) con_arrayrr \sz3DualTransformation._create_using..z%s%sNc3s|]}|VqdS)Nr)rr) obj_arrayrrr~sc3s|]}|VqdS)Nr)rr) var_arrayrrrsc3s|]}|VqdS)Nr)rr)rrrrs)Z initializecs$tfddjD|kS)Nc3s$|]}|j|VqdS)N)vars)rv)AmodelrrrrszKDualTransformation._create_using..constraintRule..)sumvar_set)rcrr r)rr rrconstraintRulesz8DualTransformation._create_using..constraintRule)rulecstfddjDS)Nc3s |]}|j|VqdS)N)r)rr)br rrrszJDualTransformation._create_using..objectiveRule..)r!r")r&r r)r&r r objectiveRulesz7DualTransformation._create_using..objectiveRule)r%sense)poprrZ component_mapZ Constraintitems_indexZ local_namerZgenerate_standard_repnbodylowerZ Objectiveexprr(Z AbstractModelZVarappendSetr"Zcon_setrrZconsZmaximizeobjcreate)rr rZconstraint_suffixZvariable_prefixZsf_kwdsZ sf_transformZsfrr&r#Zcon_nameconcnameZ body_termsrowZvnameZcoefZ lower_termsZobj_namer1Ztermsr ZdualZconstraint_set_initvar_namevarZvariable_set_initZdual_variable_rootsr$r'r)rrrr _create_using1sp      0     z DualTransformation._create_using)__name__ __module__ __qualname____doc__rr r8 __classcell__rr)rrr s r c@s eZdZdZddZddZdS)ra- Represents a sparse map. Uses a user-provided value to initialize entries. If the default value is a callable object, it is called with no arguments. Examples # Sparse vector v = _sparse(0) # 2-dimensional sparse matrix A = _sparse(lambda: _sparse(0)) cOs:tj|f||t|dr*d|_||_n ||_d|_dS)N__call__)dictr hasattr_default_value _default_func)rdefaultargsrrrrr s  z_sparse.__init__cCs0||krt||S|jdk r&|S|jSdS)N)r? __getitem__rBrA)rrrrrrEs   z_sparse.__getitem__N)r9r:r;r<r rErrrrrs rN)Zpyomo.common.deprecationrZ pyomo.coreZ&pyomo.core.plugins.transform.hierarchyrZ*pyomo.core.plugins.transform.standard_formrZ!pyomo.core.plugins.transform.utilrrZTransformationFactoryregisterr r?rrrrrs