Skip to main content

TSP SYS

Answered

Comments

4 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?.
  • Jose Vindel
    • Gurobi-versary
    • Thought Leader
    • Investigator

    After reading some documentation on sys, I now know it gives back a list, in the case for the TSP problem what's the list of?

    0
  • Eli Towle
    • Gurobi Staff

    Hi Jose,

    sys.argv is a list of the command-line arguments used when running the program. The first argument is always the name of the program.

    The tsp.py example is meant to be run from the command line with the syntax

    python tsp.py N

    where N is an integer representing the number of random cities to use when solving the TSP. The second argument is used to construct a list of random points:

    n = int(sys.argv[1])
    random.seed(1)
    points = [(random.randint(0, 100), random.randint(0, 100)) for i in range(n)]

    If you want to fix the number of cities within the code rather than specifying it via command-line argument, you can replace the lines

    if len(sys.argv) < 2:
        print('Usage: tsp.py npoints')
        sys.exit(1)
    n = int(sys.argv[1])

    with (e.g.):

    n = 25

    Thanks!

    Eli

    0
  • Jose Vindel
    • Gurobi-versary
    • Thought Leader
    • Investigator

    Thank you so much for your answer, it clarifies a lot. No wonder when I tried to run it from Jupyter Notebook it showed an error message

    0

Post is closed for comments.