Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fikisipi/elkai
elkai is a Python library for solving travelling salesman problems (TSP) based on LKH 3
https://github.com/fikisipi/elkai
elkai optimization python python-tsp travelling-salesman-problem tsp
Last synced: 18 days ago
JSON representation
elkai is a Python library for solving travelling salesman problems (TSP) based on LKH 3
- Host: GitHub
- URL: https://github.com/fikisipi/elkai
- Owner: fikisipi
- License: other
- Created: 2019-05-03T15:06:11.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-05-09T17:34:19.000Z (over 1 year ago)
- Last Synced: 2024-09-28T13:34:59.279Z (about 2 months ago)
- Topics: elkai, optimization, python, python-tsp, travelling-salesman-problem, tsp
- Language: Python
- Homepage:
- Size: 2.9 MB
- Stars: 172
- Watchers: 3
- Forks: 17
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
elkai - a Python library for solving TSP problems
----
* **based on [LKH](http://akira.ruc.dk/~keld/research/LKH/) by Keld Helsgaun**: with proven optimal solutions up to N=315 and more accurate results than [Google's OR tools](https://developers.google.com/optimization/routing/tsp)
* **asymmetric and symmetric** [travelling salesman problems](https://en.wikipedia.org/wiki/Travelling_salesman_problem) support
* **clean and simple API**: get results with one line calls## Installation
💾 **To install it** run `pip install elkai`
## Example usage
```python
import elkaicities = elkai.Coordinates2D({
'city1': (0, 0),
'city2': (0, 4),
'city3': (5, 0)
})print(cities.solve_tsp()) # Output: ['city1', 'city2', 'city3', 'city1']
``````python
import elkaicities = elkai.DistanceMatrix([
[0, 4, 0],
[0, 0, 5],
[0, 0, 0]
])print(cities.solve_tsp()) # Output: [0, 2, 1, 0]
```> **Note**
>
> [solve_int_matrix](https://github.com/fikisipi/elkai/blob/55187e83e7d91ee597b408c8644632fb0ef2687f/elkai/__init__.py#L33) and [solve_float_matrix](https://github.com/fikisipi/elkai/blob/55187e83e7d91ee597b408c8644632fb0ef2687f/elkai/__init__.py#L38) are deprecated in v1. Also, they don't contain the departure to origin in the result by default.## License
The LKH native code by Helsgaun is released for non-commercial use only. Therefore the same restriction applies to elkai, which is explained in the `LICENSE` file.
## How it works internally
* We refactored LKH such that it doesn't have global state and you don't need to restart the program in order to run another input problem
* We added a hook in ReadProblem that allows reading problems from memory instead of files
* We read the solution from the `Tour` variable and put it in a PyObject (Python list).
* ✓ Valgrind passed on `d3d8c12`.⚠️ elkai takes the **global interpreter lock (GIL)** during the solving phase which means two threads cannot solve problems at the same time. If you want to run other workloads at the same time, you have to run another process - for example by using the `multiprocessing` module.
If there isn't a prebuilt wheel for your platform, you'll have to follow the `scikit-build` process.