# process-intelligence-research/relu_ann_milp architecture

> Architecture diagram of the GitHub repository process-intelligence-research/relu_ann_milp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/process-intelligence-research/relu_ann_milp
- Repository: https://github.com/process-intelligence-research/relu_ann_milp

## Overview

##### Main Components
- Library Core (relumip package): This includes the core functionalities to encapsulate the ANN model and generate MIP formulations.
– ann_model.py: Contains abstractions and functions specific to the neural network model formulation.
- Interfaces: A dedicated subpackage (relumip/interfaces) that provides:
– Abstract modeling interface definitions (modeling_interface.py)
– Specific interfaces for Gurobi (gurobi_modeling_interface.py) and Pyomo (pyomo_modeling_interface.py)
– Helper utilities to choose between supported modeling languages (supported_modeling_languages.py and interface_factory.py)
- Utilities (relumip/utils): Contains supporting functionalities like:
– Storage operations (storage.py) for handling data and parameter persistence.
- Documentation & Examples: Provides PDF slides, notebooks, and scripts inside the docs/ and examples/ folder – these show usages and detailed methodology (for instance, “ReLU ANN Slides.pdf” and various Jupyter notebooks).

##### Out Relationships and Interactions
- Data Flow: Start with the input (pre-trained ReLU ANN models) generated externally (e.g., using TensorFlow). These models are then processed by the core ann_model.
- Interface Utilization: The processed neural network model must be converted into a MIP formulation by calling the corresponding interface:
– Decision Logic that decides which modeling interface (Gurobi or Pyomo) to use as per the user’s environment. This can be mediated via interface_factory.py.
- Output Generation: The formulated MIP model is then passed to the underlying optimization solver (e.g., Gurobi, Pyomo with GLPK, etc.) for the target optimization task.
- Auxiliary Utilities: Secondary modules (in utils) support the operation through storage handling and visualization of results or intermediate states.

##### Architectural Patterns & Design Principles
- Layered Abstraction: Observe how the project cleanly separates the core MIP formulation (ann_model) from the solver-specific integration (interfaces). This design supports extensibility.
- Factory Pattern: The interface_factory.py suggests a factory method to instantiate the proper modeling interface, which is a standard design pattern that encourages loose coupling.
- Modularity: Different features (model formulation, solver interface, and visualization) are modularized into separate packages/subdirectories, making the system easier to maintain and extend.

a. Components to Include:
– Pre-trained ANN Input: Represent an external component that supplies the neural network model.
– Interface Layer: Represent this as an abstraction connecting the ANN model processor to:
- Gurobi Modeling Interface
- Pyomo Modeling Interface
– Solver/Optimization Engine: Show the MIP solver used (Gurobi or another Pyomo-compatible solver such as GLPK).
– Utility Modules: Optionally add a block for utilities managing storage and visualization, enhancing understanding of results.
– Examples & Documentation: Include a side note that these components are utilized in user examples and for illustrative purposes.

b. Interactions:
– Indicate data flow between the interfaces and the external solvers, emphasizing the conversion from neural network representations to MIP formulations.

##### Putting It All Together
[Pre-trained ANN Model] → [ANN Model Processing (ann_model)] → [Interface Layer (Gurobi/Pyomo)] → [MIP Solver]
– Emphasize that the separation into these many components is intentional and that each block represents a specific abstraction layer or functionality.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Input
    A["Pre-trained ANN Model"]:::external

    %% Core Processing
    B["ANN Model Processing (ann_model)"]:::core

    %% Interface Layer Subgraph
    subgraph "Interface Layer"
        C["Interface Factory"]:::interface
        D["Gurobi Modeling Interface"]:::interface
        E["Pyomo Modeling Interface"]:::interface
        F["Abstract Modeling Interface Definitions"]:::interface
        G["Supported Modeling Languages Utility"]:::interface
    end

    %% MIP Solver
    H["MIP Solver"]:::external

    %% Utility Modules Subgraph
    subgraph "Utility Modules"
        I["Storage Utility"]:::utility
        J["Visualization Utility"]:::utility
    end

    %% Documentation & Examples Subgraph
    subgraph "Documentation & Examples"
        K["Documentation Materials"]:::doc
        L["Examples & Usage"]:::doc
    end

    %% Data Flow
    A -->|"feeds"| B
    B -->|"processes"| C
    B -->|"uses"| I
    B -->|"uses"| J
    C -->|"selects"| D
    C -->|"selects"| E
    F ---|"defines"| C
    G ---|"supports"| C
    D -->|"formulates"| H
    E -->|"formulates"| H
    B -->|"demonstrated by"| K
    B -->|"demonstrated by"| L

    %% Click Events
    click B "https://github.com/process-intelligence-research/relu_ann_milp/blob/master/relumip/ann_model.py"
    click D "https://github.com/process-intelligence-research/relu_ann_milp/blob/master/relumip/interfaces/gurobi_modeling_interface.py"
    click E "https://github.com/process-intelligence-research/relu_ann_milp/blob/master/relumip/interfaces/pyomo_modeling_interface.py"
    click C "https://github.com/process-intelligence-research/relu_ann_milp/blob/master/relumip/interfaces/interface_factory.py"
    click F "https://github.com/process-intelligence-research/relu_ann_milp/blob/master/relumip/interfaces/modeling_interface.py"
    click G "https://github.com/process-intelligence-research/relu_ann_milp/blob/master/relumip/interfaces/supported_modeling_languages.py"
    click I "https://github.com/process-intelligence-research/relu_ann_milp/blob/master/relumip/utils/storage.py"
    click J "https://github.com/process-intelligence-research/relu_ann_milp/blob/master/relumip/utils/visualization.py"
    click K "https://github.com/process-intelligence-research/relu_ann_milp/blob/master/docs/ReLU ANN Slides.pdf"
    click L "https://github.com/process-intelligence-research/relu_ann_milp/tree/master/examples/"

    %% Styles
    classDef external fill:#FFF3CD,stroke:#856404,stroke-width:2px;
    classDef core fill:#BBDEFB,stroke:#1976D2,stroke-width:2px;
    classDef interface fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
    classDef utility fill:#FFECB3,stroke:#FBC02D,stroke-width:2px;
    classDef doc fill:#E1BEE7,stroke:#8E24AA,stroke-width:2px;
```
