# C++ reference The user-facing C++ library, in namespace `cptp`. - Build a `Problem` with `io::load` or `Model`'s setters, then call `Model::solve`. - Its options, `SolverOptions`, are a `std::vector>` of the `(key, value)` pairs in [Options](options.md). ## Using it from CMake Source-only: no install rules, no `find_package`. Build it inside your project and link the target `cptp`, which brings the include root (`src/`) and the patched HiGHS: ```cmake cmake_minimum_required(VERSION 3.25) project(app LANGUAGES CXX) set(CMAKE_CXX_STANDARD 23) # cptp's headers need it set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CPTP_BUILD_TESTS OFF CACHE BOOL "" FORCE) # else it fetches Catch2 include(FetchContent) FetchContent_Declare(cptp GIT_REPOSITORY https://github.com/spoorendonk/cptp.git GIT_TAG v0.3.0) FetchContent_MakeAvailable(cptp) add_executable(app main.cpp) target_link_libraries(app PRIVATE cptp) ``` - **Clone or submodule** in your source tree: `add_subdirectory(cptp)` replaces the `FetchContent` lines. - **First configure** clones and patches HiGHS: it needs network access. - **No build type set**: the build becomes Release, with `-march=native`, tied to this CPU; `RelWithDebInfo` leaves the flag out ([quick reference](quickref.md)). - **No `highs` of your own** (a `FetchContent` declaration or a target) before cptp: FetchContent keeps the first declaration, without cptp's patch, and the build fails. To call HiGHS directly, use the one cptp brings. - **Cache variables for the whole build**: `BUILD_TESTING`, `BUILD_SHARED_LIBS`, `BUILD_EXAMPLES` and `PDLP` are forced `OFF`; `HIGHS_NO_DEFAULT_THREADS` is `ON`, so a HiGHS you call with `threads` 0 starts one thread. Set `BUILD_TESTING` again before testing it after `FetchContent_MakeAvailable(cptp)`. A complete `main.cpp`, run from the clone (it reads `tests/data/tiny4.txt`): ```cpp #include #include "core/io.h" #include "model/model.h" int main() { cptp::Model model; model.set_problem(cptp::io::load("tests/data/tiny4.txt")); auto result = model.solve({{"time_limit", "60"}, {"output_flag", "false"}}); if (!result.has_solution()) { return 1; } std::cout << "objective " << result.objective << ", tour"; for (auto node : result.tour) { std::cout << ' ' << node; } std::cout << '\n'; // objective -11, tour 0 1 2 0 } ``` ## Model ```{doxygenclass} cptp::Model ``` ```{doxygenstruct} cptp::Resource ``` ## Problem ```{doxygenclass} cptp::Problem ``` ```{doxygenstruct} cptp::Edge ``` ## Results ```{doxygenstruct} cptp::SolveResult ``` ```{doxygenstruct} cptp::SeparatorStats ``` ## Loading instances ```{doxygennamespace} cptp::io :content-only: ```