Skip to main content

elkai is a Python library for solving travelling salesman problems (TSP) based on LKH 3

Project description

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())
import elkai

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

print(cities.solve_tsp())

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

  • 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

elkai-2.0.1.tar.gz (227.7 kB view hashes)

Uploaded Source

Built Distributions

elkai-2.0.1-cp311-cp311-win_amd64.whl (158.9 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

elkai-2.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (229.3 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

elkai-2.0.1-cp311-cp311-macosx_13_0_arm64.whl (189.9 kB view hashes)

Uploaded CPython 3.11 macOS 13.0+ ARM64

elkai-2.0.1-cp311-cp311-macosx_12_0_x86_64.whl (204.9 kB view hashes)

Uploaded CPython 3.11 macOS 12.0+ x86-64

elkai-2.0.1-cp310-cp310-win_amd64.whl (158.9 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

elkai-2.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (229.3 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

elkai-2.0.1-cp310-cp310-macosx_13_0_arm64.whl (189.9 kB view hashes)

Uploaded CPython 3.10 macOS 13.0+ ARM64

elkai-2.0.1-cp310-cp310-macosx_12_0_x86_64.whl (204.9 kB view hashes)

Uploaded CPython 3.10 macOS 12.0+ x86-64

elkai-2.0.1-cp39-cp39-win_amd64.whl (158.9 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

elkai-2.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (229.3 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

elkai-2.0.1-cp39-cp39-macosx_13_0_arm64.whl (189.9 kB view hashes)

Uploaded CPython 3.9 macOS 13.0+ ARM64

elkai-2.0.1-cp39-cp39-macosx_12_0_x86_64.whl (204.9 kB view hashes)

Uploaded CPython 3.9 macOS 12.0+ x86-64

elkai-2.0.1-cp38-cp38-win_amd64.whl (158.9 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

elkai-2.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (229.3 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

elkai-2.0.1-cp38-cp38-macosx_13_0_arm64.whl (189.9 kB view hashes)

Uploaded CPython 3.8 macOS 13.0+ ARM64

elkai-2.0.1-cp38-cp38-macosx_10_16_x86_64.whl (204.9 kB view hashes)

Uploaded CPython 3.8 macOS 10.16+ x86-64

elkai-2.0.1-cp37-cp37m-win_amd64.whl (158.9 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

elkai-2.0.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (229.3 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

elkai-2.0.1-cp37-cp37m-macosx_10_16_x86_64.whl (204.9 kB view hashes)

Uploaded CPython 3.7m macOS 10.16+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page