Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Genetic Algorithm Optimization Framework

Documentation generated by Cascade - An AI-powered coding assistant

A comprehensive Genetic Algorithm (GA) optimization framework for solving complex multi-objective optimization problems. Built with Python backend and interactive web frontend for real-time algorithm visualization and configuration.

Overview

This project implements a flexible genetic algorithm framework capable of optimizing solutions based on multiple criteria including cost, time, and complexity. The system features:

  • Multi-objective optimization with weighted fitness functions
  • Configurable evolutionary operators (crossover, mutation, selection)
  • Interactive web interface for real-time monitoring
  • Dynamic configuration of algorithm parameters
  • Modular architecture for easy extension

Architecture

project/
├── api_layer/          # Flask REST API and web server
├── backend_layer/      # Core GA implementation
│   ├── data_models/    # Chromosome, Gene, Allele data structures
│   ├── evolutionary_functions/  # Crossover, Mutation, Selection operators
│   ├── fitness/        # Fitness calculation functions
│   └── functions/      # Helper utilities
├── data_layer/         # JSON data storage
│   ├── allele_data.json      # Allele definitions
│   ├── chromosome_data.json  # Gene and parameter definitions
│   ├── config.json           # Algorithm configuration
│   └── *_names.json          # Translation files
└── frontend_layer/     # Web UI
    ├── static/css/     # Stylesheets
    └── templates/      # HTML templates

Key Features

1. Algorithm Configuration

Configurable parameters include:

  • Population Size & Generation Count
  • Mutation Probability & Crossover Rate
  • Evolutionary Formulas:
    • Crossover: SBX, Uniform, Single Point, Two Point
    • Mutation: Gaussian, Random Resetting, Swap, Inversion
    • Selection: Tournament (Duplicated/Non-Duplicated), Linear Ranking, Stochastic Universal Sampling
    • Fitness: Balanced, Deviation
  • Weight Parameters for cost/time/complexity balancing
  • Constraint Thresholds (budget, deadline, complexity)

2. Data Model

Chromosome Structure:

  • Contains multiple Genes (tasks to be performed)
  • Each Gene has Parameters with selectable options
  • Each ParameterOption has cost, time, and complexity values
  • Allele represents additional chromosome-level attributes

3. Interactive Web Interface

Main Dashboard:

  • Real-time evolution charts (Cost, Time, Complexity)
  • Best solution highlighting
  • Chromosome population browser
  • Gene-level detail inspection

Configuration Pages:

  • Allele Config: Manage allele types and their probability distributions
  • Chromosome Config: Edit genes, parameters, and options
  • Translations Config: Manage human-readable names for IDs

Quick Start

Prerequisites

  • Python 3.11+
  • Make (optional, for automated setup)

See SETUP.md for detailed installation instructions.

Installation & Run

# Setup (creates venv, installs Poetry)
make setup

# Install dependencies
make install

# Run the Flask web server
make run_web

Access at: http://localhost:5000

Manual Setup (Without Make)

python -m venv venv
.\venv\Scripts\Activate.ps1
pip install poetry
poetry install
poetry run python -m project.api_layer.app

Usage Guide

1. Configure Algorithm Parameters

  1. Open the main page
  2. Expand "Algorithm Configuration" panel
  3. Adjust population size, generation count, mutation rate, etc.
  4. Select desired crossover, mutation, and selection formulas
  5. Click "Save & Apply"

2. Define Problem Data

Via Allele Config Page:

  • Navigate via hamburger menu → "Allele Config"
  • Add/edit alleles with different cost/time/complexity profiles
  • Set probability distributions

Via Chromosome Config Page:

  • Navigate via hamburger menu → "Chromosome Config"
  • Add genes (tasks) with auto-generated IDs (RAT1, RAT2, ...)
  • Add parameters to each gene with options
  • Set option values (cost, time, complexity)

3. Run the Algorithm

  1. Click "Run Algorithm" button
  2. Monitor evolution charts in real-time
  3. View results:
    • Global minimum cost/time/complexity values
    • Best chromosome details
    • Full population browser with gene breakdown

4. View Results

After completion:

  • Charts show min/max/avg evolution across generations
  • Best Solution panel highlights optimal chromosome
  • Chromosomes Table allows expanding rows to see gene-level details
  • Global minimum values display in header

Technical Details

Backend Components

Component Description
generation_generator.py Creates initial population with random allele/parameter selection
crossover.py Implements SBX, Uniform, Single/Two Point crossover
mutation.py Gaussian, Random Resetting, Swap, Inversion operators
selection.py Tournament, Linear Ranking, SUS selection strategies
chromosome_var.py Min/max calculations for normalization

Frontend Structure

File Purpose
main.html Dashboard with charts, config panel, results
allele_config.html CRUD interface for allele definitions
chromosome_config.html Gene/parameter configuration with dynamic options
translations_config.html Translation key-value editor

CSS Organization

Stylesheets are modularized:

  • common.css - Shared base styles (buttons, forms, cards)
  • main.css - Dashboard-specific styles
  • allele_config.css - Allele configuration styling
  • chromosome_config.css - Chromosome/gene card styling
  • translations_config.css - Translation editor styling

Configuration File Reference

config.json

{
    "pop_size": 200,
    "gen_num": 150,
    "mutation_prob": 0.05,
    "gene_mutation_prob": 0.1,
    "cros_rate": 0.99,
    "tournament_size": 10,
    "w_cost": 0.333,
    "w_time": 0.333,
    "w_complexity": 0.334,
    "f_budget": 0.6,
    "f_deadline": 0.6,
    "f_complexity": 0.6,
    "decay_formula": "linear",
    "crossover_formula": "sbx",
    "mutation_formula": "gaussian",
    "selection_formula": "tournament_non_duplicated",
    "fitness_formula": "balanced",
    "sbx_distribution_index": 25,
    "gaussian_standard_deviation": 0.2,
    "initial_decay_number": 0.5
}

License

MIT License - See LICENSE file for details

Acknowledgments

  • Built with Flask (backend)
  • Charts powered by Chart.js
  • UI styled with custom CSS (no external frameworks)

Screenshots

Main Dashboard

Main Page

Allele Configuration

Allele Config Page

Chromosome Configuration

Chromosome Config Page

Translations Configuration

Translations Config Page

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages