B ÔÂ_iã@s|dZddlmZddlmZmZmZddlmZm Z m Z m Z ddl m Z mZmZddlmZddlmZdd „Zd d „Zd S) zIteration loop for MindtPy.é)Údivision)Úsolve_OA_masterÚhandle_master_mip_optimalÚ"handle_master_mip_other_conditions)Úsolve_NLP_subproblemÚhandle_NLP_subproblem_optimalÚ handle_NLP_subproblem_infeasibleÚ'handle_NLP_subproblem_other_termination)ÚminimizeÚ ObjectiveÚVar)ÚTerminationCondition)Úget_main_elapsed_timecCs>|j}t|jtddƒ}x|j|jkr8|j d|j¡t||ddrLPd|_ |j dkr¢t ||ƒ\}}|j j tjkr†t|||ƒnt||||ƒ| ||¡ntƒ‚t||ddr¸P|jdkrt||ƒ\}}|j j tjksì|j j tjkrút|||ƒn0|j j tjkrt|||ƒnt||j j ||ƒ| ||¡qWdS)NT)Úactivez!---MindtPy Master Iteration %s---F)Ú check_cyclingrZOA)Ú working_modelÚnextÚcomponent_data_objectsr Úmip_iterÚiteration_limitÚloggerÚinfoÚalgorithm_should_terminateZ mip_subiterZstrategyrÚsolverÚtermination_conditionÚtcÚoptimalrrZcall_after_master_solveÚNotImplementedErrorZ single_treerZlocallyOptimalrZ infeasiblerr Zcall_after_subproblem_solve)Ú solve_dataÚconfigrZmain_objectiveZ master_mipZmaster_mip_resultsZ fixed_nlpZfixed_nlp_result©r úA/tmp/pip-unpacked-wheel-d4p3hk07/pyomo/contrib/mindtpy/iterate.pyÚMindtPy_iteration_loops>      r"cCs|j|j|jkr>|j d |j|j|j¡¡tj|jj _ dS|j |j kr†|j d |j ¡¡|j d |j|j¡¡tj |jj _ dSt|jƒ|jkrÚ|j d |jt|jƒ¡¡|j d |j|j¡¡tj|jj _ dS|jdkrŒ|j dkrŒ|rŒg}x6|jjtdD]$}| ¡r | tt|jƒƒ¡q W||_|j|jkr„|j d |j ¡¡|j d |j|j¡¡tj|jj _ dS|j|_d S) zùCheck if the algorithm should terminate. Termination conditions based on solver options and progress. Sets the solve_data.results.solver.termination_condition to the appropriate condition, i.e. optimal, maxIterations, maxTimeLimit zBMindtPy exiting on bound convergence. LB: {} + (tol {}) >= UB: {} Tz=MindtPy unable to converge bounds after {} master iterations.z"Final bound values: LB: {} UB: {}zVMindtPy unable to converge bounds before time limit of {} seconds. Elapsed: {} secondsé)Úctypez¬Cycling happens after {} master iterations. This issue happens when the NLP subproblem violates constraint qualification. Convergence to optimal solution is not guaranteed.F)ZLBZbound_toleranceZUBrrÚformatrrÚresultsrrrrZ maxIterationsrZtimingZ time_limitZ maxTimeLimitZ cycling_checkZmiprr Ú is_integerÚappendÚintÚroundÚvalueZ curr_int_solZ prev_int_solZfeasible)rrrÚtempÚvarr r r!r`sR         rN)Ú__doc__Ú __future__rZpyomo.contrib.mindtpy.mip_solverrrZpyomo.contrib.mindtpy.nlp_solverrrr Z pyomo.corer r r Z pyomo.optr rZpyomo.contrib.gdpopt.utilrr"rr r r r!Ús   R