https://github.com/nschloe/tspsolve
Solution algorithms for the travelling salesman problem.
https://github.com/nschloe/tspsolve
Last synced: 16 days ago
JSON representation
Solution algorithms for the travelling salesman problem.
- Host: GitHub
- URL: https://github.com/nschloe/tspsolve
- Owner: nschloe
- Created: 2018-07-09T12:30:03.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-07-09T15:50:42.000Z (almost 7 years ago)
- Last Synced: 2025-06-07T08:08:17.128Z (27 days ago)
- Language: Python
- Size: 12.7 KB
- Stars: 1
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# tspsolve
[](https://circleci.com/gh/nschloe/tspsolve/tree/master)
[](https://codecov.io/gh/nschloe/tspsolve)
[](https://github.com/ambv/black)
[](https://pypi.org/project/tspsolve)
[](https://github.com/nschloe/tspsolve)Algorithms for the [traveling salesman problem
(TSP)](https://en.wikipedia.org/wiki/Travelling_salesman_problem) in Python.Implemented so far:
* Nearest neighbor algorithm
```python
import tspsolve# Create matrix of distances d
path = tspsolve.nearest_neighbor(d)
```* [2-opt](https://en.wikipedia.org/wiki/2-opt) improvement
```python
import tspsolve# Create matrix of distances d and an initial path
new_path = tspsolve.two_opt(d, path, verbose=True)
```For [Euclidiean
TSP](https://en.wikipedia.org/wiki/Travelling_salesman_problem#Euclidean_TSP), the
distance matrix can be computed efficiently with
```python
dx = numpy.subtract.outer(x, x)
dy = numpy.subtract.outer(y, y)
d = numpy.sqrt(dx ** 2 + dy ** 2)
```### Installation
tspsolve is [available from the Python Package
Index](https://pypi.org/project/tspsolve/), so simply type
```
pip install -U tspsolve
```
to install or upgrade.### Testing
To run the tspsolve unit tests, check out this repository and type
```
pytest
```### Distribution
To create a new release
1. bump the `__version__` number,
2. publish to PyPi and GitHub:
```
make publish
```### License
tspsolve is published under the [MIT license](https://en.wikipedia.org/wiki/MIT_License).