百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
E

elkai

> 编程语言
开源

elkai 是一款 Python 库,用于基于 LKH 3 解决旅行商问题 (TSP)。

200 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

elkai 是一款 Python 库,用于基于 LKH 3 解决旅行商问题 (TSP)。

elkai - a Python library for solving TSP problems


  • based on LKH by Keld Helsgaun: with proven optimal solutions up to N=315 and more accurate results than Google's OR tools
  • asymmetric and symmetric travelling salesman problems support
  • clean and simple API: get results with one line calls

Installation

To install it run pip install elkai

Example usage

python
import elkai

cities = elkai.Coordinates2D({
    'city1': (0, 0),
    'city2': (0, 4),
    'city3': (5, 0)
})

print(cities.solve_tsp()) # Output: ['city1', 'city2', 'city3', 'city1']
python
import elkai

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

print(cities.solve_tsp()) # Output: [0, 2, 1, 0]

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.

Issues· 15 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Pythonelkaioptimizationpythonpython-tsp

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言