How meco-group/fatrop works
Purpose and entry points
FATROP is a C++ constrained nonlinear optimization library centered on robust interior-point methods. It supports structured optimal control problems (OCP), small dense NLPs, and block-sparse graph NLPs. Public C++ entry points are the umbrella header include/fatrop/fatrop.hpp and problem-specific abstractions such as include/fatrop/ocp/ocp_abstract.hpp, include/fatrop/dense/nlp_dense.hpp, and include/fatrop/graph/nlp_graph.hpp.
Build and deliverables
CMake is the primary build boundary: CMakeLists.txt assembles the library, while src/CMakeLists.txt builds its implementation and c_interface/CMakeLists.txt exposes a C-facing integration. A Docker build is available in Dockerfile. Documentation publishes through GitHub Pages via .github/workflows/gh-pages.yml. Core implementation is C++ with a Python CasADi code-generation package under fatropgen/.
Shared interior-point engine
The reusable solver lifecycle is defined in include/fatrop/ip_algorithm/ip_application.hpp and include/fatrop/ip_algorithm/ip_algorithm.hpp, with construction/configuration in include/fatrop/ip_algorithm/ip_alg_builder.hpp. It owns iterative primal-dual state, initialization, search direction computation, line search/filter acceptance, barrier updates, convergence checks, and restoration for infeasible iterates. Shared algorithm mechanics live in src/ip_algorithm/ip_filter.cpp and src/ip_algorithm/ip_mu_update.cpp; each problem family supplies specialized solver stages.
OCP specialization
The OCP path accepts user model/cost/constraint callbacks through include/fatrop/ocp/ocp_abstract.hpp. include/fatrop/ocp/nlp_ocp.hpp adapts staged dynamics and constraints to the NLP algorithm, while dimensions, derivatives, and Hessian structure are represented by include/fatrop/ocp/dims.hpp, include/fatrop/ocp/jacobian.hpp, and include/fatrop/ocp/hessian.hpp. The OCP primal-dual/KKT solve is specialized in src/ocp/aug_system_solver.cpp and src/ocp/pd_system_orig.cpp, exploiting horizon structure through Riccati-style recursion rather than a generic dense factorization.
Dense NLP specialization
Dense nonlinear programs use the same interior-point concepts but a full dense KKT representation. The boundary is include/fatrop/dense/nlp_dense.hpp; problem metadata and derivative evaluation are in include/fatrop/dense/problem_info.hpp and include/fatrop/dense/jacobian.hpp. src/dense/aug_system_solver.cpp and src/dense/pd_solver_orig.cpp implement its linear-system path. This is the appropriate branch for compact, unstructured NLPs rather than staged dynamics.
Graph NLP specialization
Graph NLP models block variables and sparse Hessian adjacency through include/fatrop/graph/graph_abstract.hpp and include/fatrop/graph/nlp_graph.hpp. Sparse structure is established by include/fatrop/graph/block_sparsity.hpp and include/fatrop/graph/symbolic_factorization.hpp; runtime elimination and numerical linear solution occur in src/graph/elimination_order.cpp, src/graph/symbolic_factorization.cpp, and src/graph/linear_solver.cpp. This branch targets SLAM/bundle-adjustment-like objectives, with block-local inequalities and no equality constraints.
Numerical and integration boundaries
Linear algebra types and solver contracts are centralized in include/fatrop/linear_algebra/linear_algebra.hpp and include/fatrop/linear_algebra/linear_solver.hpp, with BLASFEO integration encapsulated by include/fatrop/linear_algebra/blasfeo_wrapper.hpp. The C API wraps staged OCP applications at c_interface/include/fatrop/ocp/OCPCInterface.h and c_interface/src/OCPCInterface.cpp. Python users can generate/runtime-bind CasADi models through fatropgen/fatropgen/ocp_codegen.py, fatropgen/fatropgen/ocp_direct_solver.py, and the generated C++ runtime interface fatropgen/fatropgen/casadi_utils/ocp_direct_runtime.hpp.
Main entry points: ip_application.hpp IP application · nlp_ocp.hpp OCP-to-NLP adapter · linear_solver.hpp Linear algebra contracts · ip_algorithm.hpp IP algorithm
Components 18
Interior-Point Core
Shared primal-dual solver lifecycle.
- Algorithm builder · Constructs and configures solver applications.
include/fatrop/ip_algorithm/ip_alg_builder.hpp - IP application · Owns iterative primal-dual solver state.
include/fatrop/ip_algorithm/ip_application.hpp - IP algorithm
include/fatrop/ip_algorithm/ip_algorithm.hpp - Filter and barrier updates · Line-search acceptance and barrier parameter updates.
src/ip_algorithm/ip_filter.cpp - Linear algebra contracts · Centralizes matrix types, solver contracts, and BLASFEO wrapping.
include/fatrop/linear_algebra/linear_solver.hpp
OCP Solver
Horizon-structured optimal control specialization.
- OCP model callbacks · User staged dynamics, costs, and constraints.
include/fatrop/ocp/ocp_abstract.hpp - OCP-to-NLP adapter · Adapts staged OCP data to the NLP algorithm.
include/fatrop/ocp/nlp_ocp.hpp - Riccati KKT solver · Exploits horizon structure in the primal-dual solve.
src/ocp/aug_system_solver.cpp
Dense NLP Solver
Full dense KKT specialization.
- Dense NLP boundary · Boundary for compact unstructured nonlinear programs.
include/fatrop/dense/nlp_dense.hpp - Dense KKT solver · Uses a full dense KKT representation.
src/dense/aug_system_solver.cpp
Graph NLP Solver
Block-sparse graph optimization specialization.
- Graph NLP boundary · Models block variables and sparse Hessian adjacency.
include/fatrop/graph/nlp_graph.hpp - Sparse structure · Establishes block sparsity and symbolic factorization.
include/fatrop/graph/symbolic_factorization.hpp - Graph linear solver · Performs runtime elimination and numerical solution.
src/graph/linear_solver.cpp
Integration
Public, C, and Python-facing boundaries.
- Public C++ API
include/fatrop/fatrop.hpp - C OCP API · Wraps staged OCP applications for C callers.
c_interface/include/fatrop/ocp/OCPCInterface.h - CasADi code generation · Generates and runtime-binds CasADi OCP models.
fatropgen/fatropgen/ocp_codegen.py - Generated OCP runtime
fatropgen/fatropgen/casadi_utils/ocp_direct_runtime.hpp
Other components
- CMake build · Builds the library and integrations.
CMakeLists.txt
Connections 21
- CMake build → Public C++ API: packages
- CMake build → C OCP API: builds
- Public C++ API → Algorithm builder: exposes
- Algorithm builder → IP application: constructs
- IP application → IP algorithm: runs
- IP algorithm → Filter and barrier updates: uses
- IP algorithm → Linear algebra contracts: uses
- OCP model callbacks → OCP-to-NLP adapter: supplies callbacks
- OCP-to-NLP adapter → IP application: specializes
- OCP-to-NLP adapter → Riccati KKT solver: forms KKT system for
- Riccati KKT solver → Linear algebra contracts: implements contract
- Dense NLP boundary → IP application: specializes
- Dense NLP boundary → Dense KKT solver: forms KKT system for
- Dense KKT solver → Linear algebra contracts: implements contract
- Graph NLP boundary → IP application: specializes
- Graph NLP boundary → Sparse structure: defines adjacency for
- Sparse structure → Graph linear solver: drives elimination
- Graph linear solver → Linear algebra contracts: implements contract
- C OCP API → OCP-to-NLP adapter: wraps
- CasADi code generation → Generated OCP runtime: generates bindings for
- Generated OCP runtime → OCP model callbacks: implements callbacks