# cptp ```{include} ../README.md :relative-docs: docs/ :relative-images: :start-after: :end-before: ``` % Drawn by figures/make_tour.py from a cptp solve; one copy per colour mode. ```{figure} figures/tour-light.svg :figclass: only-light :align: center :width: 420px :alt: Customers scattered around a depot, sized by profit; the optimal tour visits a group of them to one side of the depot, and the rest are faded. The optimal tour of `E-n76-k7_a` (Roberti Set 3) from the depot (the square): of 75 customers, sized by profit, it visits the 11 worth their travel cost within the vehicle's capacity. ``` ```{figure} figures/tour-dark.svg :figclass: only-dark :align: center :width: 420px :alt: Customers scattered around a depot, sized by profit; the optimal tour visits a group of them to one side of the depot, and the rest are faded. The optimal tour of `E-n76-k7_a` (Roberti Set 3) from the depot (the square): of 75 customers, sized by profit, it visits the 11 worth their travel cost within the vehicle's capacity. ``` ```{include} ../README.md :relative-docs: docs/ :relative-images: :start-after: ``` ```{toctree} :hidden: quickref options results method cpp Python reference ``` # Quick reference How to call cptp, as a command or a library, and what it prints. ## Terminal ```bash # 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: Bound: Gap: % Time: s Nodes: `; 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 ```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](cpp.md#using-it-from-cmake) has the CMake file and an example. Reference: [C++](cpp.md), [Python](https://spoorendonk.dk/cptp/autoapi/cptp/index.html); all the docs as text: , . ## 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`](https://github.com/spoorendonk/cptp/blob/main/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/`](https://github.com/spoorendonk/cptp/tree/main/benchmarks/instances) holds SPPRCLIB, Roberti and their `multicap/` versions with m = 2, 5 and 10. # Solver options - Options are `--key value` pairs on `cptp-solve` and `python -m cptp` (`--help`, `--version`, `--highs_help` and `--verbose` stand alone), and `("key", "value")` tuples in Python's `Model.solve` (which takes the source and target from the problem). - The defaults below hold on every interface. - Only `cptp-solve` has `--highs_help`; only `python -m cptp` has `--verbose`, a flag without a value. - Which capacity rows the row-aware options use: [Method](method.md#several-capacity-rows). The block is `cptp-solve --help`, word for word. ```text cptp-solve — Capacitated Profitable Tour Problem solver Usage: cptp-solve [--source ] [--target ] [--