gpt4 book ai didi

python - CPLEX 的 Python 中的 Bender 分解示例

转载 作者:太空宇宙 更新时间:2023-11-03 14:30:06 25 4
gpt4 key购买 nike

[![在此处输入图像描述][1]][1]我正在运行 CPLEX 通过 eclips 提出的示例中的“bendersatsp.py”。我只在定义“filename=”的主子句中添加了 atsp.dat 的路径。运行后,它似乎只在 len(sys.argv)=1 时执行,并给出以下结果。您知道问题是什么以及为什么它不能完全运行吗?

  Usage:     bendersatsp.py {0|1} [filename]
0: Benders' cuts only used as lazy constraints,
to separate integer infeasible solutions.
1: Benders' cuts also used as user cuts,
to separate fractional infeasible solutions.
filename: ATSP instance file name.
File C:\Program Files (x86)\IBM\ILOG\CPLEX_Studio1261\cplex\examples/data/atsp.dat used if no name is provided.

最佳答案

0|1 参数是必需的。例如,您需要像这样运行脚本:

python bendersatsp.py 0 "C:\Program Files (x86)\IBM\ILOG\CPLEX_Studio1261\cplex\examples/data/atsp.dat"

或者,假设您已更改默认文件名路径:

python bendersatsp.py 0

我在解析下面命令行参数的代码中添加了一些注释,以尝试阐明这一点:

if __name__ == "__main__":
# If there are not 1 or 2 arguments then exit (recall that
# sys.argv[0] is the program name itself (i.e., "bendersatsp.py")
if len(sys.argv) != 2 and len(sys.argv) != 3:
usage()
sys.exit(-1)
# If the first argument is not "0" or "1" then exit.
if sys.argv[1] not in ["0", "1"]:
usage()
sys.exit(-1)
# Store the second argument in filename if there is one.
if len(sys.argv) == 3:
filename = sys.argv[2]
else:
# Otherwise, use the following default.
filename = "../../../examples/data/atsp.dat"
# Pass the arguments into the bendersATSP function.
bendersATSP(sys.argv[1][0], filename)

关于python - CPLEX 的 Python 中的 Bender 分解示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47353127/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com