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 numpy as np
import elkai

M = np.zeros((3, 3), dtype=int)
M[0, 1] = 4
M[1, 2] = 5
elkai.solve_int_matrix(M) # Output: [0, 2, 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 its executables and then manually parse the output. Note that elkai and its author are not affiliated with the LKH project. Note: Helsgaun released the LKH project for non-commercial use only, so elkai must be used this way too.

How to manually build the library?

You need CMake, a C compiler and Python 3.5+. You need to install the dev dependencies first: pip install scikit-build ninja. To build the library, run python setup.py build and python setup.py install to install it. To make a binary wheel, run python setup.py bdist_wheel.

How accurately does it solve asymmetric 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.9.tar.gz (1.5 MB view details)

Uploaded Source

Built Distributions

elkai-0.0.9-cp38-cp38-win_amd64.whl (79.7 kB view details)

Uploaded CPython 3.8 Windows x86-64

elkai-0.0.9-cp38-cp38-win32.whl (72.2 kB view details)

Uploaded CPython 3.8 Windows x86

elkai-0.0.9-cp38-cp38-manylinux1_x86_64.whl (94.9 kB view details)

Uploaded CPython 3.8

elkai-0.0.9-cp38-cp38-macosx_10_14_x86_64.whl (93.8 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

elkai-0.0.9-cp37-cp37m-win_amd64.whl (79.7 kB view details)

Uploaded CPython 3.7m Windows x86-64

elkai-0.0.9-cp37-cp37m-win32.whl (72.2 kB view details)

Uploaded CPython 3.7m Windows x86

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

Uploaded CPython 3.7m

elkai-0.0.9-cp37-cp37m-macosx_10_14_x86_64.whl (93.8 kB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

elkai-0.0.9-cp36-cp36m-win_amd64.whl (79.7 kB view details)

Uploaded CPython 3.6m Windows x86-64

elkai-0.0.9-cp36-cp36m-win32.whl (72.2 kB view details)

Uploaded CPython 3.6m Windows x86

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

Uploaded CPython 3.6m

elkai-0.0.9-cp36-cp36m-macosx_10_14_x86_64.whl (93.8 kB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

elkai-0.0.9-cp35-cp35m-win_amd64.whl (91.2 kB view details)

Uploaded CPython 3.5m Windows x86-64

elkai-0.0.9-cp35-cp35m-win32.whl (81.2 kB view details)

Uploaded CPython 3.5m Windows x86

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

Uploaded CPython 3.5m

elkai-0.0.9-cp35-cp35m-macosx_10_14_x86_64.whl (93.8 kB view details)

Uploaded CPython 3.5m macOS 10.14+ x86-64

File details

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

File metadata

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

File hashes

Hashes for elkai-0.0.9.tar.gz
Algorithm Hash digest
SHA256 eb065f2d82ccd6ae8b0195545077a7cacb94e5d07e009359272b42f521fe664b
MD5 f4f402405a890915ff536384025a9cbb
BLAKE2b-256 3ac20552360cb34f0a7d0137cfe9f4849a0e54bd2c00a7e96ad432a6cfeadb21

See more details on using hashes here.

File details

Details for the file elkai-0.0.9-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: elkai-0.0.9-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 79.7 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.9-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 c7adf84177d6be5c4d510ef1a887b93bf7f1ca0c15ccea8946f19974d960744d
MD5 9dfb61af0675a6362c82e40d8c43ae4c
BLAKE2b-256 934acf0d1dbdd5bce6766f1420bb6996bce1f90d0492e0ab184fa324750bf441

See more details on using hashes here.

File details

Details for the file elkai-0.0.9-cp38-cp38-win32.whl.

File metadata

  • Download URL: elkai-0.0.9-cp38-cp38-win32.whl
  • Upload date:
  • Size: 72.2 kB
  • Tags: CPython 3.8, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.9-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 69034913cf4ad352603aec825bb951e0e0820e01d18b78a26bfdd5ddb614d638
MD5 8de62a81b0bf1d488542c2d15eb77226
BLAKE2b-256 7d7f19620ae8d8878892a395022dd0af140094d9f7a4437985a7ccbc9c704f88

See more details on using hashes here.

File details

Details for the file elkai-0.0.9-cp38-cp38-manylinux1_x86_64.whl.

File metadata

  • Download URL: elkai-0.0.9-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 94.9 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.9-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 550d71747ff2e64e8902d7269a7fb1184f71051e9386ef4bfb7e4dac230aac3d
MD5 90e061f20405573a614c8bcfc1dce2b7
BLAKE2b-256 dc72f4590a31e479ad435955dfd7fb9dfe364a1ebe74c229ea5ab6d4f3aa2000

See more details on using hashes here.

File details

Details for the file elkai-0.0.9-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: elkai-0.0.9-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 93.8 kB
  • Tags: CPython 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.9-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 ae8458016ed286452236b6340b9675b600850a4ab64ad782118b4daa8fb45807
MD5 87f7feba4668dcd61ca0f6bebdb42da1
BLAKE2b-256 c9bb73ceb0ec72463ebb9bd7d6b6c84f17bcf8c5b98aa0de024b5d88461d5da3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: elkai-0.0.9-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 79.7 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/39.1.0 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.9-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 a9465e3b7bd2470d1cfe2bb05e34407a214b988bd6c1365b68d902232b39bd19
MD5 9063416a48c273fb4beae8fffedf8c19
BLAKE2b-256 94975ee03b2ed5dd9d455685dc541abd0f418dd4e9fa1adf6201940c8c157dcc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: elkai-0.0.9-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 72.2 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/39.1.0 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.9-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 0c214be073c249a4d7b3689ad1cbf176a1ce15998a7819480d953c21276fb2c5
MD5 1f019264092ab8214889be761b35c984
BLAKE2b-256 41d2aa0ba3615f83f7e502bac10dd76255542b9eb6bfdac454d9e2f46db66f25

See more details on using hashes here.

File details

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

File metadata

  • Download URL: elkai-0.0.9-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/39.1.0 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.9-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 c65a5f2efa2766f040a9ac2f8e4b01cb94afa2637111197dd7bb8827f0f01c72
MD5 82561b2cbaf2813645dc6d24f61af620
BLAKE2b-256 e7421a350ecf25535cd3f11dc621c8f233435fc02429f671836e1f6b1b2824de

See more details on using hashes here.

File details

Details for the file elkai-0.0.9-cp37-cp37m-macosx_10_14_x86_64.whl.

File metadata

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

File hashes

Hashes for elkai-0.0.9-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 dee06dff0284f4ba921fa9a27572c74db35acb1fa090c310ff400a792155c88c
MD5 be36dbaa133c22ecc78d2b4738634235
BLAKE2b-256 309cf7c6da4f7dee6bf421783fb6f6207cebd2a71c288f0ac1dbc01ae11d98cc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: elkai-0.0.9-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 79.7 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/39.1.0 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.9-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 6e82af6d94a4760d6749fc62881054c70503a9b1f82b693d34a529c74836c835
MD5 111201c22a6ea9210275c4457e0e007e
BLAKE2b-256 49c2f7e53266695917f87f664a5646f698ac80e1ac103162e9d525f5e5cbfc8c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: elkai-0.0.9-cp36-cp36m-win32.whl
  • Upload date:
  • Size: 72.2 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/39.1.0 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.9-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 a9e881728aa9ba5116264d2fa63cb6ff9a23c8fd4ff4172494bb6cc2ac9fab75
MD5 d9fef7b995c8a0aae4eda514d2a2cc01
BLAKE2b-256 62eb0ce1b0e0278fb75eca5ae98a68e9c3da441a9f63659a06b7c96b15845c41

See more details on using hashes here.

File details

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

File metadata

  • Download URL: elkai-0.0.9-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/39.1.0 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.9-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 8e567be947a40c222d899e76472e6aec580a502f7d03283d7966197eb51bf724
MD5 b3c7fb9c6bbdd497dedfe8b6f7f9c1d3
BLAKE2b-256 4224d2adac081a1cf4dcefdbdd76b6dc570ad257cd3d82f4328ab18f9aad3eb4

See more details on using hashes here.

File details

Details for the file elkai-0.0.9-cp36-cp36m-macosx_10_14_x86_64.whl.

File metadata

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

File hashes

Hashes for elkai-0.0.9-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 1340731c416dd742030df01f4e09c3f24b044a8625635985cd2d84899d50eb88
MD5 fbac5ec184c6fd6aafd2948b5cc8e8dc
BLAKE2b-256 070da55b00a5541973ac270d69ca55711ae19febccfe6be0384ba1172ac24d81

See more details on using hashes here.

File details

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

File metadata

  • Download URL: elkai-0.0.9-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 91.2 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/39.1.0 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.9-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 e7fbeb232e5dceee669d70107e89f38b6a05d8eb5dbfe3df5f0c48c7ebe2bb92
MD5 b5de51cfce184341b7baaaca91eddc46
BLAKE2b-256 667f740b5bd34eb2c3ca977251c3dcbd97aab39193a1a445e21f566626c9e772

See more details on using hashes here.

File details

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

File metadata

  • Download URL: elkai-0.0.9-cp35-cp35m-win32.whl
  • Upload date:
  • Size: 81.2 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/39.1.0 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.9-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 e8f4e687e77ccb8520ecb89b5e02cd36e7f9773d717c8035323b1af741cccb13
MD5 6e1535dcf038febebd91a60006ae45a6
BLAKE2b-256 12c48eecb51a8394db61e8258f73107be1a941b8a0b446e490d059e5490e0646

See more details on using hashes here.

File details

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

File metadata

  • Download URL: elkai-0.0.9-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/39.1.0 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for elkai-0.0.9-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 7b2187a085dc2a5ecfd73885d5dccabe8ef8b520a3f617b4c3b06f09da458a61
MD5 9a59a0cf3033fe4a9c597c8e6b1e1fc3
BLAKE2b-256 5dd362f75648da53c5e72ff0ff842cb4d8cf1f48b99d04fc068941a978f2570b

See more details on using hashes here.

File details

Details for the file elkai-0.0.9-cp35-cp35m-macosx_10_14_x86_64.whl.

File metadata

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

File hashes

Hashes for elkai-0.0.9-cp35-cp35m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 1789ed764f0fbb1f738d56031608efa953f3096b3016057b2d7f510776cfb03d
MD5 75667d18b0199903b46dc54e12dd18ed
BLAKE2b-256 0d01c1d8558d1b1afe321b79a6ab8baa3e0246f3989d2ee07f10afa04ab60174

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