You are on page 1of 4

Mini Project

Aim: To implement the application of GA in MATLAB. In this case, application is Optimizing a Scheduling
Problem using Genetic Algorithms in MATLAB.

**Theory:**

Problem Statement: The aim of this project is to implement Genetic Algorithms (GAs) in MATLAB to
optimize a scheduling problem. Scheduling problems involve the allocation of resources over time to
achieve specific objectives. In this context, we'll consider a job-shop scheduling problem where a set
of jobs needs to be processed on a set of machines with various processing times and constraints.

Genetic Algorithm Overview: Genetic Algorithms are optimization techniques inspired by the process
of natural selection. They use a population of potential solutions and evolve them over generations to
find an optimal or near-optimal solution. Here's how the algorithm works:

1. Initialization: Create an initial population of candidate solutions (schedules) with random


values.

2. Fitness Evaluation: For each schedule, evaluate its fitness, which represents how well it
satisfies the scheduling objectives (e.g., minimizing makespan or total tardiness).

3. Selection: Select a subset of schedules from the current population as parents, favoring those
with higher fitness.

4. Crossover (Recombination): Combine the genes (job orders) of two parents to create one or
more offspring (new schedules).

5. Mutation: Introduce small random changes to the offspring to maintain diversity in the
population.

6. Termination: Repeat the process for a predefined number of generations or until a stopping
criterion is met.

Output: The final schedule with the highest fitness is considered the optimized solution.
MATLAB Implementation:

% Define scheduling problem parameters

num_jobs = 10; % Number of jobs to be scheduled

num_machines = 3; % Number of machines available

population_size = 50; % Population size for GA

num_generations = 200; % Number of generations

% Generate initial population

population = randi([0 1], population_size, num_jobs);

for generation = 1:num_generations

% Evaluate fitness of each schedule

fitness = zeros(population_size, 1);

for i = 1:population_size

schedule = population(i, :);

fitness(i) = evaluate_fitness(schedule);

end

% Select parents for crossover

parents = select_parents(population, fitness);

% Apply crossover to create offspring

offspring = crossover(parents);

% Apply mutation to offspring

offspring = mutate(offspring);

% Replace the old population with the new generation

population = offspring;

end

% Find the best schedule

best_schedule = population(find(fitness == max(fitness)), :);

% Display the best schedule

disp('Best Schedule:');disp(best_schedule);
% Function to evaluate fitness (minimize makespan, maximize utilization)

function fitness = evaluate_fitness(schedule)

% This function evaluates the schedule.

% It should return a fitness value based on makespan, utilization, or other metrics.

% For simplicity, assume a random fitness value in this example.

fitness = rand();

end

% Function to select parents (e.g., roulette wheel selection)

function parents = select_parents(population, fitness)

% For simplicity, choose parents randomly in this example.

num_parents = size(population, 1);

parent_indices = randi(num_parents, 1, num_parents);

parents = population(parent_indices, :);

end

% Function for crossover (e.g., one-point crossover)

function offspring = crossover(parents)

% For simplicity, use one-point crossover in this example.

num_parents = size(parents, 1);

crossover_point = randi(size(parents, 2) - 1);

offspring = zeros(size(parents));

for i = 1:num_parents

parent1 = parents(i, :);

parent2 = parents(randi(num_parents), :);

offspring(i, :) = [parent1(1:crossover_point), parent2(crossover_point+1:end)];

end

end
% Function for mutation

function offspring = mutate(offspring)

% For simplicity, flip a random bit in each offspring with a small probability.

mutation_rate = 0.01;

num_offspring = size(offspring, 1);

num_genes = size(offspring, 2);

for i = 1:num_offspring

for j = 1:num_genes

if rand() < mutation_rate

offspring(i, j) = ~offspring(i, j); % Flip the bit

end

end

end

end

Output: The output of this project is the best schedule found by the Genetic Algorithm, represented as
a binary sequence. The output may look like this:

This represents a schedule where jobs are assigned to machines according to the optimized sequence.

Limitations:

1. **Random Fitness Evaluation:** The fitness function in the code provides random fitness values for
simplicity. In real-world applications, the fitness function should be based on actual scheduling
objectives and constraints, which are not considered here.

2. **Simplified Operators:** The code uses basic operators (selection, crossover, and mutation) for
illustrative purposes. In practice, more sophisticated techniques and operators are often required to
handle complex scheduling problems.

You might also like