Skip to main content

PyLKH

This is a super simple Python wrapper for the constrained traveling salesman and vehicle routing problem solver called LKH-3.

If you want to use this wrapper, you should install LKH-3 first.

LKH-3 expects problems in the TSPLIB95 format. Using PyLKH you can solve problems represented as Python objects (via tsplib95) or files.

Example

import requests
import tsplib95
import lkh

problem_str = requests.get('http://vrp.galgos.inf.puc-rio.br/media/com_vrp/instances/A/A-n32-k5.vrp').text
problem = tsplib95.parse(problem_str)

solver_path = '../LKH-3.0.6/LKH'
lkh.solve(solver_path, problem=problem, runs=10)

Output:

[[26, 7, 13, 17, 19, 31, 21],
 [24, 27],
 [14, 28, 11, 4, 23, 3, 2, 6],
 [29, 18, 8, 9, 22, 15, 10, 25, 5, 20],
 [12, 1, 16, 30]]

API

lkh.solve(solver='LKH', problem=None, **kwargs)

Solve a problem.

Parameters

solver (str, optional): Path to LKH-3 executable.

problem (tsplib95.model.StandardProblem, optional): Problem object. problem or problem_file is required.

kwargs (optional): Any LKH-3 parameter described here. Lowercase works. For example: runs=10.

Returns

routes (list): List of lists of nodes.

Release files for lkh 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lkh 1.0.1
File Size Uploaded
lkh-1.0.1.tar.gz 2.1 kB Details

Release files / lkh-1.0.1.tar.gz

Download URL lkh-1.0.1.tar.gz
Size 2.1 kB
Tags Source
SHA-256 checksum
How to use checksums
ba542f6208ad2a5cac210257d1893819a9d68dde04fa1ec9ec48d8ba26781b77
BLAKE2b-256 checksum
How to use checksums
24ec403a321268a6e0f250f239c60b070be0e0468d86dd4d64bb1e17c9882392
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

Release history Release notifications | RSS feed

2.0.0

1 release file

1.1.1

2 release files

1.1.0

2 release files

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

This release

1.0.1 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page