Skip to main content

A TSP solver for Python without any dependencies.

Project description

elkai - a Python 3 TSP solver

elkai is a Python 3 library for solving travelling salesman problems without external dependencies, based on LKH by Keld Helsgaun.

💾 To install it run pip install elkai

💻 Supported platforms: elkai is available on Windows, Linux, OS X for Python 3.5 and above as a binary wheel.

Build status image

Example usage

import elkai
elkai.solve_int_matrix([
    [1, 1],
    [1, 1]
]) # Output: [0, 1]

Documentation

solve_int_matrix(matrix, runs=10) solves an instance of the asymmetric TSP problem with integer distances.

  • matrix: an N*N matrix representing an integer distance matrix between cities.

    An example of N=3 city arrangement:

    [                  # cities are zero indexed, d() is distance
        [0, 4,  9],    # d(0, 0), d(0, 1), d(0, 2)
        [4, 0, 10],    # d(1, 0), d(1, 1), ...
        [2, 4,  0]     # ... and so on
    ]
    
  • runs: An integer representing how many iterations the solver should perform. By default, 10.

  • Return value: The tour represented as a list of indices. The indices are zero-indexed and based on the distance matrix order.

solve_float_matrix(matrix, runs=10) has the same signature as the previous, but allows floating point distances. It may be inaccurate.

FAQ

What's the difference between LKH and elkai?

elkai is a library that contains the LKH solver and has some wrapper code to expose it to Python. The advantage is that you don't have to compile LKH yourself or download LKH executables and then manually parse the output.

How accurately does it solve TSP problems?

Instances with known solutions, which are up to N=315 cities, can be solved optimally.

Can you run multiple threads?

The library doesn't not release the GIL during the solution search, so other threads will be blocked. If you want to solve multiple problems concurrently you may try the multiprocessing module.

P.S.: The LKH solver was written in C with one problem per process in mind. We try to clean up the global state before and after solving a problem, but leaks are possible - if you want to help out, run Valgrind or similar diagnostics and submit an issue/PR.

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-0.0.7.tar.gz (81.7 kB view details)

Uploaded Source

Built Distributions

elkai-0.0.7-cp37-cp37m-win_amd64.whl (91.8 kB view details)

Uploaded CPython 3.7m Windows x86-64

elkai-0.0.7-cp37-cp37m-win32.whl (80.6 kB view details)

Uploaded CPython 3.7m Windows x86

elkai-0.0.7-cp37-cp37m-manylinux1_x86_64.whl (94.9 kB view details)

Uploaded CPython 3.7m

elkai-0.0.7-cp37-cp37m-macosx_10_6_x86_64.whl (95.1 kB view details)

Uploaded CPython 3.7m macOS 10.6+ x86-64

elkai-0.0.7-cp36-cp36m-win_amd64.whl (91.8 kB view details)

Uploaded CPython 3.6m Windows x86-64

elkai-0.0.7-cp36-cp36m-win32.whl (80.6 kB view details)

Uploaded CPython 3.6m Windows x86

elkai-0.0.7-cp36-cp36m-manylinux1_x86_64.whl (94.9 kB view details)

Uploaded CPython 3.6m

elkai-0.0.7-cp36-cp36m-macosx_10_6_x86_64.whl (95.1 kB view details)

Uploaded CPython 3.6m macOS 10.6+ x86-64

elkai-0.0.7-cp35-cp35m-win_amd64.whl (91.8 kB view details)

Uploaded CPython 3.5m Windows x86-64

elkai-0.0.7-cp35-cp35m-win32.whl (80.6 kB view details)

Uploaded CPython 3.5m Windows x86

elkai-0.0.7-cp35-cp35m-manylinux1_x86_64.whl (94.9 kB view details)

Uploaded CPython 3.5m

elkai-0.0.7-cp35-cp35m-macosx_10_6_x86_64.whl (95.1 kB view details)

Uploaded CPython 3.5m macOS 10.6+ x86-64

File details

Details for the file elkai-0.0.7.tar.gz.

File metadata

  • Download URL: elkai-0.0.7.tar.gz
  • Upload date:
  • Size: 81.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.7.tar.gz
Algorithm Hash digest
SHA256 b8d0e5647d3df5477a1f3704072baa7a844afcf058c3dc9796c13998b4ee308e
MD5 19d999cce0dfa7516887bdffe2247e6d
BLAKE2b-256 5666d74e3b103a69a957f7459477582733df50b16ac8aca744666e6ce1fc6e24

See more details on using hashes here.

File details

Details for the file elkai-0.0.7-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: elkai-0.0.7-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 91.8 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.7-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 5806290debc8e856b3aff23100404b46641fe0d48c90d3de80ea54a6d22330fe
MD5 0cb2266ca0ac12700db2c2b204afbbb1
BLAKE2b-256 7a7b62853e2e886ad2c39869c1f4b38b564e791e1803fe950d605244e3546872

See more details on using hashes here.

File details

Details for the file elkai-0.0.7-cp37-cp37m-win32.whl.

File metadata

  • Download URL: elkai-0.0.7-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 80.6 kB
  • Tags: CPython 3.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.7-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 ce2961f6fa2fe8a6a5cc8aadd43a2500e137954dcc906079a09a5330b517bcca
MD5 575bdb40d143168f9a9f46bd91624a75
BLAKE2b-256 4489302ac6f035f58cf9c7d52cf3c3aadb730cc8116b055b3949eefe4560747a

See more details on using hashes here.

File details

Details for the file elkai-0.0.7-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: elkai-0.0.7-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 94.9 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.7-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 d3c191f0691c1bbc970cd65ac974744160b8ff3fd3ccfd85aea902ed068e0d4b
MD5 b688c0a1bc4dbb4a8d2b0f95a6d170bc
BLAKE2b-256 579309258af96da91b753f29b6387724552a7eddfb9d29b0f222b084019018d3

See more details on using hashes here.

File details

Details for the file elkai-0.0.7-cp37-cp37m-macosx_10_6_x86_64.whl.

File metadata

  • Download URL: elkai-0.0.7-cp37-cp37m-macosx_10_6_x86_64.whl
  • Upload date:
  • Size: 95.1 kB
  • Tags: CPython 3.7m, macOS 10.6+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.7-cp37-cp37m-macosx_10_6_x86_64.whl
Algorithm Hash digest
SHA256 927183d22abe1d2aa256532d265ef509c37982062fe7fb8d9623284127db9d2b
MD5 6cf83cc42a1a2ace83abdf22b3e9c946
BLAKE2b-256 dbf5d7ea33512642d36fffd6a47a7b06791fe15a1eb3976bb1936b3bb06243b8

See more details on using hashes here.

File details

Details for the file elkai-0.0.7-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: elkai-0.0.7-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 91.8 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.7-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 5e3289565b91369228d2285dd69e208be288a684276e10c1a4100ad3cce8f439
MD5 c52c90f39b736f5b18c424af410d8fa4
BLAKE2b-256 9e108e1f5d32e2d1b1ba294fbb03821a5b9b2267aaa067fb954e77093bb2eec0

See more details on using hashes here.

File details

Details for the file elkai-0.0.7-cp36-cp36m-win32.whl.

File metadata

  • Download URL: elkai-0.0.7-cp36-cp36m-win32.whl
  • Upload date:
  • Size: 80.6 kB
  • Tags: CPython 3.6m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.7-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 064074416afb662ffe86e4058e0c6ce52b58474dfaaccc5d65a7e89088f9d5e4
MD5 cbb1b0692ff49df8f483a1ff1af10e36
BLAKE2b-256 5f12fb4fcaefebb4bb211707c910213c096118568b9602164c5538ccb581567b

See more details on using hashes here.

File details

Details for the file elkai-0.0.7-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: elkai-0.0.7-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 94.9 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.7-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 e825cff314d4757f359f594620f46db62582132155332e5375a3fedcb43c59f4
MD5 2f2bdb7674fc38589f0dcef56f816d82
BLAKE2b-256 6d763274b679966e484516a3bf916234b1b06e4a9781ea70f02781906285a034

See more details on using hashes here.

File details

Details for the file elkai-0.0.7-cp36-cp36m-macosx_10_6_x86_64.whl.

File metadata

  • Download URL: elkai-0.0.7-cp36-cp36m-macosx_10_6_x86_64.whl
  • Upload date:
  • Size: 95.1 kB
  • Tags: CPython 3.6m, macOS 10.6+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.7-cp36-cp36m-macosx_10_6_x86_64.whl
Algorithm Hash digest
SHA256 daf935f77c1c9aba28e1da740577bf89719c821a9a7bd8084878534d7e4771bb
MD5 75e5a85a663fbc151373a6962be5b5d5
BLAKE2b-256 982914ca79a7d76f244eaafedb809f23b507ab1df2ee2a5e5585ace931f884d2

See more details on using hashes here.

File details

Details for the file elkai-0.0.7-cp35-cp35m-win_amd64.whl.

File metadata

  • Download URL: elkai-0.0.7-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 91.8 kB
  • Tags: CPython 3.5m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.7-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 567e4f59465aaebc183a07bd84c27bb948829144d8d77635584cd382bb3597a4
MD5 2baa3b4992315950e6d45df4659b0744
BLAKE2b-256 3200041701bc8b7119c6be6814a47143e7649ec7e07f145dd8e666adfc9cddac

See more details on using hashes here.

File details

Details for the file elkai-0.0.7-cp35-cp35m-win32.whl.

File metadata

  • Download URL: elkai-0.0.7-cp35-cp35m-win32.whl
  • Upload date:
  • Size: 80.6 kB
  • Tags: CPython 3.5m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.7-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 737ead31578fca527eefd1f7ec20a6518a7c6b3e8c236f488459f638c2bcd493
MD5 ecd26ff9d7bd9cf015d5f68f69eb3b26
BLAKE2b-256 c394279e2525b76c0cc84cb157ce7613a424cdfba4d6f7e36b0d0d997f65e17b

See more details on using hashes here.

File details

Details for the file elkai-0.0.7-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

  • Download URL: elkai-0.0.7-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 94.9 kB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.7-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 bbf3ef07a459afcf8027b582ba93c00ceef0b7c65f5b3c71c32d35fb06f84213
MD5 798f901371cb146c1d3a98cf0e6f3f97
BLAKE2b-256 c3f5238a210c1fd9d3a22d9f04e05351a29601a7d861f9b7e48182e2c1a05157

See more details on using hashes here.

File details

Details for the file elkai-0.0.7-cp35-cp35m-macosx_10_6_x86_64.whl.

File metadata

  • Download URL: elkai-0.0.7-cp35-cp35m-macosx_10_6_x86_64.whl
  • Upload date:
  • Size: 95.1 kB
  • Tags: CPython 3.5m, macOS 10.6+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.7-cp35-cp35m-macosx_10_6_x86_64.whl
Algorithm Hash digest
SHA256 c4a9aa1507d2fa5a1d01b3428ede19e1f0ed798e162af8f19c2b5505a38b41cb
MD5 9c76cdab32440614039282d40fdf83ff
BLAKE2b-256 67da2df84862273fef7bd348f77e14166f62ab3bdfef86effe6de38dc8ad5453

See more details on using hashes here.

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