PyConcorde
==========
[![Build Status](https://travis-ci.org/jvkersch/pyconcorde.svg?branch=master)](https://travis-ci.org/jvkersch/pyconcorde)
What is it?
-----
PyConcorde is a Python wrapper around the [Concorde TSP
solver](http://www.math.uwaterloo.ca/tsp/concorde.html).
PyConcorde allows you to compute solutions to the Traveling Salesman Problem
with just a few lines of Python code. It uses the state-of-the-art Concorde
solver and provides a convenient Python layer around it.
<p align="center">
<a href="examples/us_state_capitals.py">
<img src="examples/us_state_capitals.png" alt="US state capital tour"/>
</a>
</p>
Note: until commit e065497 (pre version 0.1) PyConcorde was called PyTSP. It
was renamed to emphasize the central role of the underlying Concorde solver.
How do I install it?
------
PyConcorde runs under Python 2.7 and 3.5 and up. It needs the [Concorde TSP
solver](http://www.math.uwaterloo.ca/tsp/concorde.html) and [QSOpt linear
programming library](http://www.math.uwaterloo.ca/~bico/qsopt/). Further
instructions on building/downloading those can be found below.
To build PyConcorde, clone the repository:
git clone https://github.com/jvkersch/pyconcorde
cd pyconcorde
Then run
pip install -e .
This will download and build Concorde (and its dependency QSOpt) and then build
PyConcorde. While this may take a few minutes, downloading Concorde only
happens the first time the install script is run (unless you remove the `data`
directory).
If you already have Concorde and/or QSOpt installed (or an equivalent linear
solver), you can use those instead. Simply set the environment variable
`CONCORDE_DIR` (or `QSOPT_DIR`) to point to the folder where you installed
Concorde (or QSOpt).
Detailed instructions to build Concorde can be found at [this web
page](https://github.com/perrygeo/pytsp/wiki/Installing-Solvers).
What can I do with it?
-------
PyConcorde is a very light-weight library. The main entry point is the
`TSPSolver` class. Here we use it to read in the Berlin52 dataset, a dataset of
52 locations in Berlin (part of the TSPlib test data).
```python
>>> from concorde.tsp import TSPSolver
>>> from concorde.tests.data_utils import get_dataset_path
>>> fname = get_dataset_path("berlin52")
>>> solver = TSPSolver.from_tspfile(fname)
Problem Name: berlin52
Problem Type: TSP
52 locations in Berlin (Groetschel)
Number of Nodes: 52
Rounded Euclidean Norm (CC_EUCLIDEAN)
```
As you can see above, PyConcorde (or rather, Concorde) is somewhat chatty and
will print various message to the standard output. Now that we have a solver
instance, let's compute a solution. On my machine this is almost instantaneous.
```python
>>> solution = solver.solve()
(... output snipped for brevity ...)
```
Again, Concorde will display a variety of messages while it's running. The end
result is a `ComputedTour` object called `solution` with information about the
tour that we just computed:
```python
>>> solution.found_tour
True
>>> solution.optimal_value
7542.0
>>> solution.tour
array([ 0, 48, 31, 44, 18, 40, 7, 8, 9, 42, 32, 50, 10, 51, 13, 12, 46,
25, 26, 27, 11, 24, 3, 5, 14, 4, 23, 47, 37, 36, 39, 38, 35, 34,
33, 43, 45, 15, 28, 49, 19, 22, 29, 1, 6, 41, 20, 16, 2, 17, 30,
21], dtype=int32)
```
Other TSP solvers for Python
----------------------------
If you are looking for a pure Python TSP implementation, check
out [tsp-solver](https://github.com/dmishin/tsp-solver). It is not competitive
with Concorde in terms of speed or memory usage, but has the advantage of being
written in pure Python, which makes it more readily inspectable.
If you have another TSP algorithm that can be called from within Python, and
you want to have it added here, please open an issue.
Technical Notes
-------
PyConcorde needs Concorde and QSOpt. Downloading and building these packages
should happen automatically on Linux/Mac OS, but please file an issue if you
experience any trouble during this step.
Note that Windows is currently unsupported. If you get the library to work on
Windows, please open a ticket to describe any tweaks (or better yet, a Pull
Request).
License
-----
PyConcorde is licensed under the [Modified BSD license](COPYING). Note that
Concorde and QSOpt are released under different licenses, and that PyConcorde
does not include any code from these packages.
没有合适的资源?快使用搜索试试~ 我知道了~
围绕协和TSP求解器 的 Python 包装器_python_代码_下载
共22个文件
py:9个
txt:2个
sh:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 196 浏览量
2022-06-22
15:14:43
上传
评论 1
收藏 87KB ZIP 举报
温馨提示
PyConcorde 允许您只用几行 Python 代码计算旅行商问题的解决方案。它使用最先进的 Concorde 求解器,并围绕它提供了一个方便的 Python 层。 效果展示:https://github.com/jvkersch/pyconcorde/blob/master/examples/us_state_capitals.py 更多详情、使用方法,请下载后阅读README.md文件
资源推荐
资源详情
资源评论
收起资源包目录
pyconcorde-master.zip (22个子文件)
pyconcorde-master
MANIFEST.in 117B
pyproject.toml 60B
concorde
tsp.py 2KB
tests
test_concorde_core.py 2KB
data
berlin52.tsp 916B
test_concorde_datagroup.py 1KB
__init__.py 0B
data_utils.py 596B
util.py 1KB
__init__.py 0B
_concorde.pyx 3KB
tools
build_manylinux.sh 463B
.github
workflows
run-unittests.yml 732B
requirements.txt 13B
examples
us_state_capitals.tsv 2KB
us_state_capitals.png 72KB
requirements.txt 18B
us_state_capitals.py 2KB
setup.py 5KB
.gitignore 69B
README.md 4KB
COPYING 1KB
共 22 条
- 1
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9149
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功