TSP SYS
AnsweredHello, I am trying to understand the code on the TSP where cuts are added to eliminate subtours, but I still don't quite get the purpose of sys, I don't get
len(sys.arg) > 2
does sys.arg returns a list?
-
Official comment
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?. -
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 -
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 -
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.
Comments
4 comments