How fikisipi/elkai works
Project type and purpose
• elkai is a Python library for solving Travelling Salesman Problems (TSP), wrapping and refactoring the C-based LKH heuristic solver.
• It exposes a clean Python API (Coordinates2D, DistanceMatrix, solve_tsp()) while embedding the LKH codebase as a C extension.
File structure
• Top-level:
• elkai/ – Python package (wrapper code, types, utilities)
• LKH-3.0.8/ – upstream LKH C solver source (Makefile, .c + .h files)
• pyproject.toml, CMakeLists.txt – build and packaging (scikit-build/CMake)
• tests/ – pytest test suite
• README.md, LICENSE – documentation and license
• Key patterns:
• Native C library compiled via CMake (LKH-3.0.8/SRC)
• C extension glue (elkai/_elkai.c) exposing C functions as Python-callable
• Python API layer (elkai/utils.py, elkai/types.py)
• Build/deploy:
• pyproject.toml declares dependencies/build backend
• CMakeLists.txt integrates LKH source into the extension target
README for architecture insights
• Describes refactoring of LKH to eliminate global state
• Hook in ReadProblem to feed problems from memory
• Solution extracted from in-memory Tour structure into Python list
• Warning about GIL during solve phase
• Tests ensure correctness of wrapper and solver