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.8.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

toposolve-0.1.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (94.9 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for toposolve-0.1.8.tar.gz
Algorithm Hash digest
SHA256 7fee140ec2d12f6f4f64f74483c29d9a9d08de5b7b93f08bbaa3578e080a2d90
MD5 823b57c17471ef8c16f2881f684b8aea
BLAKE2b-256 5a5f3ad60f48b881119cc0a08c7ebad466928a525b125180510897454e734b12

See more details on using hashes here.

File details

Details for the file toposolve-0.1.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for toposolve-0.1.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c86dcdac4f643bcca775c4adde6bfd14bb7e40d0af8177962e3e42636686043b
MD5 f18a38515e7fd2b72d9dbde774e18dae
BLAKE2b-256 24368a9d1ca09aff18d563f4187e72dc10046d35d223173724be84cc4ff7041a

See more details on using hashes here.

Supported by

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