我无法在 VS Code 或任何其他程序中安装 Mindtpy

问题描述 投票:0回答:1

我已经阅读了整个 Mindtpy 手册,试图了解如何安装或使用它,但我无法安装或使用它。我尝试了类似的事情,例如“pip install mindtpy”或“import mindtpy”。我还尝试安装Mindtpy需要的其他依赖项,例如IPOPT和GLPK,但仍然没有成功。请,我需要知道如何使用它的人的帮助!

具体来说,我需要学习如何在 Visual Studio Code 中安装和使用 Mindtpy。

感谢您的关注,我很感激。

python pyomo
1个回答
0
投票

mintdpy
在安装
pyomo
时作为第三方贡献包安装,但需要外部求解器才能工作。

如果你安装了一个新的python环境并在其中安装了

pyomo
,你就可以将
mindtpy
用作
SolverFactory

假设您正在使用任何类 Unix 系统,请打开终端并输入

  1. 创建一个新环境,激活它并在其中安装
    pyomo
$ python -m venv .env
$ source .venv/bin/activate
(.env) $ pip install pyomo==6.7.0
  1. 安装外部求解器以在
    mindtpy
    中使用。先ipopt,然后cbc
$ sudo apt-get install coinor-libipopt-dev
$ sudo apt-get install coinor-cbc
  1. 写下并解决你的问题。这里我将使用一些修改的mindtpy 示例。您需要使用
    $(.env) python main.py
  2. 激活环境来运行脚本
# This is main.py
from pyomo.environ import *

model = ConcreteModel()

model.x = Var(bounds=(1.0,10.0),initialize=5.0)
model.y = Var(within=Binary)

model.c1 = Constraint(expr=(model.x-4.0)**2 - model.x <= 50.0*(1-model.y))
model.c2 = Constraint(expr=model.x*log(model.x)+5.0 <= 50.0*(model.y))

model.objective = Objective(expr=model.x, sense=minimize)

results = SolverFactory('mindtpy').solve(model, tee=True, mip_solver='cbc', nlp_solver='ipopt') 
print(results)

这应该给你以下输出:

Starting MindtPy version 0.1.0 using OA algorithm
iteration_limit: 50
stalling_limit: 15
time_limit: 600
strategy: OA
add_regularization: None
call_after_main_solve: <pyomo.contrib.gdpopt.util._DoNothing object at 0x7f572970bca0>
call_after_subproblem_solve: <pyomo.contrib.gdpopt.util._DoNothing object at 0x7f572970bcd0>
call_after_subproblem_feasible: <pyomo.contrib.gdpopt.util._DoNothing object at 0x7f572970bd00>
tee: true
logger: <Logger pyomo.contrib.mindtpy (INFO)>
logging_level: 20
integer_to_binary: false
add_no_good_cuts: false
use_tabu_list: false
single_tree: false
solution_pool: false
num_solution_iteration: 5
cycling_check: true
feasibility_norm: L_infinity
differentiate_mode: reverse_symbolic
use_mcpp: false
calculate_dual_at_solution: false
use_fbbt: false
use_dual_bound: true
partition_obj_nonlinear_terms: true
quadratic_strategy: 0
move_objective: false
add_cuts_at_incumbent: false
heuristic_nonconvex: false
init_strategy: rNLP
level_coef: 0.5
solution_limit: 10
sqp_lag_scaling_coef: fixed
fp_cutoffdecr: 0.1
fp_iteration_limit: 20
fp_projcuts: true
fp_transfercuts: true
fp_projzerotol: 0.0001
fp_mipgap: 0.01
fp_discrete_only: true
fp_main_norm: L1
fp_norm_constraint: true
fp_norm_constraint_coef: 1.0
add_slack: false
max_slack: 1000.0
OA_penalty_factor: 1000.0
equality_relaxation: false
linearize_inactive: false
nlp_solver: ipopt
nlp_solver_args:
mip_solver: cbc
mip_solver_args:
mip_solver_mipgap: 0.0001
threads: 0
regularization_mip_threads: 0
solver_tee: false
mip_solver_tee: false
nlp_solver_tee: false
mip_regularization_solver: None
absolute_bound_tolerance: 0.0001
relative_bound_tolerance: 0.001
small_dual_tolerance: 1e-08
integer_tolerance: 1e-05
constraint_tolerance: 1e-06
variable_tolerance: 1e-08
zero_tolerance: 1e-08
obj_bound: 1000000000000000.0
continuous_var_bound: 10000000000.0
integer_var_bound: 1000000000.0
initial_bound_coef: 0.1

-----------------------------------------------------------------------------------------------
               Mixed-Integer Nonlinear Decomposition Toolbox in Pyomo (MindtPy)                
-----------------------------------------------------------------------------------------------
For more information, please visit 
https://pyomo.readthedocs.io/en/stable/contributed_packages/mindtpy.html
If you use this software, please cite the following:
Bernal, David E., et al. Mixed-integer nonlinear decomposition toolbox for Pyomo (MindtPy).
Computer Aided Chemical Engineering. Vol. 44. Elsevier, 2018. 895-900.

Original model has 2 constraints (2 nonlinear) and 0 disjunctions, with 2 variables, of which 1 are binary, 0 are integer, and 1 are continuous.
rNLP is the initial strategy being used.

 ===============================================================================================
 Iteration | Subproblem Type | Objective Value | Primal Bound |   Dual Bound |   Gap   | Time(s)

         -       Relaxed NLP                 1            inf              1      nan%      0.04
         1              MILP                 1            inf              1      nan%      0.07
NLP subproblem was locally infeasible.
Solving feasibility problem
         2              MILP                 1            inf              1      nan%      0.14
*        2         Fixed NLP           2.43845        2.43845              1    58.99%      0.18
         3              MILP           2.43845        2.43845        2.43845    -0.00%      0.20
MindtPy exiting on bound convergence. Absolute gap: -1.2729224785346105e-08 <= absolute tolerance: 0.0001 

 ===============================================================================================
 Primal integral          :    0.0000 
 Dual integral            :    0.2073 
 Primal-dual gap integral :    0.2073
© www.soinside.com 2019 - 2024. All rights reserved.