Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rshipp/tsp
Defund the Police.
https://github.com/rshipp/tsp
algorithm drop-ice graph python traveling-salesman traveling-salesperson travelling-salesman-problem tsp tsp-solver
Last synced: about 2 months ago
JSON representation
Defund the Police.
- Host: GitHub
- URL: https://github.com/rshipp/tsp
- Owner: rshipp
- Created: 2015-01-26T02:01:34.000Z (almost 10 years ago)
- Default Branch: main
- Last Pushed: 2020-06-14T23:56:54.000Z (over 4 years ago)
- Last Synced: 2024-05-01T19:53:10.351Z (8 months ago)
- Topics: algorithm, drop-ice, graph, python, traveling-salesman, traveling-salesperson, travelling-salesman-problem, tsp, tsp-solver
- Language: Python
- Homepage: https://blacklivesmatters.carrd.co/#donate
- Size: 73.2 KB
- Stars: 19
- Watchers: 3
- Forks: 13
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# Traveling Salesman Problem
[![Drop ICE](drop.png)](https://twitter.com/githubbers/status/1182017616740663296)
Two implementations of solutions to the Traveling Salesman Problem in Python 3.
The first solution brute forces all permutations and is guaranteed to find
the optimal solution for visiting all points.The second solution is "nearest neighbor", which is much faster, but is not
guaranteed to find the optimal solution. In some edge cases, it finds very poor
solutions.My implementations of these algorithms display about O(n!) and 1/4 O(n^2) time,
respectively.## Usage
If you want to run the comparisons yourself, just go
./run.sh
Or, if you want to run individual tests, just use `./optimaltsp.py FILENAME` or
`./nearestneighbor.py FILENAME`.## Graphs
Here are some quick runtime graphs, courtesy of [WolframAlpha](http://www.wolframalpha.com).
### Optimal
[![optimal graph](optimal.png "x-axis is input points; y-axis is seconds")](http://www.wolframalpha.com/input/?i=plot+%286%2C+0.02%29%2C+%288%2C+1.0%29%2C+%289%2C+9.9%29%2C+%2810%2C+184.1%29)
### Nearest neighbor
[![nearest neighbor graph](nn.png "x-axis is input points; y-axis is seconds")](http://www.wolframalpha.com/input/?i=plot%20%289%2C%200%29%2C%20%281500%2C%205%29%2C%20%283000%2C%2019%29%2C%20%286000%2C%20149%29)
## Data