使用python解决TSP 旅行商问题)

               

这段时间,因为要交一篇关于旅行商问题的作业,所以在github上搜索了一下,觉得用python解决比较方便,所以给大家简单的介绍一下如何使用所给的代码:

用python实现的TSP源码:  GitHub链接:https://github.com/eldrtimo/python-salesman    百度云盘链接:链接:http://pan.baidu.com/s/1i57BhGx 密码:2w4b

这段代码使用python3实现的,可以在windows的dos环境下运行,而且还要借助于numpy(它是一种开源的python数值计算扩展)。所以必须要安装python3 和 相应的numpy;


1.安装python3

2.配置python的环境变量:把python安装路径添加到path环境变量中即可;

3.安装numpy;如果已安装python,会自动识别出python安装路径,直接点next即可。

这一切准备工作结束后,然后进入dos环境(win+r,输入cmd回车),进入源代码(python-salesman-master)所在目录,我这里是E盘,输入以下命令运行即可:


运行的命令:python main.py -nfi tspfiles


扫描二维码关注公众号,回复: 4998107 查看本文章

运行的结果部分截图如下:



命令中的参数介绍:

python main.py --helpusage: main.py [-h] [-n] [-f] [-i] [-p] PATH [PATH ...]Parse TSP files and calculate paths using simple algorithms.positional arguments:  PATH               Path to directory or .tsp file. If PATH is a directory,                     run on all .tsp files in the directory.optional arguments:  -h, --help         show this help message and exit  -n, --nearest      calculate distance traveled by nearest neighbor heuristic  -f, --furthest     calculate distance traveled by furthest insertion                     heuristic  -i, --in-order     calculate the distance traveled by the in-order-tour                     [1..n,1]  -p, --print-tours  print explicit tours

           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

猜你喜欢

转载自blog.csdn.net/qq_43668086/article/details/86561550