elkai - a Python library for solving TSP problems
- based on LKH by Keld Helsgaun: with proven optimal solutions up to N=315 and more accurate results than Google's OR tools
- asymmetric and symmetric travelling salesman problems support
- clean and simple API: get results with one line calls
💾 To install it run pip install elkai
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.
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.
- 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
.
multiprocessing
module.
If there isn't a prebuilt wheel for your platform, you'll have to follow the scikit-build
process.