B u `t/@sdZddlmZddlZddlmZmZmZmZm Z m Z ddl m Z ddl mZddlmZmZddlmZmZmZmZmZmZmZmZmZdd lmZmZdd lm Z dd l!m"Z"dd l#m$Z$e%d Z&dZ'ej(dddGddde)Z*dS)aImplementation of the MindtPy solver. The MindtPy (MINLP Decomposition Toolkit) solver applies a variety of decomposition-based approaches to solve nonlinear continuous-discrete problems. These approaches include: - Outer approximation - Benders decomposition [pending] - Partial surrogate cuts [pending] - Extended cutting plane [pending] This solver implementation was developed by Carnegie Mellon University in the research group of Ignacio Grossmann. For nonconvex problems, the bounds solve_data.LB and solve_data.UB may not be rigorous. Questions: Please make a post at StackOverflow and/or David Bernal )divisionN)copy_var_list_valuescreate_utility_block time_codesetup_results_objectprocess_objectivelower_logger_level_to)MindtPy_initialize_master)MindtPy_iteration_loop)MindtPySolveDatamodel_is_valid) BlockConstraintListNonNegativeRealsSetSuffixVarVarListTransformationFactory Objective) SolverFactory SolverResults) Container)fbbt)_get_GDPopt_configzpyomo.contrib.mindtpy)rrZmindtpyz?MindtPy: Mixed-Integer Nonlinear Decomposition Toolbox in Pyomo)docc@s@eZdZdZeZdddZddZddZd d Z d d Z d S) MindtPySolverz(A decomposition-based MINLP solver. TcCsdS)zCheck if solver is available. TODO: For now, it is always available. However, sub-solvers may not always be available, and so this should reflect that possibility. T)selfZexception_flagrrA/tmp/pip-unpacked-wheel-n62dbgi3/pyomo/contrib/mindtpy/MindtPy.py availableCszMindtPySolver.availablecCstS)z/Return a 3-tuple describing the solver version.) __version__)rrrr versionJszMindtPySolver.versionc Ks||di}|||jrFd|_d|_d|_d|_|j d|j dkrVd|_|j dkrd|_d|_d|_ d|_ d|_d|_|jd krd|_|jd kr|j|_t|jtdd }|jd krd|_t}t|_t|_g|_g|_|jr t ||j d ||_!|"|_#|j r2t$d%|j#|j&r@t'j(nd }t)|jdddt*|j|t+|j#d||j d|j#j,}t-||t.|||j dt/dd|j0D|_1d |_2d |_3dt4|j |jj5_6t7||sd St8}|_9|:t;dd|_t;dd| _?| j?:d |_@d |_Ad |_BtCd|_DtCd|_E|jDg|_F|jEg|_G|jr|jri|_H|j dkr|jri|_ItJdd| _KtJdd| _L|jMdks|jMdkrtJd d!tN|jOdDd"d#|_PtQ|jPtRdd$|_SntQtRdd$|_S|jr>tTd |j fd tRd%| _Ud|_V|jd&krtW|j#d'sntXtXjYd(|j#_ZtW|j#d)stXtXjYd(|j#_[t)|jd*t\||Wd QRXt)|jd+t]||Wd QRX|j2d k rt^|j2j,j0|j0|d,t^|j0|j!tQ||jD|jj__`|jE|jj__aWd QRXWd QRXWd QRX|j|jj5_|jjb|jj5_c|jjb|jj5_d|jA|jj5_e|j3|jj5_3|jr|j@|jfd-krdnd |jj5_g|jS).aPSolve the model. Warning: this solver is still in beta. Keyword arguments subject to change. Undocumented keyword arguments definitely subject to change. Warning: at this point in time, if you try to use PSC or GBD with anything other than IPOPT as the NLP solver, bad things will happen. This is because the suffixes are not in place to extract dual values from the variable bounds for any other solver. TODO: fix needed with the GBD implementation. Args: model (Block): a Pyomo model or block to be solved optionsrFZcplex_persistentzTSingle tree implementation is activated. The defalt MIP solver is 'cplex_persistent'gZGOATZbaronN)ctypeactiverz/Use the fbbt to tighten the bounds of variableszcontrib.integer_to_binarytotal)Z is_main_timer MindtPy_utilsz---Starting MindtPy---)use_mcppcss|] }|jVqdS)N)value).0vrrr sz&MindtPySolver.solve..MindtPyzFeasibility Problem Constraints)rz integer cutszexplored integer cutsz-infinf)ZdimenZL1ZL2cSs"g|]\}}|jdkr|qS))rr)bodypolynomial_degree)r+iZconstrrrr sz'MindtPySolver.solve..z{Integer index set over the nonlinear constraints.The set corresponds to the index of nonlinear constraint in constraint_set) initializer)domainr4)Zboundsr4r5Zipopt ipopt_zL_out) direction ipopt_zU_outZinitializationz main loop) from_listZto_listconfigZrNLP)hCONFIGpop set_valueZ single_treeZiteration_limitZ add_slackZadd_nogood_cutsZ mip_solverloggerinfoZ max_slackZstrategyr)Zinteger_to_binaryZuse_dualZuse_fbbtZ nlp_solverZ ecp_toleranceZbound_tolerancenextZcomponent_data_objectsrexprr1Zuse_dual_boundr rresultsrZtimingZ curr_int_solZ prev_int_solrZoriginal_modelcloneZ working_modelrZapply_toteeloggingINFOrrrr(rrlistZ variable_listZinitial_var_valuesZbest_solution_foundZbest_solution_found_timestrZsolvernamer r Z MindtPy_feasZ deactivaterZfeas_constraintsZMindtPy_linear_cutsZ integer_cutsZfeasible_integer_cutsZnlp_iterZmip_iterZ mip_subiterfloatZLBZUBZ LB_progressZ UB_progressZ stored_boundZnum_no_good_cuts_addedrZ nlp_itersZ mip_itersZfeasibility_norm enumerateZconstraint_listZnl_constraint_setrrZ slack_varrZ slack_varsZsolution_improvedhasattrrZIMPORTr6r8r r rZproblemZ lower_boundZ upper_boundr'Z user_timeZwallclock_timeZ iterationsZ init_strategyZ num_nodes) rmodelkwdsr:objZ solve_dataZnew_logging_levelr.ZfeasZlinrrr solveNs                           *   zMindtPySolver.solvecCs|S)Nr)rrrr __enter__szMindtPySolver.__enter__cCsdS)Nr)rtr, tracebackrrr __exit__szMindtPySolver.__exit__N)T) __name__ __module__ __qualname____doc__rr;r!r#rPrQrTrrrr r;s Mr)+rX __future__rrEZpyomo.contrib.gdpopt.utilrrrrrrZ$pyomo.contrib.mindtpy.initializationr Zpyomo.contrib.mindtpy.iterater Zpyomo.contrib.mindtpy.utilr r Z pyomo.corer rrrrrrrrZ pyomo.optrrZpyomo.common.collectionsrZpyomo.contrib.fbbt.fbbtrZ$pyomo.contrib.mindtpy.config_optionsr getLoggerr>r"registerobjectrrrrr s"    ,