Python 折弯机&x27;CPLEX'中的s分解示例;巨蟒

Python 折弯机&x27;CPLEX'中的s分解示例;巨蟒,python,cplex,decomposition,Python,Cplex,Decomposition,[![enter image description here][1][1]我正在运行CPLEX通过eclips提出的示例中的“bendersatsp.py”。我只在定义了“filename=”的main子句中添加了atsp.dat的路径。运行之后,它似乎只对len(sys.argv)=1执行,并给出以下结果。你知道问题是什么吗?为什么它不能完全运行 Usage: bendersatsp.py {0|1} [filename] 0: Benders' cuts on

[![enter image description here][1][1]我正在运行CPLEX通过eclips提出的示例中的“bendersatsp.py”。我只在定义了“filename=”的main子句中添加了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)

请显示您对bendersatsp.py所做的修改。@rkersh,我刚刚添加了文件名的路径。默认数据是在我的com中的C:\Program Files(x86)\IBM\ILOG\CPLEX\u Studio1261\CPLEX\examples/data/atsp.dat中定义的,因此我只是将其作为文件名放在原始bendersatsp.py中。我还没有更改bendersatsp.py。谢谢您的回复!即使在命令行中,我仍然无法运行该程序。请看我添加的图片。在您的屏幕截图中,您没有使用正确的命令。例如,您需要将
cd
放入bendersatsp.py所在的目录中。然后,运行
c:\Python34\python.exe bendersatsp.py 0
。在发出此命令之前,不要启动Python交互。@rkersh谢谢,你说得对!日食呢?我如何运行它?我不使用Eclipse进行Python开发,但可能会有所帮助。$sys.argv=input('Enter command line arguments:')。split()$这对我很有用!谢谢你的帮助!