[![在此处输入图片说明] [1]] [1]我正在运行" bendersatsp.py"来自CPLEX通过eclips提出的示例。我只在main子句中添加了atsp.dat的路径,其中" filename ="被定义为。运行之后,它似乎只对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)
需要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)