# ura-project/libess architecture

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

- Interactive diagram: https://gitdiagram.com/ura-project/libess
- Repository: https://github.com/ura-project/libess

## Overview

##### Main Components
- Data Layer: Represented by the “data” directories in each variant folder (GA, NSGA, PMSBX_GA, PMSBX_NSGA_II) that hold input files like resource.csv and supply_orders.csv. Additionally, there’s a “save_data” folder holding various JSON and population snapshots which represent the persistent storage of computational results (e.g., best_solution.json, population_gen_X.json).

- Algorithm Engine: This consists of the core optimization modules spread across multiple directories. Each variant has its own implementation:
– GA and NSGA variants have their respective “src/ga” or “src/nsga” subdirectories that include initialization, core algorithm, and utility modules.
– The “check_the_formula” directories, containing crossover.py and mutation.py, indicate encapsulated routines for genetic operators used during evolution.
– The shared “src/algorithm.py”, “src/parameters.py”, and “src/all_packages.py” support the overall execution of the algorithms.

- Visualization Component: The “chart” directories (present in each main variant folder) with the draw_chart.py file are dedicated to plotting and visualizing evolution results like fitness and Pareto fronts. The additional PDF files (evolution_charts.pdf, combined_charts.pdf, etc.) further support the visualization process.

- Entry Points: Each variant has its own main.py which acts as the driver for running that specific algorithm implementation.

- Logging & Reporting: Textual logs and violation indicators (for battery and deadline constraints) as well as the pareto_front related files indicate continuous evaluation and reporting during execution.

- Main Execution (main.py)
- Data Handling: reading input CSV files and saving data (via save_load_data modules and “save_data” directory)
- Algorithm Core: running optimization routines (algorithm.py, parameters.py, and the variant-specific submodules)
- Genetic Operators: using crossover.py and mutation.py from the “check_the_formula” component.
- Visualization: calling chart/draw_chart.py to generate performance charts.

- Data Flow from “data” directories into the Algorithm Engine.
- Algorithm processing results being passed onto the Charting modules.
- Outputs being saved to the “save_data” folder.
- Logging outputs (logfile.log, violation texts, pareto set files) being generated as a result of the algorithm’s execution.

##### Architectural Patterns and Design Principles
- Modularity: Notice how each evolutionary algorithm variant has its own complete structure (with dedicated src, chart, data, and check_the_formula folders). This modular design enhances experimental flexibility and side-by-side comparisons.
- Reuse of Core Components: Shared modules (like algorithm.py, parameters.py, etc.) suggest a design focused on reusability and consistency across different algorithm implementations.
- Separation of Concerns: The clear separation between data management, algorithm logic, and visualization/reporting implies adherence to sound design principles.

##### Putting It Together
- Within this, create sub-clusters for each variant (GA, NSGA, PMSBX_GA, PMSBX_NSGA_II).
- From there, illustrate calls to the algorithm core (algorithm.py, parameters.py, plus the variant-specific submodules in src/ga, src/nsga, etc.).
- Genetic operators as separate nodes linked to the algorithm core.
- Finally, have the algorithm output feed into the chart/draw_chart.py module for generating visualizations, with results and logs stored in save_data and log files.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "LiBESS System"
        
        %% Global nodes
        PS["Persistent Storage"]:::globalComp
        LR["Logging & Reporting"]:::globalComp
        VO["Visualization Output"]:::globalComp

        %% GA Variant
        subgraph "GA Variant"
            GA_Main["Main.py"]:::entry
            GA_Data["Data (CSV)"]:::data
            GA_Algorithm["Algorithm Core"]:::algorithm
            GA_Evolution["Evolution Routine"]:::algorithm
            GA_Operators["Genetic Operators"]:::operator
            GA_SaveLoad["Save/Load Module"]:::algorithm
            GA_Chart["Chart Module"]:::visualization

            GA_Main -->|"triggers"| GA_Data
            GA_Main -->|"triggers"| GA_Algorithm
            GA_Data -->|"loads"| GA_SaveLoad
            GA_Algorithm -->|"executes"| GA_Evolution
            GA_Evolution -->|"uses"| GA_Operators
            GA_Evolution -->|"sends output to"| GA_SaveLoad
            GA_SaveLoad -->|"saves results to"| PS
            GA_SaveLoad -->|"logs activity to"| LR
            GA_SaveLoad -->|"feeds data to"| GA_Chart
            GA_Chart -->|"visualizes"| VO
        end

        %% NSGA Variant
        subgraph "NSGA Variant"
            NSGA_Main["Main.py"]:::entry
            NSGA_Data["Data (CSV)"]:::data
            NSGA_Algorithm["Algorithm Core"]:::algorithm
            NSGA_Evolution["Evolution Routine"]:::algorithm
            NSGA_Operators["Genetic Operators"]:::operator
            NSGA_SaveLoad["Save/Load Module"]:::algorithm
            NSGA_Chart["Chart Module"]:::visualization

            NSGA_Main -->|"triggers"| NSGA_Data
            NSGA_Main -->|"triggers"| NSGA_Algorithm
            NSGA_Data -->|"loads"| NSGA_SaveLoad
            NSGA_Algorithm -->|"executes"| NSGA_Evolution
            NSGA_Evolution -->|"uses"| NSGA_Operators
            NSGA_Evolution -->|"sends output to"| NSGA_SaveLoad
            NSGA_SaveLoad -->|"saves results to"| PS
            NSGA_SaveLoad -->|"logs activity to"| LR
            NSGA_SaveLoad -->|"feeds data to"| NSGA_Chart
            NSGA_Chart -->|"visualizes"| VO
        end

        %% PMSBX_GA Variant
        subgraph "PMSBX_GA Variant"
            PMSBX_GA_Main["Main.py"]:::entry
            PMSBX_GA_Data["Data (CSV)"]:::data
            PMSBX_GA_Algorithm["Algorithm Core"]:::algorithm
            PMSBX_GA_Evolution["Evolution Routine"]:::algorithm
            PMSBX_GA_Operators["Genetic Operators"]:::operator
            PMSBX_GA_SaveLoad["Save/Load Module"]:::algorithm
            PMSBX_GA_Chart["Chart Module"]:::visualization

            PMSBX_GA_Main -->|"triggers"| PMSBX_GA_Data
            PMSBX_GA_Main -->|"triggers"| PMSBX_GA_Algorithm
            PMSBX_GA_Data -->|"loads"| PMSBX_GA_SaveLoad
            PMSBX_GA_Algorithm -->|"executes"| PMSBX_GA_Evolution
            PMSBX_GA_Evolution -->|"uses"| PMSBX_GA_Operators
            PMSBX_GA_Evolution -->|"sends output to"| PMSBX_GA_SaveLoad
            PMSBX_GA_SaveLoad -->|"saves results to"| PS
            PMSBX_GA_SaveLoad -->|"logs activity to"| LR
            PMSBX_GA_SaveLoad -->|"feeds data to"| PMSBX_GA_Chart
            PMSBX_GA_Chart -->|"visualizes"| VO
        end

        %% PMSBX_NSGA_II Variant
        subgraph "PMSBX_NSGA_II Variant"
            PMSBX_NSGA_II_Main["Main.py"]:::entry
            PMSBX_NSGA_II_Data["Data (CSV)"]:::data
            PMSBX_NSGA_II_Algorithm["Algorithm Core"]:::algorithm
            PMSBX_NSGA_II_Evolution["Evolution Routine"]:::algorithm
            PMSBX_NSGA_II_Operators["Genetic Operators"]:::operator
            PMSBX_NSGA_II_SaveLoad["Save/Load Module"]:::algorithm
            PMSBX_NSGA_II_Chart["Chart Module"]:::visualization

            PMSBX_NSGA_II_Main -->|"triggers"| PMSBX_NSGA_II_Data
            PMSBX_NSGA_II_Main -->|"triggers"| PMSBX_NSGA_II_Algorithm
            PMSBX_NSGA_II_Data -->|"loads"| PMSBX_NSGA_II_SaveLoad
            PMSBX_NSGA_II_Algorithm -->|"executes"| PMSBX_NSGA_II_Evolution
            PMSBX_NSGA_II_Evolution -->|"uses"| PMSBX_NSGA_II_Operators
            PMSBX_NSGA_II_Evolution -->|"sends output to"| PMSBX_NSGA_II_SaveLoad
            PMSBX_NSGA_II_SaveLoad -->|"saves results to"| PS
            PMSBX_NSGA_II_SaveLoad -->|"logs activity to"| LR
            PMSBX_NSGA_II_SaveLoad -->|"feeds data to"| PMSBX_NSGA_II_Chart
            PMSBX_NSGA_II_Chart -->|"visualizes"| VO
        end
    end

    %% Click Events for GA Variant
    click GA_Data "https://github.com/ura-project/libess/tree/main/GA/data"
    click GA_Algorithm "https://github.com/ura-project/libess/blob/main/GA/src/algorithm.py"
    click GA_Evolution "https://github.com/ura-project/libess/tree/main/GA/src/ga"
    click GA_Operators "https://github.com/ura-project/libess/tree/main/GA/check_the_formula"
    click GA_SaveLoad "https://github.com/ura-project/libess/blob/main/GA/src/save_load_data.py"
    click GA_Chart "https://github.com/ura-project/libess/blob/main/GA/chart/draw_chart.py"
    click GA_Main "https://github.com/ura-project/libess/blob/main/GA/main.py"

    %% Click Events for NSGA Variant
    click NSGA_Data "https://github.com/ura-project/libess/tree/main/NSGA/data"
    click NSGA_Algorithm "https://github.com/ura-project/libess/blob/main/NSGA/src/algorithm.py"
    click NSGA_Evolution "https://github.com/ura-project/libess/tree/main/NSGA/src/nsga"
    click NSGA_Operators "https://github.com/ura-project/libess/tree/main/NSGA/check_the_formula"
    click NSGA_SaveLoad "https://github.com/ura-project/libess/blob/main/NSGA/src/save_load_data.py"
    click NSGA_Chart "https://github.com/ura-project/libess/blob/main/NSGA/chart/draw_chart.py"
    click NSGA_Main "https://github.com/ura-project/libess/blob/main/NSGA/main.py"

    %% Click Events for PMSBX_GA Variant
    click PMSBX_GA_Data "https://github.com/ura-project/libess/tree/main/PMSBX_GA/data"
    click PMSBX_GA_Algorithm "https://github.com/ura-project/libess/blob/main/PMSBX_GA/src/algorithm.py"
    click PMSBX_GA_Evolution "https://github.com/ura-project/libess/tree/main/PMSBX_GA/src/pmsbx_ga"
    click PMSBX_GA_Operators "https://github.com/ura-project/libess/tree/main/PMSBX_GA/check_the_formula"
    click PMSBX_GA_SaveLoad "https://github.com/ura-project/libess/blob/main/PMSBX_GA/src/save_load_data.py"
    click PMSBX_GA_Chart "https://github.com/ura-project/libess/blob/main/PMSBX_GA/chart/draw_chart.py"
    click PMSBX_GA_Main "https://github.com/ura-project/libess/blob/main/PMSBX_GA/main.py"

    %% Click Events for PMSBX_NSGA_II Variant
    click PMSBX_NSGA_II_Data "https://github.com/ura-project/libess/tree/main/PMSBX_NSGA_II/data"
    click PMSBX_NSGA_II_Algorithm "https://github.com/ura-project/libess/blob/main/PMSBX_NSGA_II/src/algorithm.py"
    click PMSBX_NSGA_II_Evolution "https://github.com/ura-project/libess/tree/main/PMSBX_NSGA_II/src/pmsbx_nsga"
    click PMSBX_NSGA_II_Operators "https://github.com/ura-project/libess/tree/main/PMSBX_NSGA_II/check_the_formula"
    click PMSBX_NSGA_II_SaveLoad "https://github.com/ura-project/libess/blob/main/PMSBX_NSGA_II/src/save_load_data.py"
    click PMSBX_NSGA_II_Chart "https://github.com/ura-project/libess/blob/main/PMSBX_NSGA_II/chart/draw_chart.py"
    click PMSBX_NSGA_II_Main "https://github.com/ura-project/libess/blob/main/PMSBX_NSGA_II/main.py"

    %% Click Event for Persistent Storage
    click PS "https://github.com/ura-project/libess/tree/main/save_data"

    %% Styling
    classDef data fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef algorithm fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef operator fill:#F5DEB3,stroke:#000,stroke-width:2px;
    classDef visualization fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef entry fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef globalComp fill:#E0FFFF,stroke:#000,stroke-width:2px;
```
