Skip to main content

Super simple Python wrapper for LKH-3

Project description

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.

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

lkh-1.0.1.tar.gz (2.1 kB view details)

Uploaded Source

File details

Details for the file lkh-1.0.1.tar.gz.

File metadata

  • Download URL: lkh-1.0.1.tar.gz
  • Upload date:
  • Size: 2.1 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for lkh-1.0.1.tar.gz
Algorithm Hash digest
SHA256 ba542f6208ad2a5cac210257d1893819a9d68dde04fa1ec9ec48d8ba26781b77
MD5 1c7a71951e9aaf5334dd51055aaf31b1
BLAKE2b-256 24ec403a321268a6e0f250f239c60b070be0e0468d86dd4d64bb1e17c9882392

See more details on using hashes here.

Supported by

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