🌿 Bio-Inspired Optimization Lab

Learn from nature! Algorithms inspired by evolution, swarms, and natural processes.

📐 Genetic Algorithm Mathematics

Core Formulas

1. Fitness Function

f(x)=objective(x)f(x) = \text{objective}(x)

Measures solution quality. Higher fitness = better solution.

2. Selection Probability (Roulette Wheel)

P(xi)=f(xi)j=1nf(xj)P(x_i) = \frac{f(x_i)}{\sum_{j=1}^{n} f(x_j)}

Probability of selecting individual xix_i is proportional to its fitness.

Example:

If fitness values are [10, 20, 30], probabilities are [16.7%, 33.3%, 50%]

3. Crossover (Single-Point)

child=parent1[0:k]+parent2[k:n]\text{child} = \text{parent}_1[0:k] + \text{parent}_2[k:n]

Combine genetic material at crossover point kk

Example:

Parent 1: 11001010
Parent 2: 00110101
Child: 11000101 (crossover at position 4)

4. Mutation

xi={xiwith probability 1pm¬xiwith probability pmx_i' = \begin{cases} x_i & \text{with probability } 1-p_m \\ \neg x_i & \text{with probability } p_m \end{cases}

Flip bits with mutation probability pmp_m = 10%

Example:

Before: 11001010
After: 11011010 (bit 3 mutated)

5. Average Fitness Evolution

fˉ(t)=1Ni=1Nf(xi(t))\bar{f}(t) = \frac{1}{N}\sum_{i=1}^{N} f(x_i^{(t)})

Average fitness at generation tt with population size NN

💡 How It Works Together

1

Selection: Better solutions (higher f(x)f(x)) have higher P(x)P(x), more likely to reproduce

2

Crossover: Combines good traits from parents (rate = 80%)

3

Mutation: Introduces diversity, prevents premature convergence (rate = 10%)

4

Result: Average fitness fˉ(t)\bar{f}(t) increases over generations

🧬 Interactive Genetic Algorithm Simulation

Like breeding the perfect recipe! Start with random recipes, keep the best ones, mix them together (crossover), add small changes (mutation), and repeat!

Evolution Parameters

20

Number of solutions in each generation

0.8

Probability of combining parent genes

0.1

Probability of random gene changes

Top 10 Individuals (Chromosomes)

01101111f(x) = 42.8
01000010f(x) = 39.2
10101100f(x) = 36.5
10111011f(x) = 35.4
11000000f(x) = 28.1
10000100f(x) = 17.9
01000110f(x) = 14.6
10100111f(x) = 10.5
00100011f(x) = 6.7
10100010f(x) = 4.1

Fitness Evolution Over Generations

Current Generation: 0

Best Fitness: 5.00

Average Fitness fˉ\bar{f}: 5.00

Population Size N: 20

Improvement: 0%

🎯 Genetic Operators Explained

🎲

1. Initialize

Create random population of solutions

N = 20 individuals

2. Selection

Choose parents based on fitness

P(xi)f(xi)P(x_i) \propto f(x_i)

🔀

3. Crossover

Combine parent genes

Rate = 80%

4. Mutation

Random gene changes

pmp_m = 10%