我正在尝试在我的程序生成的一堆 cnf 编码上运行 SAT 求解器。我已经通过自制软件在我的笔记本电脑(MacOS)上安装了 minisat,我可以在终端上运行 minisat:
$ minisat INPUT_FILE.cnf OUTPUT_FILE.txt
但是因为我有数百种编码,所以我使用subprocess
. 编码是在for
循环内生成的。该循环还包含子进程命令,理想情况下,SAT 求解器 (minisat) 在每个循环上运行每个文件。
cnf 编码生成良好,我可以在终端上单独运行它们,但是当我尝试运行使用 subprocess 命令时,它会抛出一个错误说:
FileNotFoundError: [Errno 2] No such file or directory: 'minisat': 'minisat'
这是我的代码(它只是我的代码的一部分,我省略了不相关的部分):
solver = 'minisat'
for i in range...:
encoding = generate_encoding()
cnf = 'generated_cnf_encoding'+ str(i) +'.cnf'
#write encoding to cnf
...
sol = 'empty_output_file'+ str(i) +'.txt'
cmd = [solver, cnf, sol]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, err = p.communicate()
print(err)
编辑:在此处提到的其他几个解决方案中,建议添加,但这会在打印时shell=True
抛出minisat: command not found
err