Pyomo 使用 GLPK 导致错误 - 即使在应用多个解决方案后也找不到求解器

Pyomo using GLPK results in Error - Solver is not found even after applying several solutions

我正在尝试使用 pyomo(版本 6.2)解决线性问题。我已经使用过 Gurobi 和 CPLEX 求解器,它们都有效。现在我正在尝试使用 GLPK,但我总是弹出错误。

import pyomo.environ
import pyomo.environ as pyo    

opt = pyo.SolverFactory('glpk', solver_io="python")
results = opt.solve(model, tee=True)

出现以下错误

The SolverFactory was unable to create the solver "_glpk_direct" and returned an UnknownSolver object. This error is raised at the point where the UnknownSolver object was used as if it were valid (by calling method "solve").

The original solver was created with the following parameters:
    executable: _glpk_direct
    type: _glpk_direct
    _args: ()}

我已经检查了几个解决方案。到目前为止我做了什么:

  1. 我已经按照以下说明安装了 GLPK 4.65:Installing GLPK (GNU Linear Programming Kit) on Windows

  2. 将 glpk 可执行文件添加到 PATH 文件夹。我可以 运行 在 PyCharm 终端和命令提示符中 运行 命令“glpsol --help”

  3. 我已经安装了 glpk 包 (conda install -c conda-forge glpk)

仍然,当前错误仍然弹出,我还没有找到解决此问题的任何其他方法。

在尝试其他开源求解器(如 cbc)并遇到相同问题后,我发现 cbc 的错误也提供了以下信息:

ERROR: Unknown IO type: python

因此,它只是删除了 solver_io="python" 并且成功了。

opt = pyo.SolverFactory('glpk')

不知道为什么会这样