0

我编写了一个 Python 脚本,它使用 Pyomo 构建抽象模型,创建具体模型实例,然后使用 Coin-Or Branch-and-Cut (CBC) 求解器求解具体模型。一旦找到最佳解决方案,Python 脚本就会对结果进行一些后处理。当我在家中的 Windows 10 计算机上从命令提示符运行脚本时,它按预期执行。但是,当我通过另一台计算机上的 bash shell 运行脚本时,Python 脚本在调用 CBC 求解器后终止。CBC 求解器写入一个日志文件,显示找到了最佳解决方案,并且 Python 脚本没有引发任何错误。

进入 bash shell 的命令如下:

export LD_LIBRARY_PATH=/home/660/tw9752/Coinbrew/CBC/lib
module load python3/3.9.2
python3 script.py > logfile1.log

出现错误的 script.py 部分是:

instance = model.create_instance() # Create concrete model from abstract model in Pyomo

solverpath_exe='/home/660/tw9752/Coinbrew/CBC/bin/cbc' # Define location of CBC solver binary
opt = pyo.SolverFactory('cbc',executable=solverpath_exe) # Create solver object in Pyomo
opt.options['seconds'] = 1200 # Modify the solver object to terminate the solver if no solution found in time limit
print("success 1") # This line is printed

opt.solve(instance,logfile='logfile2.log') # Solve the concrete model and write a logfile. Successfully executes this line since a logfile is written, stating that optimal solution was found.
print("success 2") # This line does not execute when run from bash terminal. No issue when run from command prompt on my own computer.

“logfile1.log”或 bash 终端中没有打印任何错误,Python 解释器似乎只是在调用求解器后关闭。

当我在自己的计算机上安装 CBC 求解器时,我下载了二进制文件并将它们复制到 anaconda3/Library/bin 中,包括 cbc.exe 文件(带有solverpath_exe = path/to/cbc.exe)。当我在使用 bash shell 的计算机上安装 CBC 求解器时,我使用 coinbrew 来获取和构建求解器(使用solverpath_exe = path/to/cbc)。问题可能是由于solverpath_exe变量调用“cbc”而不是“cbc.exe”吗?当没有引发表明 Python 解释器关闭原因的错误时,如何解决此问题?

4

0 回答 0