## Genetic Algorithm MATLAB

Genetic Algorithm MATLAB here our major aim of this project is to identify the least of the Rastrigin function.We work on any types of coding and algorithms.  We provide an explicit Rastrigin function, procedures of genetic algorithm and also MATLAB code in an elaborate manner. For optimization methods, this is examined as a usual evaluation function.

Rastrigin Function

The Rastrigin function is defined as: f(x)=10n+∑i=1n[xi2−10cos⁡(2πxi)]f(x) = 10n + \sum_{i=1}^{n} \left[x_i^2 – 10 \cos(2 \pi x_i)\right]f(x)=10n+∑i=1n[xi2−10cos(2πxi)] where nnn is the dimension of the input vector xxx.

Genetic Algorithm Procedures

1. Initialization: It is significant to produce the primary population of findings.
2. Evaluation: The capability of every individual in the population has to be evaluated.
3. Selection: Generally, individuals must be chosen in such a manner on the basis of their capability to recreate.
4. Crossover: As a means to create offspring, our team plans to incorporate sets of individuals.
5. Mutation: For few individuals, we need to initiate irregular modifications.
6. Replacement: On the basis of the offspring and few previous individuals, focus on creating a novel population.
7. Termination: When an ending condition is attained, we intend to terminate the method.

MATLAB Code

Applying a basic Genetic Algorithm, the following is the MATLAB code:

% Genetic Algorithm to minimize the Rastrigin function

clc; clear; close all;

% Parameters

popSize = 50;  % Population size

maxGen = 100;  % Maximum number of generations

pc = 0.8;      % Crossover probability

pm = 0.01;     % Mutation probability

nVar = 2;      % Number of variables (dimensions)

varRange = [-5.12 5.12];  % Variable range

% Initialize population

pop = varRange(1) + (varRange(2) – varRange(1)) * rand(popSize, nVar);

fitness = evaluatePopulation(pop);

% Main GA loop

for gen = 1:maxGen

% Selection (Roulette Wheel Selection)

selectedPop = selectPopulation(pop, fitness);

% Crossover

offspring = crossoverPopulation(selectedPop, pc, varRange);

% Mutation

offspring = mutatePopulation(offspring, pm, varRange);

% Evaluate offspring

offspringFitness = evaluatePopulation(offspring);

% Replacement

[pop, fitness] = replacePopulation(pop, fitness, offspring, offspringFitness);

% Display best fitness in current generation

disp([‘Generation ‘, num2str(gen), ‘: Best Fitness = ‘, num2str(min(fitness))]);

end

% Best solution

[bestFitness, bestIdx] = min(fitness);

bestSolution = pop(bestIdx, :);

disp(‘Best Solution:’);

disp(bestSolution);

disp([‘Best Fitness: ‘, num2str(bestFitness)]);

% Functions

function fitness = evaluatePopulation(pop)

% Evaluate fitness of each individual in the population

fitness = arrayfun(@rastrigin, pop(:,1), pop(:,2));

end

function selectedPop = selectPopulation(pop, fitness)

% Roulette Wheel Selection

cumFitness = cumsum(1./fitness);

totalFitness = cumFitness(end);

selectedPop = pop;

for i = 1:size(pop, 1)

r = rand * totalFitness;

selectedIdx = find(cumFitness >= r, 1, ‘first’);

selectedPop(i, 🙂 = pop(selectedIdx, :);

end

end

function offspring = crossoverPopulation(pop, pc, varRange)

% Uniform Crossover

offspring = pop;

for i = 1:2:size(pop, 1)-1

if rand < pc

alpha = rand(size(pop, 2), 1);

offspring(i, 🙂 = alpha .* pop(i, 🙂 + (1 – alpha) .* pop(i+1, :);

offspring(i+1, 🙂 = alpha .* pop(i+1, 🙂 + (1 – alpha) .* pop(i, :);

% Ensure offspring are within the variable range

offspring(i, 🙂 = max(min(offspring(i, :), varRange(2)), varRange(1));

offspring(i+1, 🙂 = max(min(offspring(i+1, :), varRange(2)), varRange(1));

end

end

end

function mutatedPop = mutatePopulation(pop, pm, varRange)

% Mutation

mutatedPop = pop;

for i = 1:size(pop, 1)

for j = 1:size(pop, 2)

if rand < pm

mutatedPop(i, j) = varRange(1) + (varRange(2) – varRange(1)) * rand;

end

end

end

end

function [newPop, newFitness] = replacePopulation(pop, fitness, offspring, offspringFitness)

% Combine population and offspring

combinedPop = [pop; offspring];

combinedFitness = [fitness; offspringFitness];

% Select the best individuals to form the new population

[~, sortedIdx] = sort(combinedFitness);

newPop = combinedPop(sortedIdx(1:size(pop, 1)), :);

newFitness = combinedFitness(sortedIdx(1:size(pop, 1)));

end

function f = rastrigin(x, y)

% Rastrigin function

n = length([x, y]);

f = 10 * n + (x^2 – 10 * cos(2 * pi * x)) + (y^2 – 10 * cos(2 * pi * y));

end

## Important 50 genetic algorithms list for research

There are many genetic algorithms, but some are determined as effective. We suggest a set of 50 significant genetic algorithm topics and uses for investigation:

Basic Genetic Algorithms

1. Binary-Coded Genetic Algorithm
2. Steady-State Genetic Algorithm
3. Micro Genetic Algorithm
4. Hybrid Genetic Algorithm
5. Distributed Genetic Algorithm
6. Standard Genetic Algorithm
7. Real-Coded Genetic Algorithm
8. Generational Genetic Algorithm
9. Adaptive Genetic Algorithm
10. Parallel Genetic Algorithm

1. Multi-Objective Genetic Algorithm (MOGA)
2. Strength Pareto Evolutionary Algorithm (SPEA)
3. Elitist Genetic Algorithm
4. Island Model Genetic Algorithm
5. Memetic Algorithm
6. Genetic Programming
7. Niched Pareto Genetic Algorithm (NPGA)
8. Non-dominated Sorting Genetic Algorithm (NSGA-II)
9. Hierarchical Genetic Algorithm
10. Cellular Genetic Algorithm

Specialized Genetic Algorithms

1. Genetic Algorithms for Constraint Satisfaction Problems
2. Genetic Algorithms for Function Optimization
3. Genetic Algorithms for Neural Network Training
4. Genetic Algorithms for Traveling Salesman Problem (TSP)
5. Genetic Algorithms for Job Shop Scheduling
6. Genetic Algorithms for Dynamic Environments
7. Genetic Algorithms for Combinatorial Optimization
8. Genetic Algorithms for Feature Selection
9. Genetic Algorithms for Scheduling Problems
10. Genetic Algorithms for Vehicle Routing Problem (VRP)

Genetic Algorithms in Engineering

1. Genetic Algorithms in Control System Design
2. Genetic Algorithms in Power System Optimization
3. Genetic Algorithms in Communication Network Optimization
4. Genetic Algorithms in Biomedical Engineering
5. Genetic Algorithms in Environmental Engineering
6. Genetic Algorithms in Structural Optimization
7. Genetic Algorithms in Signal Processing
8. Genetic Algorithms in Robotics Path Planning
9. Genetic Algorithms in Image Processing
10. Genetic Algorithms in Chemical Engineering

Genetic Algorithms in Computer Science

1. Genetic Algorithms for Data Mining
2. Genetic Algorithms for Software Testing
3. Genetic Algorithms for Game Playing
4. Genetic Algorithms for Bioinformatics
5. Genetic Algorithms for Automated Design
6. Genetic Algorithms for Machine Learning
7. Genetic Algorithms for Pattern Recognition
8. Genetic Algorithms for Cryptography
9. Genetic Algorithms for Natural Language Processing
10. Genetic Algorithms for Artificial Life

We have offered Rastrigin function, genetic algorithm procedures, and MATLAB code, to identify the smallest of the Rastrigin function which is the major goal of this project. Also, a collection of 50 major genetic algorithm topics and uses for exploration are provided by us in a detailed way. The above-mentioned information will be beneficial as well as helpful.phdtopic.com team will provide you with thesis writing services and will share ides and topics on your interested area.