Quick reference

How to call cptp, as a command or a library, and what it prints.

Terminal

# Build the CLI, ./build/cptp-solve, tied to this CPU, from a clone
git clone https://github.com/spoorendonk/cptp && cd cptp
cmake -B build -DCMAKE_BUILD_TYPE=Release -DCPTP_BUILD_TESTS=OFF
# or, portable:
#   cmake -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCPTP_BUILD_TESTS=OFF
cmake --build build --parallel 4

# Install for Python: import cptp, and the cptp command
pip install git+https://github.com/spoorendonk/cptp
# or a portable .whl for another machine, from a clone
pip wheel . -C cmake.build-type=RelWithDebInfo

# Solve a file (path/to/instance.txt: yours, e.g. tests/data/tiny4.txt in a clone)
./build/cptp-solve path/to/instance.txt --time_limit 60 --output_flag false
cptp path/to/instance.txt --time_limit 60

# Every option and default, output lines, exit status (on stdout; also the Options page)
./build/cptp-solve --help
# The Python command's own flags
cptp --help
  • Output. Tour: 0 -> 1 -> 2 -> 0 (Path: for an s–t path), then Objective: <obj>  Bound: <bound>  Gap: <percent>%  Time: <sec>s  Nodes: <count>; the objective is travel cost minus profit, so negative is a gain.

  • cptp-solve exits 0 with a solution (optimal, feasible or at a limit); 1 without one, or on bad arguments or a bad instance file.

  • cptp (python -m cptp) exits the same, but 2 on its own usage errors (argparse), and prints No feasible solution found (status: ...) instead of the Tour and Objective lines.

Python

import cptp

# Solve from arrays
result = cptp.solve(num_nodes, edges, edge_costs, profits, demands, capacity)

# Solve a file in Python, any option
model = cptp.Model()
model.set_problem(cptp.load("path/to/instance.txt"))
result = model.solve([("time_limit", "60")])

C++

Link the target cptp: the C++ reference has the CMake file and an example.

Reference: C++, Python; all the docs as text: https://spoorendonk.dk/cptp/llms.txt, https://spoorendonk.dk/cptp/llms-full.txt.

Instance formats

.vrp, .tsp and .sppcc files are read as TSPLIB, any other file as TSPLIB when its content is, else as numeric.

  • Numeric (.txt): num_nodes num_arcs [m]; per node id profit d_1 .. d_m; per arc tail head cost; the capacities Q_1 .. Q_m; optionally source target (tests/data/tiny4.txt).

  • TSPLIB (.vrp, .tsp): the CVRP format over the complete graph, profits in a PROFIT_SECTION (or a negated NODE_WEIGHT_SECTION), CAPACITY : Q_1 .. Q_m and DEMAND_SECTION lines id d_1 .. d_m; node ids 1-based.

  • SPPCC (.sppcc): SPPRCLIB’s subproblem format, read as TSPLIB with explicit weights and NODE_WEIGHT_SECTION profits.

  • Benchmarks: benchmarks/instances/ holds SPPRCLIB, Roberti and their multicap/ versions with m = 2, 5 and 10.