1

可以在命令行中激活多线程:

$cbc -threads=6
Welcome to the CBC MILP Solver
Version: 2.9.9
Build Date: Aug 21 2017
$command line - cbc -threads=6 (default strategy 1)
threads was changed from 0 to 6

但是当我尝试在 pyomo 代码中激活这个选项时

opt = SolverFactory('cbc')
result = opt.solve(instance, options="threads=4")

我收到一个错误:

File "/usr/local/lib/python3.9/dist-packages/pyomo/opt/base/solvers.py", line 561, in solve
    self.options.update(kwds.pop('options', {}))
  File "/usr/local/lib/python3.9/dist-packages/pyutilib/misc/misc.py", line 360, in update
    if type(d[k]) is dict:
TypeError: string indices must be integers

有任何想法吗?

4

1 回答 1

3

options关键字参数需要一个字典。如果你想使用与命令行相同的语法,你就在options_string

opt.solve(instance, options_string="threads=4")
opt.solve(instance, options={"threads": 4})
于 2021-03-18T10:40:44.487 回答