# adm91/powersystem-dl architecture

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

- Interactive diagram: https://gitdiagram.com/adm91/powersystem-dl
- Repository: https://github.com/adm91/powersystem-dl

## Overview

##### Main Components
a. Power System Simulation Environment
- Integration with Matpower6.0 and Octave via dependency annotations.

b. Objective Evaluation Module
- “Objective Evaluation” component; include the files in the objective directory (e.g., objective/objective_function.py, objective/cumulative_losses.py, etc.). This module computes various metrics (cumulative lost load, power deviation, etc.) which drive the optimization’s fitness evaluations.

c. Optimization Engine
- You may also note the existence of a “Random Search” for additional methods (optimize/random_search.py).
- These components interact with the simulation to try different restoration action sequences.

d. Restoration Tree and System Structure Component
- A node for “Restoration Tree” (from the tree directory). This typically models the sequential decision-making process in restoration.

e. Visualization and Analysis

f. Supporting Utilities & Auxiliary Functions

g. Testing Framework
- A “Testing Suite” that shows the verification modules (from test directory), ensuring integrity of the simulation, optimization, and system state mechanisms.

##### Interaction and Data Flow
- A feedback loop from the “Simulator” to the “Objective Evaluation Module” which computes performance based on simulated states.
- From the “Objective Evaluation Module,” connect back to the “Optimization Engine” showing fitness and cost metrics informing the selection and mutation processes.
- Auxiliary or utility functions that support these data flows.

##### Architectural Patterns and Design Principles
- Modular separation following a loosely coupled design: Simulation, Optimization, Evaluation, and Visualization work as distinct components.
- Iterative loop between optimization (action proposal) and simulation/evaluation (feedback), a key pattern in reinforcement learning and optimization algorithms.
- Dependency on external systems like Matpower/Octave. This should be annotated on the “Simulator” node.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Modules
    Simulator["Power System Simulator (Matpower6.0,Octave,numpy,matplotlib,oct2py)"]:::simulator
    Objective["Objective Evaluation Module"]:::evaluation
    Restoration["Restoration Tree"]:::restoration
    Visualization["Visualization Module"]:::visualization
    Aux["Auxiliary Utilities"]:::auxiliary
    Testing["Testing Suite"]:::testing

    %% Optimization Engine Subgraph
    subgraph "Optimization Engine"
        Genetic["Genetic Optimization Module"]:::optimization
        Stochastic["Stochastic Optimization Module"]:::optimization
        Random["Random Search Optimization"]:::optimization
    end

    %% Data Flow Connections
    Genetic -->|"simulate"| Simulator
    Stochastic -->|"simulate"| Simulator
    Random -->|"simulate"| Simulator

    Simulator -->|"feedback"| Objective
    Objective -->|"inform"| Genetic

    Simulator -->|"decisionInfo"| Restoration

    Simulator -->|"visualize"| Visualization
    Genetic -->|"visualize"| Visualization
    Stochastic -->|"visualize"| Visualization
    Random -->|"visualize"| Visualization

    %% Auxiliary Utilities Connections (dashed)
    Aux -.-> Simulator
    Aux -.-> Objective
    Aux -.-> Genetic
    Aux -.-> Stochastic
    Aux -.-> Random

    %% Testing Suite Connections (dashed)
    Testing -.-> Simulator
    Testing -.-> Objective
    Testing -.-> Genetic
    Testing -.-> Stochastic
    Testing -.-> Random

    %% Click Events
    click Simulator "https://github.com/adm91/powersystem-dl/blob/master/system/PowerSystem.py"
    click Objective "https://github.com/adm91/powersystem-dl/blob/master/objective/objective_function.py"
    click Genetic "https://github.com/adm91/powersystem-dl/blob/master/optimize/genetic/genetic_alg.py"
    click Stochastic "https://github.com/adm91/powersystem-dl/blob/master/optimize/stochastic/stochastic_tree_search.py"
    click Random "https://github.com/adm91/powersystem-dl/blob/master/optimize/random_search.py"
    click Restoration "https://github.com/adm91/powersystem-dl/blob/master/tree/RestorationTree.py"
    click Visualization "https://github.com/adm91/powersystem-dl/blob/master/visualize/visualize_network.py"
    click Aux "https://github.com/adm91/powersystem-dl/tree/master/auxiliary"
    click Testing "https://github.com/adm91/powersystem-dl/blob/master/test/multithread_matpower.py"

    %% Styles
    classDef simulator fill:#f9c,stroke:#333,stroke-width:2px;
    classDef evaluation fill:#dfd,stroke:#333,stroke-width:2px;
    classDef optimization fill:#bbf,stroke:#333,stroke-width:2px;
    classDef restoration fill:#cfc,stroke:#333,stroke-width:2px;
    classDef visualization fill:#ff9,stroke:#333,stroke-width:2px;
    classDef auxiliary fill:#fdd,stroke:#333,stroke-width:2px;
    classDef testing fill:#ddd,stroke:#333,stroke-width:2px;
```
