CPLEX的Python中Bender的分解示例

2024-06-12 16:36:51 发布

您现在位置:Python中文网/ 问答频道 /正文

[![在此处输入图像说明][1]][1]我正在运行”bendersatsp.py“来自CPLEX通过eclips提出的例子。我只添加了atsp.dat公司在定义了“filename=”的main子句中。伦恩似乎只是在它执行之后才执行的(系统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.

Tags: tonamepyasfilenamedatusedsolutions
1条回答
网友
1楼 · 发布于 2024-06-12 16:36:51

0 | 1参数是必需的。例如,需要按如下方式运行脚本:

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

或者,假设您已经更改了默认的filename路径:

^{pr2}$

我在解析以下命令行参数的代码中添加了一些注释,试图使这一点更清楚:

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)

相关问题 更多 >