fikisipi / elkai

elkai is a Python library for solving travelling salesman problems (TSP) based on LKH 3
Other
177 stars 18 forks source link
elkai optimization python python-tsp travelling-salesman-problem tsp

elkai - a Python library for solving TSP problems

Python build elkai on PyPi


Installation

💾 To install it run pip install elkai

Example usage

import elkai

cities = elkai.Coordinates2D({
    'city1': (0, 0),
    'city2': (0, 4),
    'city3': (5, 0)
})

print(cities.solve_tsp()) # Output: ['city1', 'city2', 'city3', 'city1']
import elkai

cities = elkai.DistanceMatrix([
    [0, 4, 0],
    [0, 0, 5],
    [0, 0, 0]
])

print(cities.solve_tsp()) # Output: [0, 2, 1, 0]

Note

solve_int_matrix and solve_float_matrix 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

⚠️ 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.