CPLEX 中的 Bender 分解示例 Python
Bender's decomposition example in CPLEX's Python
[![在此处输入图像描述][1]][1]我 运行宁 "bendersatsp.py" 来自 CPLEX 通过 eclips 提出的示例。我只在定义 "filename=" 的主子句中添加了 atsp.dat 的路径。在 运行ning 之后,它似乎只对 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"
或者,假设您更改了默认 filename
路径:
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)
[![在此处输入图像描述][1]][1]我 运行宁 "bendersatsp.py" 来自 CPLEX 通过 eclips 提出的示例。我只在定义 "filename=" 的主子句中添加了 atsp.dat 的路径。在 运行ning 之后,它似乎只对 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"
或者,假设您更改了默认 filename
路径:
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)