# ergo-code/highs architecture

> Architecture diagram of the GitHub repository ergo-code/highs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ergo-code/highs
- Repository: https://github.com/ergo-code/highs

## Overview

##### Main components
- Core Solver Engine – The heart of HiGHS resides in the “src” directory. This includes multiple submodules such as:
– lp_data: Data structures for models, options, and core routines.
– simplex: The revised simplex solvers for LP.
– ipm (interior point methods): Implements the interior point algorithms.
– mip: Mixed Integer Programming components.
– qpsolver and pdlp: Modules for quadratic programming and advanced linear programming.
– presolve: Components to precondition, simplify, or analyze the optimization model.
– model and parallel: Support for model construction and parallel execution.
- Interfaces – Found in “src/interfaces” (and mirrored by files under “app” and “examples”). They provide language bindings for C, C#, Python, and Fortran. These components serve as entry points for external usage.
- I/O and File Readers – Located in “src/io”, these components handle reading LP, MPS and other file formats.
- Command Line & Demo – The “app” directory contains files like RunHighs.cpp and CLI11.hpp that support a command-line interface and possibly a web demo (“highs_webdemo_shell.html”), which acts as an additional frontend.
- Build and Test Infrastructure – Multiple build system files (CMakeLists.txt, bazel files, meson.build), custom check routines under the “check” directory, and extensive GitHub Actions workflows (under “.github/workflows”) show that the project has robust CI/CD and testing in place.
- External Dependencies – The “extern” folder includes third-party libraries such as pdqsort, catch.hpp, and zstr for additional functionality.
- Documentation – The “docs” directory maintains generated documentation alongside scripts to produce API and user documentation.
- Examples – The “examples” directory offers numerous use case scripts in C, C++, Python, etc., illustrating how to interface with the solver.

##### Out relationships and interactions
- Input Flow – Data (e.g., MPS/LP files) is ingested through I/O modules (in “src/io”) and preprocessed (using “src/presolve”).
- Core Processing – The processed data is then sent to the optimization solvers (simplex, ipm, mip, qpsolver, etc.) that perform the heavy lifting.
- Output Flow – Results are stored or output via designated I/O mechanisms.
- Interfaces – They wrap around the core library, allowing different programming languages and applications to invoke the solver. They communicate with the core engine by using shared headers (e.g., “Highs.h” in “src/”) and specialized interface files.
- Build/Integration – The multiple build scripts and configuration files (CMakeLists.txt, BUILD.bazel, meson.build) indicate that the system is designed for cross-platform builds and integration testing. CI pipelines coordinate the building, testing, and code quality checks.

##### Design patterns and design principles
- Layered Architecture – Separate layers for the core optimization logic, I/O processing, and user interfaces.
- Modular Design – Each functionality (simplex, ipm, mip, etc.) is encapsulated in its own module with organized directories.
- Multi-interface Support – Separate modules for C, C#, Fortran, and Python interact with the central engine, suggesting the use of thin wrapper patterns.
- Build System Abstraction – Support for multiple build systems (CMake, Meson, Bazel) indicates an emphasis on portability and maintainability.

##### Relevant technologies and frameworks
- Languages: Mainly C++ (with some C), and interfaces for Python (highspy), C, C#, and Fortran.
- Build Tools: CMake, Bazel, Meson, and Nix (for reproducibility).
- Testing and CI: Extensive suite of unit tests (in “check” and “tests”) and CI workflows configured in GitHub Actions.
- External Libraries: Utilizes lightweight libraries from “extern” (e.g., catch.hpp for testing and pdqsort for efficient sorting).

##### Summarize the key architectural components
- Frontend/CLI: Handles command line input and demo (in “app”).
- Core Computation Layer: Contains the optimization algorithms in “src” split into various modules like lp_data, simplex, ipm, mip, etc.
- I/O Module: Reads, writes, and preprocesses optimization models.
- Multi-language Interfaces: Wrap around the core solver to support different programming environments.
- Build and Test Infrastructure: Manages CI/CD and cross-platform builds.
- Documentation and Examples: Provide user guidance and example usage.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main Data Flow
    A["Input Files"]:::input
    B["I/O Module"]:::io
    C["Preprocessing"]:::io
    E["Result Output"]:::io

    A --> B
    B --> C
    C --> D1

    %% Core Solver Engine Subgraph
    subgraph "Core Solver Engine"
        D1["lp_data"]:::core
        D2["Simplex Solver"]:::core
        D3["Interior Point Methods"]:::core
        D4["Mixed Integer Programming"]:::core
        D5["Quadratic Programming (qpsolver)"]:::core
        D6["Advanced LP (pdlp)"]:::core
        D7["Model Construction"]:::core
        D8["Parallel Execution"]:::core
        D1 --> D2 --> D3 --> D4 --> D5 --> D6 --> D7 --> D8
    end
    D8 --> E

    %% Interfaces Subgraph
    subgraph "Interfaces"
        F1["C/C#/Fortran Interface"]:::interface
        F2["Python Interface"]:::interface
        F1 --> F2
    end
    D8 --> F1

    %% CLI & Demo Subgraph
    subgraph "CLI & Demo"
        G1["CLI"]:::cli
        G2["Web Demo"]:::cli
        G1 --> G2
    end
    G1 --> D1

    %% Support Infrastructure Subgraph
    subgraph "Support Infrastructure"
        S1["Build & Test Infrastructure"]:::support
        S2["CI Workflows"]:::support
        S3["Documentation"]:::support
        S4["Examples"]:::support
        S5["External Dependencies"]:::support
        S2 --> S1
        S3 --> S1
        S4 --> S1
        S5 --> S1
    end
    %% Dashed arrow to represent support integration with core engine
    S1 --- D1

    %% Click Events
    click B "https://github.com/ergo-code/highs/tree/master/src/io"
    click C "https://github.com/ergo-code/highs/tree/master/src/presolve"
    click D1 "https://github.com/ergo-code/highs/tree/master/src/lp_data"
    click D2 "https://github.com/ergo-code/highs/tree/master/src/simplex"
    click D3 "https://github.com/ergo-code/highs/tree/master/src/ipm"
    click D4 "https://github.com/ergo-code/highs/tree/master/src/mip"
    click D5 "https://github.com/ergo-code/highs/tree/master/src/qpsolver"
    click D6 "https://github.com/ergo-code/highs/tree/master/src/pdlp"
    click D7 "https://github.com/ergo-code/highs/tree/master/src/model"
    click D8 "https://github.com/ergo-code/highs/tree/master/src/parallel"
    click F1 "https://github.com/ergo-code/highs/tree/master/src/interfaces"
    click F2 "https://github.com/ergo-code/highs/tree/master/src/highspy"
    click G1 "https://github.com/ergo-code/highs/tree/master/app"
    click G2 "https://github.com/ergo-code/highs/blob/master/app/highs_webdemo_shell.html"
    click S1 "https://github.com/ergo-code/highs/blob/master/CMakeLists.txt"
    click S2 "https://github.com/ergo-code/highs/tree/master/.github/workflows"
    click S3 "https://github.com/ergo-code/highs/tree/master/docs"
    click S4 "https://github.com/ergo-code/highs/tree/master/examples"
    click S5 "https://github.com/ergo-code/highs/tree/master/extern"

    %% Styles
    classDef input fill:#cde,stroke:#333,stroke-width:2px;
    classDef io fill:#ff9,stroke:#333,stroke-width:2px;
    classDef core fill:#bbf,stroke:#333,stroke-width:2px;
    classDef interface fill:#bfb,stroke:#333,stroke-width:2px;
    classDef cli fill:#fc9,stroke:#333,stroke-width:2px;
    classDef support fill:#fdd,stroke:#333,stroke-width:2px;
```
