This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
PyConcorde is a Python wrapper around the Concorde TSP solver. It provides two APIs for solving Traveling Salesman Problems.
This project uses uv for dependency management.
# Install dependencies and build (downloads and builds Concorde + QSOpt automatically on first run)
uv sync
# Run all tests
uv run python -m unittest discover -v .
# Run a single test file
uv run python -m unittest concorde.tests.test_concorde -v
# Run a single test
uv run python -m unittest concorde.tests.test_concorde.TestConcorde.test_solve -vNo separate lint or type-check tooling is configured.
Follow the red/green TDD pattern: always start by writing a failing test, verify it fails, then implement the fix and verify the test passes.
Set CONCORDE_DIR and QSOPT_DIR environment variables to use pre-installed Concorde/QSOpt instead of downloading.
There are two parallel APIs:
Concorde— invokes the Concorde binary as a subprocessProblem— wrapstsplib95to create TSP problems from coordinates, distance matrices, or.tspfilesSolution— parses Concorde's.soloutput files, extracts optimal value and running time- The Concorde binary is located via
find_concorde_binary()which checksexternal/pyconcorde-build/binaries/(git checkout) or falls back to a bundled binary (wheel install)
TSPSolver— uses Cython bindings (concorde/_concorde.pyx) to call Concorde's C library directly- Returns
ComputedTournamedtuple with tour, optimal value, and status flags - The Cython extension links against
concorde.aandqsopt.astatic libraries
pyproject.toml— project metadata and dependenciessetup.py— custom build logic that downloads QSOpt and compiles Concorde from source, then builds the Cython extensionconcorde/_concorde.pyx— Cython bridge to Concorde's C APIconcorde/util.py— TSP file writing utilities andEDGE_WEIGHT_TYPESconstantsconcorde/testing.py— test helpers (temp_folderdecorator,get_dataset_path)- Test data lives in
concorde/tests/data/