Skip to main content

A fast C++ implementation of the Held-Karp algorithm for solving TSP

Project description

toposolve

A fast C++ implementation of the Held-Karp algorithm for solving the Traveling Salesman Problem (TSP) for ring-reduce tours, with Python bindings. We solve a specific variant of TSP where the dist(i, j) is calculated as min(max(dist(i, k), dist(k, j)) for k in range(n)).

Installation

pip install toposolve

Usage

from toposolve import TSPSolver

# Create distance matrix
distances = [
    [0, 10, 15, 20],
    [10, 0, 35, 25],
    [15, 35, 0, 30],
    [20, 25, 30, 0]
]

# Create solver instance
solver = TSPSolver()

# Solve TSP
min_distance, path = solver.solve_tsp(distances)

print(f"Minimum distance: {min_distance}")
print(f"Optimal path: {path}")

Requirements

  • Python 3.6+
  • C++ compiler supporting C++17
  • CMake 3.18+

Building from source

git clone https://github.com/Jackmin801/toposolve
cd toposolve
pip install .

Running tests

pip install pytest
pytest tests/

License

MIT License

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

toposolve-0.1.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

toposolve-0.1.0-cp311-cp311-macosx_13_0_arm64.whl (61.5 kB view details)

Uploaded CPython 3.11 macOS 13.0+ ARM64

File details

Details for the file toposolve-0.1.0.tar.gz.

File metadata

  • Download URL: toposolve-0.1.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for toposolve-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3b96229149efe801fb5a28420ae42cebc0463289aab14766413660c5bf6ea94e
MD5 c717fda1ef5fd44fed10264ed8ad7735
BLAKE2b-256 651d3d0a2fa0a0291801f0b51c7a3c6d1fb5baa2cb2663951f0266e3c331768d

See more details on using hashes here.

Provenance

File details

Details for the file toposolve-0.1.0-cp311-cp311-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for toposolve-0.1.0-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 73a8701e7274de31bb408d611b7466993842cae52c43c9922c9d4649dfc8172d
MD5 57a28198a1f0217653e64045bbecfcb3
BLAKE2b-256 adfe81db48426268ca474f53b204044f4b0ecdd212bfe7cf53b09334a435d7e3

See more details on using hashes here.

Provenance

Supported by

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