elkai - a Python 3 TSP solver
====
elkai is a Python 3 library for solving [travelling salesman problems](https://en.wikipedia.org/wiki/Travelling_salesman_problem) without external dependencies,
based on [LKH](http://akira.ruc.dk/~keld/research/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.
[![Python build](https://github.com/fikisipi/elkai/actions/workflows/python-app.yml/badge.svg)](https://github.com/fikisipi/elkai/actions/workflows/python-app.yml)
[![image](https://img.shields.io/pypi/v/elkai.svg)](https://pypi.org/project/elkai/)
Example usage
----------
```python
import numpy as np
import elkai
M = np.zeros((3, 3), dtype=int)
M[0, 1] = 4
M[1, 2] = 5
print(elkai.solve_int_matrix(M))
# Output: [0, 2, 1]
```
Documentation
-------------
**elkai.solve_int_matrix(matrix, runs=10)**:
* `matrix`:
*an N\*N matrix representing an integer distance matrix between cities.*
* N=3 example: (can be any indexed structure: list, numpy array etc)
```python
[ # 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.*
* **Returns**: *The tour represented as a list of indices. The indices are
zero-indexed and based on the distance matrix order.*
**elkai.solve_float_matrix(matrix, runs=10)** has the same signature as the previous, but allows floating point distances.
It may be inaccurate.
FAQ
----------------------
**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 and install, run `python setup.py install`.
**How accurately does it solve asymmetric TSP problems?**
Instances with known solutions, which are up to N=315 cities, [can be solved optimally](http://akira.ruc.dk/~keld/research/LKH/Soler_ATSP_results.html).
**What's the difference between LKH and elkai?**
elkai packages the C LKH code into a nicer C library and then wraps it and compiles it into a Python wheel. **Note:** Dr. Helsgaun has released the LKH project for non-commercial use only, so elkai as a derivative work must be used this way too.
**Does it lock the GIL during a run?**
Yes.
没有合适的资源?快使用搜索试试~ 我知道了~
基于 LKH(跨平台)的 Python 3 旅行商 ( TSP ) 近似求解器_python_代码_下载
共143个文件
c:107个
h:10个
pdf:5个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 2 下载量 71 浏览量
2022-06-22
17:30:03
上传
评论
收藏 1.49MB ZIP 举报
温馨提示
文档 elkai.solve_int_matrix(矩阵,运行=10): matrix: 一个 N*N 矩阵,表示城市之间的整数距离矩阵。 N=3 示例:(可以是任何索引结构:列表、numpy 数组等) [ # 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: 一个整数,表示求解器应该执行多少次迭代。默认情况下,10。 返回:表示为索引列表的游览。索引是零索引的,并且基于距离矩阵顺序。 elkai.solve_float_matrix(matrix, runs=10)与前面的签名相同,但允许浮点距离。它可能不准确。 更多详情、使用方法,请下载后阅读README.md文件
资源推荐
资源详情
资源评论
收起资源包目录
基于 LKH(跨平台)的 Python 3 旅行商 ( TSP ) 近似求解器_python_代码_下载 (143个子文件)
gpx.c 67KB
ReadProblem.c 50KB
ReadParameters.c 42KB
Best5OptMove.c 37KB
Create_POPMUSIC_CandidateSet.c 21KB
_elkai.c 18KB
CreateQuadrantCandidateSet.c 17KB
Delaunay.c 17KB
Flip_SSL.c 16KB
Gain23.c 13KB
GreedyTour.c 13KB
SolveSubproblem.c 13KB
Best4OptMove.c 13KB
BridgeGain.c 11KB
Flip_SL.c 11KB
PatchCycles.c 11KB
SolveKMeansSubproblems.c 9KB
SolveSubproblemBorderProblems.c 9KB
Make5OptMove.c 8KB
BestKOptMove.c 8KB
SolveRoheSubproblems.c 8KB
Ascent.c 8KB
MergeWithTourIPT.c 8KB
SolveDelaunaySubproblems.c 8KB
OrderCandidateSet.c 7KB
Distance.c 7KB
Best3OptMove.c 7KB
Genetic.c 7KB
ChooseInitialTour.c 6KB
LinKernighan.c 6KB
PrintParameters.c 6KB
CreateCandidateSet.c 6KB
C.c 5KB
FindTour.c 5KB
GenerateCandidates.c 5KB
LKHmain.c 5KB
SFCTour.c 4KB
MinimumSpanningTree.c 4KB
SegmentSize.c 4KB
ERXT.c 4KB
Sequence.c 4KB
MergeWithTourGPX2.c 4KB
SolveKarpSubproblems.c 4KB
Best2OptMove.c 4KB
BuildKDTree.c 4KB
CreateDelaunayCandidateSet.c 4KB
Heap.c 3KB
SolveSFCSubproblems.c 3KB
SolveKCenterSubproblems.c 3KB
SolveTourSegmentSubproblems.c 3KB
AllocateStructures.c 3KB
MakeKOptMove.c 3KB
ReadCandidates.c 3KB
WriteTour.c 3KB
ReadEdges.c 3KB
Flip.c 3KB
AdjustCandidateSet.c 2KB
Between_SSL.c 2KB
AddTourCandidates.c 2KB
Hashing.c 2KB
Statistics.c 2KB
Connect.c 2KB
CreateNNCandidateSet.c 2KB
Minimum1TreeCost.c 2KB
KSwapKick.c 2KB
IsPossibleCandidate.c 2KB
FreeStructures.c 2KB
AddExtraCandidates.c 2KB
AdjustClusters.c 2KB
Random.c 2KB
ReadPenalties.c 2KB
GeoConversion.c 1KB
WriteCandidates.c 1KB
ResetCandidateSet.c 1KB
Between_SL.c 1KB
StoreTour.c 1KB
RecordBetterTour.c 1KB
AddCandidate.c 1KB
CandidateReport.c 1KB
SolveCompressedSubproblem.c 1KB
Make4OptMove.c 1KB
ReadLine.c 1KB
RestoreTour.c 966B
MergeTourWithBestTour.c 944B
WritePenalties.c 916B
Between.c 854B
Activate.c 843B
Distance_SPECIAL.c 809B
GetTime.c 806B
fscanint.c 785B
TrimCandidateSet.c 783B
Excludable.c 699B
NormalizeSegmentList.c 631B
FixedOrCommonCandidates.c 623B
Exclude.c 609B
Make3OptMove.c 560B
RemoveFirstActive.c 556B
SymmetrizeCandidateSet.c 512B
NormalizeNodeList.c 502B
RecordBestTour.c 464B
共 143 条
- 1
- 2
资源评论
- m0_692276262023-05-22这个资源对我启发很大,受益匪浅,学到了很多,谢谢分享~
- 非池也2023-05-22非常有用的资源,可以直接使用,对我很有用,果断支持!
快撑死的鱼
- 粉丝: 1w+
- 资源: 9149
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功