B _o#@svddlZddlZddlmZmZmZmZmZm Z ddl Z ddl m Z ddlZ e jjjdddGddde jjZdS) N)TransformationFactoryVar ComponentUIDBlock ObjectiveSet)SubModel bilevel_ldz0Solver for bilevel problems using linear duality)docc@s4eZdZddZddZddZddZd d Zd S) BILEVEL_Solver1cKs$d|d<tjjj|f|d|_dS)Nr typeT)pyomoopt OptSolver__init__Z _metasolver)selfkwdsrA/tmp/pip-unpacked-wheel-d4p3hk07/pyomo/bilevel/plugins/solver1.pyrszBILEVEL_Solver1.__init__cOs$|d|_tjjj|f||dS)Nr) _instancer rr _presolve)rargsrrrrrs zBILEVEL_Solver1._presolvec Cs@t}td}||jd}x(|jjtddD]}|jdk}Pq2W|rtd}||jtd}|j|j|j dd d |jj }|jj sd }t j |}g|_|j|j|j|j|jd |r0d } xL|jjjD]:} t| jdkr d |jjj| <nd|jjj| <| d} qW|jj|jjd} t} x\| jD]R} xJ| |jD]6\}}|js`|j|j|_d|_| t!|q`WqJWx| j"D]}t#|j|}|$x>|j%dd&D]*\}}t'|t(st'|t)s|$qWt#|j|d}|t j*+di|d|j,|t-t j |}|j|j|j|jd }WdQRXqWxD| jD]:} x2| |jD]\}}t!|| krd|_qWqvW|jj.j/d dd|j|t}|||_0|1|_2x&|j%t&D]\}}|$qWt3j4j5t#|ddt#|dddSQRXdS)Nzbilevel.linear_dualFT)activez gdp.bilinearzgdp.bigmbigMi)rZglpk)teeZ timelimitrgHz>Z_dualz pyomo.repn.compute_standard_repn)model)Zignore_fixed_varsZ_rc_log)rclog)6timerZapply_torZcomponent_objectsrexprZpolynomial_degreeoptionsgetsolverr r SolverFactoryresultsappendZsolve_teeZ _timelimitZbilinear_data_vlist itervaluesabsvalueZ vlist_booleanZ deactivateZ_transformation_datasetZfixedZfind_component_on iteritemsZfind_componentaddrsubmodelgetattractivateZ component_mapitems isinstancerrcommonZPyomoAPIFactoryZreclassify_component_typer solutionsselect wall_time_setup_results_obj results_objpyutilibmiscZBunch)r start_timeZxfrmZ nonlinearodataZgdp_xfrmZmip_xfrmr$rivZtdataZ unfixed_cuidsZvuidZindex_Zdata_Zname_r0namedataZ dual_submodelZ opt_innerr&Z stop_timeZonamerrr _apply_solver sz           &    zBILEVEL_Solver1._apply_solvercCs d|_|jS)N)rr:)rrrr _postsolveszBILEVEL_Solver1._postsolvecCstj}|j}|jj|_|j|_g}x.|j D]$}t |jdddk r.| |jj q.Wt |dkrlt||_ tjjj|_|j}|jj|_|jjj|_|jjj|_|jjj|_|jjj|_|jjj|_|jjj|_|jj||S)Ncpu_timer)r rZ SolverResultsr$r"Z subsolverrAr8Zwallclock_timer&r1r'rElensumZTerminationConditionZoptimalZtermination_conditionZproblemrZ statisticsZnumber_of_constraintsZnumber_of_variablesZnumber_of_binary_variablesZnumber_of_integer_variablesZnumber_of_continuous_variablesZnumber_of_objectivesr6Zstore_to)rr&ZsolvZcpu_resZprobrrrr9s*             z"BILEVEL_Solver1._setup_results_objN)__name__ __module__ __qualname__rrrCrDr9rrrrr s  r )r Z pyutilib.miscr;Z pyomo.corerrrrrrZ pyomo.optr Zpyomo.bilevel.componentsrZ pyomo.commonrr%registerrr rrrr s