# rohanchhipa/polygonga architecture

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

- Interactive diagram: https://gitdiagram.com/rohanchhipa/polygonga
- Repository: https://github.com/rohanchhipa/polygonga

## Overview

##### Main Components
- GA Core Library (PolygonGa.Algorithm): This is the heart of the system. Its subcomponents include:
- AlgorithmRunner: Orchestrates the overall GA process.
- Genetic Operators:
o Crossover Operators: Various implementations (SinglePointCrossover, TwoPointCrossover, UniformCrossover) linked through the ICrossover interface.
o Mutation Operators: Includes PolygonColourMutation, PolygonGrowMutation, PolygonMoveMutation, PolygonRotateMutation, PolygonShearMutation, PolygonShrinkMutation, PolygonSwapMutation – all implementing IMutation.
o Selection Mechanism: TournamentSelection via the ISelection interface.
o Fitness Function: Implementation such as MseFitnessFunction based on the IFitnessFunction interface.
- Polygon Generation: Includes implementations like SquarePolygonGenerator and TrianglePolygonGenerator, tied into IPolygonGenerator interface.
- GA Settings: GaParameters, configuration of evolution parameters (likely controlling mutation rates, population size, etc.).
- Supporting Utilities: Helpers found under Extensions (e.g., PointExtensions) and domain models like Chromosome and ImagePolygon.
- Console Application (PolygonGa.Console): Serves as the user interface that initializes the GA process and triggers the evolution experiment. It depends on the GA Core Library.
- External Resources and Results: The Results directory showing evolved images and animations. This represents persistent outputs of the algorithm.

##### Capturing Component Interactions
- The Console App (PolygonGa.Console) acts as the entry point. It instantiates and configures the GA Core, then triggers the AlgorithmRunner.
- The AlgorithmRunner coordinates the genetic evolution loop by selecting individuals, crossing them over, applying various mutations, and evaluating fitness against a target image.
- Within each evolution cycle, the Selection component (a tournament-style strategy) chooses parent solutions.
- Crossover operators are used to combine genetic material from selected parents.
- Mutation operators then perturb the offspring using various transformations like moving, rotating, or changing polygon attributes.
- The Fitness component calculates the difference between the current evolved image and the target image (using the MSE function) to determine quality.

##### Architectural Patterns and Design Principles
- Modularity: The use of interfaces (ICrossover, IMutation, ISelection, IFitnessFunction, IPolygonGenerator) promotes a plug-and-play architecture where new genetic operators or polygon generators can be added easily.
- Separation of Concerns: The system clearly separates the genetic algorithm logic from the user-facing console application.
- Extensibility: Additional evolutionary operators or polygon types can be introduced with minimal changes due to clear interface boundaries.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Components
    Console["Console Application"]:::console
    GACore["GA Core Library"]:::core

    %% External Resources
    Results["Results (Evolved Images)"]:::results

    %% GA Core Library Subgraphs
    subgraph "GA Core Library"
        %% Genetic Algorithm Engine
        subgraph "Genetic Algorithm Engine"
            AlgorithmRunner["AlgorithmRunner"]:::engine
        end

        %% Operators
        subgraph "Operators"
            %% Selection Mechanism
            subgraph "Selection Mechanism"
                ISelection["ISelection"]:::operators
                Tournament["TournamentSelection"]:::operators
            end
            %% Crossover Operators
            subgraph "Crossover Operators"
                ICrossover["ICrossover"]:::operators
                SinglePoint["SinglePointCrossover"]:::operators
                TwoPoint["TwoPointCrossover"]:::operators
                Uniform["UniformCrossover"]:::operators
            end
            %% Mutation Operators
            subgraph "Mutation Operators"
                IMutation["IMutation"]:::operators
                PolygonColour["PolygonColourMutation"]:::operators
                PolygonGrow["PolygonGrowMutation"]:::operators
                PolygonMove["PolygonMoveMutation"]:::operators
                PolygonRotate["PolygonRotateMutation"]:::operators
                PolygonShear["PolygonShearMutation"]:::operators
                PolygonShrink["PolygonShrinkMutation"]:::operators
                PolygonSwap["PolygonSwapMutation"]:::operators
            end
            %% Fitness Evaluation
            subgraph "Fitness Evaluation"
                IFitness["IFitnessFunction"]:::operators
                MseFitness["MseFitnessFunction"]:::operators
            end
        end

        %% Polygon Generation
        subgraph "Polygon Generation"
            IPolygonGen["IPolygonGenerator"]:::polygon
            SquarePoly["SquarePolygonGenerator"]:::polygon
            TrianglePoly["TrianglePolygonGenerator"]:::polygon
        end

        %% Supporting Models & Utilities
        subgraph "Supporting Models & Utilities"
            Chromosome["Chromosome"]:::support
            ImagePolygon["ImagePolygon"]:::support
            GaParameters["GaParameters"]:::support
            PointExtensions["PointExtensions"]:::support
        end
    end

    %% Component Interactions
    Console -->|"triggers"| AlgorithmRunner
    AlgorithmRunner -->|"selects"| Tournament
    Tournament -->|"calls"| SinglePoint
    SinglePoint -->|"invokes"| PolygonColour
    PolygonColour -->|"evaluates"| MseFitness
    MseFitness -->|"feeds back"| AlgorithmRunner
    AlgorithmRunner -->|"uses"| GaParameters
    AlgorithmRunner -->|"generates"| SquarePoly
    AlgorithmRunner -->|"updates"| Results

    %% Styles
    classDef console fill:#FFF3CD,stroke:#333,stroke-width:2px;
    classDef core fill:#D6EAF8,stroke:#333,stroke-width:2px;
    classDef engine fill:#C8E6C9,stroke:#333,stroke-width:2px;
    classDef operators fill:#FADBD8,stroke:#333,stroke-width:2px;
    classDef polygon fill:#FCF3CF,stroke:#333,stroke-width:2px;
    classDef support fill:#F2D7D5,stroke:#333,stroke-width:2px;
    classDef results fill:#D5F5E3,stroke:#333,stroke-width:2px;

    %% Click Events
    click GACore "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Algorithm"
    click AlgorithmRunner "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Algorithm/AlgorithmRunner.cs"
    click Chromosome "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Algorithm/Chromosome.cs"
    click ImagePolygon "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Algorithm/ImagePolygon.cs"
    click ICrossover "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Algorithm/Crossover/ICrossover.cs"
    click SinglePoint "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Algorithm/Crossover/SinglePointCrossover.cs"
    click TwoPoint "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Algorithm/Crossover/TwoPointCrossover.cs"
    click Uniform "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Algorithm/Crossover/UniformCrossover.cs"
    click IMutation "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Algorithm/Mutation/IMutation.cs"
    click PolygonColour "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Algorithm/Mutation/PolygonColourMutation.cs"
    click PolygonGrow "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Algorithm/Mutation/PolygonGrowMutation.cs"
    click PolygonMove "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Algorithm/Mutation/PolygonMoveMutation.cs"
    click PolygonRotate "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Algorithm/Mutation/PolygonRotateMutation.cs"
    click PolygonShear "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Algorithm/Mutation/PolygonShearMutation.cs"
    click PolygonShrink "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Algorithm/Mutation/PolygonShrinkMutation.cs"
    click PolygonSwap "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Algorithm/Mutation/PolygonSwapMutation.cs"
    click ISelection "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Algorithm/Selection/ISelection.cs"
    click Tournament "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Algorithm/Selection/TournamentSelection.cs"
    click IFitness "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Algorithm/Fitness/IFitnessFunction.cs"
    click MseFitness "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Algorithm/Fitness/MseFitnessFunction.cs"
    click IPolygonGen "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Algorithm/PolygonGenerator/IPolygonGenerator.cs"
    click SquarePoly "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Algorithm/PolygonGenerator/SquarePolygonGenerator.cs"
    click TrianglePoly "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Algorithm/PolygonGenerator/TrianglePolygonGenerator.cs"
    click GaParameters "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Algorithm/GaParameters.cs"
    click PointExtensions "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Algorithm/Extensions/PointExtensions.cs"
    click Console "https://github.com/rohanchhipa/polygonga/blob/develop/PolygonGa.Console/Program.cs"
```
