B u `I#ã@snddlZddlmZmZmZmZmZmZddlZ ddl Z ddl m Z e j jjdddGdd„de j jƒƒZdS) éN)ÚTransformationFactoryÚVarÚ ComponentUIDÚBlockÚ ObjectiveÚSet)ÚBunchÚ bilevel_ldz0Solver for bilevel problems using linear duality)Údocc@s4eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd S) ÚBILEVEL_Solver1cKs$d|d<tjjj|f|Žd|_dS)Nr ÚtypeT)ÚpyomoÚoptÚ OptSolverÚ__init__Z _metasolver)ÚselfÚkwds©rúA/tmp/pip-unpacked-wheel-n62dbgi3/pyomo/bilevel/plugins/solver1.pyrszBILEVEL_Solver1.__init__cOs$|d|_tjjj|f|ž|ŽdS)Nr)Ú _instancer rrÚ _presolve)rÚargsrrrrrs zBILEVEL_Solver1._presolvec Cs<t ¡}tdƒ}| |j¡d}x(|jjtddD]}|j ¡dk}Pq2W|r„tdƒ}| |j¡tdƒ}|j|j|j  dd ¡d |jj }|jj s˜d }t j   |¡Œ}g|_|j |j|j|j|jd ¡|r0d } xL|jjj ¡D]:} t| jƒdkr d |jjj| <nd|jjj| <| d} qæW|jj ¡|jjd} tƒ} x\| jD]R} xJ|  |j¡ ¡D]6\}}|js`|j |¡j|_d|_|   t!|ƒ¡q`WqJWxÌ| j"D]Â}t#|j|ƒ}| $¡x>|j%dd &¡D]*\}}t'|t(ƒsÒt'|t)ƒsÒ| $¡qÒWt#|j|dƒ}| ¡t j* +d¡i|d|j ,|t-¡t j   |¡}|j|j|j|jd }WdQRXq¨WxD| jD]:} x2|  |j¡ ¡D]\}}t!|ƒ| krŒd|_qŒWqvW|jj.j/d dd|j |¡t ¡}|||_0| 1¡|_2x&|j %t¡ &¡D]\}}| $¡qWt3t#|ddƒt#|ddƒdSQRXdS)Nzbilevel.linear_dualFT)Úactiveéz gdp.bilinearzgdp.bigmÚbigMi †)rZglpk)ÚteeZ timelimitrgH¯¼šò×z>Z_dualz pyomo.repn.compute_standard_repn)Úmodel)Zignore_fixed_varsZ_rcÚ_log)ÚrcÚlog)4ÚtimerZapply_torZcomponent_objectsrÚexprZpolynomial_degreeÚoptionsÚgetÚsolverr rÚ SolverFactoryÚresultsÚappendZsolveÚ_teeZ _timelimitZbilinear_data_ÚvlistÚ itervaluesÚabsÚvalueZ vlist_booleanZ deactivateZ_transformation_dataÚsetZfixedZfind_component_onÚ iteritemsZfind_componentÚaddrÚsubmodelÚgetattrÚactivateZ component_mapÚitemsÚ isinstancerrÚcommonZPyomoAPIFactoryZreclassify_component_typerÚ solutionsÚselectÚ wall_timeÚ_setup_results_objÚ results_objr)rÚ start_timeZxfrmZ nonlinearÚodataZgdp_xfrmZmip_xfrmr$rÚiÚvZtdataZ unfixed_cuidsZvuidZindex_Zdata_Zname_r0ÚnameÚdataZ dual_submodelZ opt_innerr&Z stop_timeZonamerrrÚ _apply_solversz           &     zBILEVEL_Solver1._apply_solvercCs d|_|jS)N)rr:)rrrrÚ _postsolve¢szBILEVEL_Solver1._postsolvecCsâtj ¡}|j}|jj|_|j|_g}x.|j D]$}t |jddƒdk r.|  |jj ¡q.Wt |ƒdkrlt|ƒ|_ tjjj|_|j}|jj|_|jjj|_|jjj|_|jjj|_|jjj|_|jjj|_|jjj|_|jj |¡|S)NÚcpu_timer)r rZ SolverResultsr$r"Z subsolverr?r8Zwallclock_timer&r1r'rCÚlenÚsumZTerminationConditionZoptimalZtermination_conditionZproblemrZ statisticsZnumber_of_constraintsZnumber_of_variablesZnumber_of_binary_variablesZnumber_of_integer_variablesZnumber_of_continuous_variablesZnumber_of_objectivesr6Zstore_to)rr&ZsolvZcpu_ÚresZprobrrrr9¬s*             z"BILEVEL_Solver1._setup_results_objN)Ú__name__Ú __module__Ú __qualname__rrrArBr9rrrrr s  r )r Z pyomo.corerrrrrrZ pyomo.optr Z pyomo.commonZpyomo.common.collectionsrrr%Úregisterrr rrrrÚ s