Pyomo 未从 ampl 加载求解器('couenne'、'bonmin')

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

当我想使用 pyomo 执行优化时,使用我通过 AMPL 许可证工具安装的求解器之一,在检查求解器的可用性时出现错误。

“couenne”和“bonmin”求解器会发生这种情况。其他求解器似乎工作正常。

如果有人知道问题的解决方案,或者建议使用 couenne 求解器的不同方法,我将不胜感激

例如,当运行以下命令时,

from pyomo.environ import SolverFactory
SolverFactory('couenne').available()

我收到以下错误:

Exception in thread Thread-12:
Traceback (most recent call last):
  File "C:\Users\VictorVerbist\anaconda3\envs\energylib\lib\threading.py", line 980, in _bootstrap_inner
    self.run()
  File "C:\Users\VictorVerbist\anaconda3\envs\energylib\lib\threading.py", line 917, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\VictorVerbist\anaconda3\envs\energylib\lib\subprocess.py", line 1495, in _readerthread
    buffer.append(fh.read())
  File "C:\Users\VictorVerbist\anaconda3\envs\energylib\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 38: character maps to <undefined>

Traceback (most recent call last):

  Cell In[6], line 1
    SolverFactory('Couenne').available()

  File ~\anaconda3\envs\energylib\lib\site-packages\pyomo\solvers\plugins\solvers\ASL.py:123 in available
    return self.version() is not None

  File ~\anaconda3\envs\energylib\lib\site-packages\pyomo\opt\base\solvers.py:443 in version
    self._version = self._get_version()

  File ~\anaconda3\envs\energylib\lib\site-packages\pyomo\solvers\plugins\solvers\ASL.py:109 in _get_version
    ver = _extract_version(results.stdout)

  File ~\anaconda3\envs\energylib\lib\site-packages\pyomo\opt\base\solvers.py:47 in _extract_version
    m = re.search('[t,T]runk', x)

  File ~\anaconda3\envs\energylib\lib\re.py:201 in search
    return _compile(pattern, flags).search(string)

TypeError: expected string or bytes-like object
pyomo ampl
1个回答
0
投票

您可以将 AMPL 求解器模块与 Pyomo 结合使用,如下所示:

from amplpy import modules
import pyomo.environ as pyo
solver = pyo.SolverFactory(modules.find("couenne"), solve_io="nl") 

有关更多信息,请参阅以下文档:https://dev.ampl.com/ampl/python/modules.html#using-from-pyomo

为了使用 couenne 或其他 COIN-OR 求解器,您需要安装 coin 模块,如下所示:

$ python -m amplpy.modules install coin
© www.soinside.com 2019 - 2024. All rights reserved.