SlideShare a Scribd company logo
CHECKBOARD USING GENETIC
ALGORITHM
• We are given an n by n checkboard in which
every field can have a different colour from a
set of four colours.
• Goal is to achieve a checkboard in a way that there
are no neighbours with the same colour (not diagonal)
1 2 3 4 5 6 7 8 9 10
1
2
3
4
5
6
7
8
9
10
1 2 3 4 5 6 7 8 9 10
1
2
3
4
5
6
7
8
9
10
The size of a population populationSize = 4
The size of the matrix we'll be using as a solution matrixSize = 4
Build a data structure to contain the initial population population =
zeros( matrixSize, matrixSize, populationSize );
• The checkboard contain 4 colors which shows by number 0 to 3.
it is a node-edge problem so the maximum fitness can easily be computed
optimalFitness = 2 * ( ( matrixSize - 1 ) * matrixSize )=2*3*4=24;
Performance
Initialize:
for( i = 1:populationSize )
population( :, :, i ) = fix( 4 * rand( matrixSize, matrixSize ) );
end
Initial population
population(:,:,1)
1 3 0 0
3 3 2 0
2 3 0 1
2 3 0 2
population(:,:,2)
3 0 0 0
2 1 0 1
0 1 2 2
2 2 3 2
population(:,:,3)
2 0 1 0
3 0 0 3
2 1 1 1
0 2 3 2
population(:,:,4)
3 2 3 1
1 0 2 3
3 1 3 0
0 3 3 0
Fitness function calculation
population(:,:,1)
1 3 0 0
3 3 2 0
2 3 0 1
2 3 0 2
1 1 0
0 1 1
1 1 1
1 1 1
Row Column
1 + 1 + 0
0 + 1 + 1
1 + 1 + 1
1 + 1 + 1
1 + 1 + 0
0 + 0 + 0
1 + 1 + 0
0 + 1 + 1
10 6
10 + 6 = 16Fitness value
Fitness of the initial population
fitness( 1 ) = checkers( population( :, :, 1 ) ) = 16
fitness( 2 ) = checkers( population( :, :, 2 ) ) = 17
fitness( 3 ) = checkers( population( :, :, 3 ) ) = 20
fitness( 4 ) = checkers( population( :, :, 4 ) ) = 21
optimalFitness = 2 × N × (N-1)
here N is the size of matrix (N=4) optimalFitness=2×4×3=24
what's the best fitness in this
population?
bestCurrentFitness = max( fitness ) = 21;
meanCurrentFitness = mean( fitness) = 18.5;
• optimalFitness = 24
bestCurrentFitness = 21 > bestFitness = 0
bestFitness = bestCurrentFitness
And displaye checkboard
0.5 1 1.5 2 2.5 3 3.5 4 4.5
0.5
1
1.5
2
2.5
3
3.5
4
4.5
Generate newPopulation
newPopulation(:,:,1)
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
newPopulation(:,:,2)
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
newPopulation(:,:,3)
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
newPopulation(:,:,4)
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
Number of chromosome which bestindividual is memorized to do
crossovers a3 = fix (populationSize*rand(1))+1;
Number of chromosome which bestindividual is memorized after crossovers
a4 = fix (populationSize*rand(1))+1;
a3 = 4
a4 = 4
Generation = 1
i = 1 and i +1 = 2
mom = select( population, fitness );
1 3 0 0
3 3 2 0
2 3 0 1
2 3 0 2
dad = select( population, fitness );
3 0 0 0
2 1 0 1
0 1 2 2
2 2 3 2
dad
3 0 0 0
2 1 0 1
0 1 2 2
2 2 3 2
mom
1 3 0 0
3 3 2 0
2 3 0 1
2 3 0 2
Crossover for i = 1 and i +1 = 2 and rand(1) = 0.68 > 0.5
Mutation for i = 1 and i +1 = 2
child1
1 3 0 0
2 3 2 0
0 1 0 1
2 2 3 2
newPopulation( :, :, 1 ) =
mutate(child1 )
1 3 0 0
2 3 2 0
0 1 0 1
2 2 3 2
For each gene 1% probability exists to occur mutation.
child2
3 0 0 0
3 1 0 1
2 3 2 2
2 3 0 2
newPopulation( :, :, 2 ) =
mutate(child2 )
3 0 0 0
3 1 0 1
2 3 2 2
2 3 0 2
i = 3 and i +1 = 4
mom = select( population, fitness );
3 2 3 1
1 0 2 3
3 1 3 0
0 3 3 0
dad = select( population, fitness );
3 0 0 0
2 1 0 1
0 1 2 2
2 2 3 2
dad
3 0 0 0
2 1 0 1
0 1 2 2
2 2 3 2
mom
3 2 3 1
1 0 2 3
3 1 3 0
0 3 3 0
Crossover for i = 3 and i +1 = 4 and rand(1) = 0.38 < 0.5
Number of the Column for Crossover
a5 = fix (matrixSize*rand(1))+1 = 2;
Mutation for i = 3 and i +1 = 4
child1
3 0 3 1
1 1 2 3
3 1 3 0
0 2 3 0
newPopulation( :, :, 3 ) =
mutate(child1 )
3 0 3 1
1 1 2 3
3 1 3 0
0 2 3 0
For each gene 1% probability exists to occur mutation.
newPopulation( :, :, 4 ) =
bestindividual( population, fitness)
3 2 3 1
1 0 2 3
3 1 3 0
0 3 3 0
Population = newPopulation
population(:,:,1)
1 3 0 0
2 3 2 0
0 1 0 1
2 2 3 2
population(:,:,2)
3 0 0 0
3 1 0 1
2 3 2 2
2 3 0 2
population(:,:,3)
3 0 3 1
1 1 2 3
3 1 3 0
0 2 3 0
population(:,:,4)
3 2 3 1
1 0 2 3
3 1 3 0
0 3 3 0
Fitness changes
Old
fitness( 1 ) = checkers( population( :, :, 1 ) ) = 16
fitness( 2 ) = checkers( population( :, :, 2 ) ) = 17
fitness( 3 ) = checkers( population( :, :, 3 ) ) = 20
fitness( 4 ) = checkers( population( :, :, 4 ) ) = 21
New
fitness( 1 ) = checkers( population( :, :, 1 ) ) = 20
fitness( 2 ) = checkers( population( :, :, 2 ) ) = 16
fitness( 3 ) = checkers( population( :, :, 3 ) ) = 20
fitness( 4 ) = checkers( population( :, :, 4 ) ) = 21
After 47 generation the optimal fitness obtains
0.5 1 1.5 2 2.5 3 3.5 4 4.5
0.5
1
1.5
2
2.5
3
3.5
4
4.5
0 5 10 15 20 25 30 35 40 45 50
16
17
18
19
20
21
22
23
24
Generations
Fitness
Best Fitness
Mean Fitness
Performance of Select Function
population(:,:,1)
1 3 0 0
2 3 2 0
0 1 0 1
2 2 3 2
population(:,:,2)
3 0 0 0
3 1 0 1
2 3 2 2
2 3 0 2
population(:,:,3)
3 0 3 1
1 1 2 3
3 1 3 0
0 2 3 0
population(:,:,4)
3 2 3 1
1 0 2 3
3 1 3 0
0 3 3 0
fitness( 1 ) = checkers( population( :, :, 1 ) ) = 20
fitness( 2 ) = checkers( population( :, :, 2 ) ) = 16
fitness( 3 ) = checkers( population( :, :, 3 ) ) = 20
fitness( 4 ) = checkers( population( :, :, 4 ) ) = 21
Performance of Select Function
function selected = select( population, fitness )
[m, n] = size( fitness ); % m = n = 4
s = sum( fitness ); % s = 77
roulette = s*rand( 1 ); % roulette = 48.7868
currentSum = 0;
picked = n; % n = 4
for i = 1:n
s1 = currentSum + fitness(i)
if s1 < roulette
picked = I
end
currentSum = currentSum + fitness(i);
end
selected = population( :, :, picked );
i currentSum fitness(i) s1 if s1 < roulette picked
1 0 20 20 Yes 1
2 20 16 36 Yes 2
3 36 20 56 No 2
4 56 21 77 No 2

More Related Content

Similar to Genetic algorithm

N queen
N queenN queen
N queen
Ahmed Yousef
 
Matrices
Matrices Matrices
Matrices
Karan Kukreja
 
Introduction to machine learning algorithms
Introduction to machine learning algorithmsIntroduction to machine learning algorithms
Introduction to machine learning algorithms
bigdata trunk
 
lagrange and newton divided differences.ppt
lagrange and newton divided differences.pptlagrange and newton divided differences.ppt
lagrange and newton divided differences.ppt
Thirumoorthy64
 
3D Math Without Presenter Notes
3D Math Without Presenter Notes3D Math Without Presenter Notes
3D Math Without Presenter Notes
Janie Clayton
 
Theory to consider an inaccurate testing and how to determine the prior proba...
Theory to consider an inaccurate testing and how to determine the prior proba...Theory to consider an inaccurate testing and how to determine the prior proba...
Theory to consider an inaccurate testing and how to determine the prior proba...
Toshiyuki Shimono
 
Oct8 - 131 slid
Oct8 - 131 slidOct8 - 131 slid
Oct8 - 131 slid
Tak Lee
 
Practice Test 2 Solutions
Practice Test 2  SolutionsPractice Test 2  Solutions
Practice Test 2 Solutions
Long Beach City College
 
Genetic algorithm
Genetic algorithmGenetic algorithm
Genetic algorithm
Syed Muhammad Zeejah Hashmi
 
Lr4 math cad
Lr4 math cadLr4 math cad
Lr4 math cad
metallurg056
 
The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202
Mahmoud Samir Fayed
 
Descriptiva-Semana8
Descriptiva-Semana8 Descriptiva-Semana8
Descriptiva-Semana8
Jorge Obando
 
Diversity mechanisms for evolutionary populations in Search-Based Software En...
Diversity mechanisms for evolutionary populations in Search-Based Software En...Diversity mechanisms for evolutionary populations in Search-Based Software En...
Diversity mechanisms for evolutionary populations in Search-Based Software En...
Annibale Panichella
 
Binomial distributions
Binomial distributionsBinomial distributions
Binomial distributions
Ulster BOCES
 
3 Systems Jeopardy - Copy.ppt
3 Systems Jeopardy - Copy.ppt3 Systems Jeopardy - Copy.ppt
3 Systems Jeopardy - Copy.ppt
ssusere48744
 
Introduction
IntroductionIntroduction
Introduction
butest
 
Chapter 4 review
Chapter 4 reviewChapter 4 review
Chapter 4 review
Natalie Klag
 
ML MODULE 2.pdf
ML MODULE 2.pdfML MODULE 2.pdf
ML MODULE 2.pdf
Shiwani Gupta
 
Chapter-1-04032021-111422pm (2).pptx
Chapter-1-04032021-111422pm (2).pptxChapter-1-04032021-111422pm (2).pptx
Chapter-1-04032021-111422pm (2).pptx
abdulhannan992458
 
Genetic algorithm
Genetic algorithmGenetic algorithm
Genetic algorithm
Bablu Shofi
 

Similar to Genetic algorithm (20)

N queen
N queenN queen
N queen
 
Matrices
Matrices Matrices
Matrices
 
Introduction to machine learning algorithms
Introduction to machine learning algorithmsIntroduction to machine learning algorithms
Introduction to machine learning algorithms
 
lagrange and newton divided differences.ppt
lagrange and newton divided differences.pptlagrange and newton divided differences.ppt
lagrange and newton divided differences.ppt
 
3D Math Without Presenter Notes
3D Math Without Presenter Notes3D Math Without Presenter Notes
3D Math Without Presenter Notes
 
Theory to consider an inaccurate testing and how to determine the prior proba...
Theory to consider an inaccurate testing and how to determine the prior proba...Theory to consider an inaccurate testing and how to determine the prior proba...
Theory to consider an inaccurate testing and how to determine the prior proba...
 
Oct8 - 131 slid
Oct8 - 131 slidOct8 - 131 slid
Oct8 - 131 slid
 
Practice Test 2 Solutions
Practice Test 2  SolutionsPractice Test 2  Solutions
Practice Test 2 Solutions
 
Genetic algorithm
Genetic algorithmGenetic algorithm
Genetic algorithm
 
Lr4 math cad
Lr4 math cadLr4 math cad
Lr4 math cad
 
The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202
 
Descriptiva-Semana8
Descriptiva-Semana8 Descriptiva-Semana8
Descriptiva-Semana8
 
Diversity mechanisms for evolutionary populations in Search-Based Software En...
Diversity mechanisms for evolutionary populations in Search-Based Software En...Diversity mechanisms for evolutionary populations in Search-Based Software En...
Diversity mechanisms for evolutionary populations in Search-Based Software En...
 
Binomial distributions
Binomial distributionsBinomial distributions
Binomial distributions
 
3 Systems Jeopardy - Copy.ppt
3 Systems Jeopardy - Copy.ppt3 Systems Jeopardy - Copy.ppt
3 Systems Jeopardy - Copy.ppt
 
Introduction
IntroductionIntroduction
Introduction
 
Chapter 4 review
Chapter 4 reviewChapter 4 review
Chapter 4 review
 
ML MODULE 2.pdf
ML MODULE 2.pdfML MODULE 2.pdf
ML MODULE 2.pdf
 
Chapter-1-04032021-111422pm (2).pptx
Chapter-1-04032021-111422pm (2).pptxChapter-1-04032021-111422pm (2).pptx
Chapter-1-04032021-111422pm (2).pptx
 
Genetic algorithm
Genetic algorithmGenetic algorithm
Genetic algorithm
 

Recently uploaded

New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
wisnuprabawa3
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
Mukeshwaran Balu
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
awadeshbabu
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
University of Maribor
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
gerogepatton
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt
PuktoonEngr
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
Divyam548318
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 

Recently uploaded (20)

New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 

Genetic algorithm

  • 2. • We are given an n by n checkboard in which every field can have a different colour from a set of four colours. • Goal is to achieve a checkboard in a way that there are no neighbours with the same colour (not diagonal) 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10
  • 3. The size of a population populationSize = 4 The size of the matrix we'll be using as a solution matrixSize = 4 Build a data structure to contain the initial population population = zeros( matrixSize, matrixSize, populationSize ); • The checkboard contain 4 colors which shows by number 0 to 3. it is a node-edge problem so the maximum fitness can easily be computed optimalFitness = 2 * ( ( matrixSize - 1 ) * matrixSize )=2*3*4=24; Performance Initialize: for( i = 1:populationSize ) population( :, :, i ) = fix( 4 * rand( matrixSize, matrixSize ) ); end
  • 4. Initial population population(:,:,1) 1 3 0 0 3 3 2 0 2 3 0 1 2 3 0 2 population(:,:,2) 3 0 0 0 2 1 0 1 0 1 2 2 2 2 3 2 population(:,:,3) 2 0 1 0 3 0 0 3 2 1 1 1 0 2 3 2 population(:,:,4) 3 2 3 1 1 0 2 3 3 1 3 0 0 3 3 0
  • 5. Fitness function calculation population(:,:,1) 1 3 0 0 3 3 2 0 2 3 0 1 2 3 0 2 1 1 0 0 1 1 1 1 1 1 1 1 Row Column 1 + 1 + 0 0 + 1 + 1 1 + 1 + 1 1 + 1 + 1 1 + 1 + 0 0 + 0 + 0 1 + 1 + 0 0 + 1 + 1 10 6 10 + 6 = 16Fitness value
  • 6. Fitness of the initial population fitness( 1 ) = checkers( population( :, :, 1 ) ) = 16 fitness( 2 ) = checkers( population( :, :, 2 ) ) = 17 fitness( 3 ) = checkers( population( :, :, 3 ) ) = 20 fitness( 4 ) = checkers( population( :, :, 4 ) ) = 21 optimalFitness = 2 × N × (N-1) here N is the size of matrix (N=4) optimalFitness=2×4×3=24
  • 7. what's the best fitness in this population? bestCurrentFitness = max( fitness ) = 21; meanCurrentFitness = mean( fitness) = 18.5; • optimalFitness = 24
  • 8. bestCurrentFitness = 21 > bestFitness = 0 bestFitness = bestCurrentFitness And displaye checkboard 0.5 1 1.5 2 2.5 3 3.5 4 4.5 0.5 1 1.5 2 2.5 3 3.5 4 4.5
  • 9. Generate newPopulation newPopulation(:,:,1) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 newPopulation(:,:,2) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 newPopulation(:,:,3) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 newPopulation(:,:,4) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  • 10. Number of chromosome which bestindividual is memorized to do crossovers a3 = fix (populationSize*rand(1))+1; Number of chromosome which bestindividual is memorized after crossovers a4 = fix (populationSize*rand(1))+1; a3 = 4 a4 = 4 Generation = 1
  • 11. i = 1 and i +1 = 2 mom = select( population, fitness ); 1 3 0 0 3 3 2 0 2 3 0 1 2 3 0 2 dad = select( population, fitness ); 3 0 0 0 2 1 0 1 0 1 2 2 2 2 3 2
  • 12. dad 3 0 0 0 2 1 0 1 0 1 2 2 2 2 3 2 mom 1 3 0 0 3 3 2 0 2 3 0 1 2 3 0 2 Crossover for i = 1 and i +1 = 2 and rand(1) = 0.68 > 0.5
  • 13. Mutation for i = 1 and i +1 = 2 child1 1 3 0 0 2 3 2 0 0 1 0 1 2 2 3 2 newPopulation( :, :, 1 ) = mutate(child1 ) 1 3 0 0 2 3 2 0 0 1 0 1 2 2 3 2 For each gene 1% probability exists to occur mutation. child2 3 0 0 0 3 1 0 1 2 3 2 2 2 3 0 2 newPopulation( :, :, 2 ) = mutate(child2 ) 3 0 0 0 3 1 0 1 2 3 2 2 2 3 0 2
  • 14. i = 3 and i +1 = 4 mom = select( population, fitness ); 3 2 3 1 1 0 2 3 3 1 3 0 0 3 3 0 dad = select( population, fitness ); 3 0 0 0 2 1 0 1 0 1 2 2 2 2 3 2
  • 15. dad 3 0 0 0 2 1 0 1 0 1 2 2 2 2 3 2 mom 3 2 3 1 1 0 2 3 3 1 3 0 0 3 3 0 Crossover for i = 3 and i +1 = 4 and rand(1) = 0.38 < 0.5 Number of the Column for Crossover a5 = fix (matrixSize*rand(1))+1 = 2;
  • 16. Mutation for i = 3 and i +1 = 4 child1 3 0 3 1 1 1 2 3 3 1 3 0 0 2 3 0 newPopulation( :, :, 3 ) = mutate(child1 ) 3 0 3 1 1 1 2 3 3 1 3 0 0 2 3 0 For each gene 1% probability exists to occur mutation. newPopulation( :, :, 4 ) = bestindividual( population, fitness) 3 2 3 1 1 0 2 3 3 1 3 0 0 3 3 0
  • 17. Population = newPopulation population(:,:,1) 1 3 0 0 2 3 2 0 0 1 0 1 2 2 3 2 population(:,:,2) 3 0 0 0 3 1 0 1 2 3 2 2 2 3 0 2 population(:,:,3) 3 0 3 1 1 1 2 3 3 1 3 0 0 2 3 0 population(:,:,4) 3 2 3 1 1 0 2 3 3 1 3 0 0 3 3 0
  • 18. Fitness changes Old fitness( 1 ) = checkers( population( :, :, 1 ) ) = 16 fitness( 2 ) = checkers( population( :, :, 2 ) ) = 17 fitness( 3 ) = checkers( population( :, :, 3 ) ) = 20 fitness( 4 ) = checkers( population( :, :, 4 ) ) = 21 New fitness( 1 ) = checkers( population( :, :, 1 ) ) = 20 fitness( 2 ) = checkers( population( :, :, 2 ) ) = 16 fitness( 3 ) = checkers( population( :, :, 3 ) ) = 20 fitness( 4 ) = checkers( population( :, :, 4 ) ) = 21
  • 19. After 47 generation the optimal fitness obtains 0.5 1 1.5 2 2.5 3 3.5 4 4.5 0.5 1 1.5 2 2.5 3 3.5 4 4.5 0 5 10 15 20 25 30 35 40 45 50 16 17 18 19 20 21 22 23 24 Generations Fitness Best Fitness Mean Fitness
  • 20. Performance of Select Function population(:,:,1) 1 3 0 0 2 3 2 0 0 1 0 1 2 2 3 2 population(:,:,2) 3 0 0 0 3 1 0 1 2 3 2 2 2 3 0 2 population(:,:,3) 3 0 3 1 1 1 2 3 3 1 3 0 0 2 3 0 population(:,:,4) 3 2 3 1 1 0 2 3 3 1 3 0 0 3 3 0 fitness( 1 ) = checkers( population( :, :, 1 ) ) = 20 fitness( 2 ) = checkers( population( :, :, 2 ) ) = 16 fitness( 3 ) = checkers( population( :, :, 3 ) ) = 20 fitness( 4 ) = checkers( population( :, :, 4 ) ) = 21
  • 21. Performance of Select Function function selected = select( population, fitness ) [m, n] = size( fitness ); % m = n = 4 s = sum( fitness ); % s = 77 roulette = s*rand( 1 ); % roulette = 48.7868 currentSum = 0; picked = n; % n = 4 for i = 1:n s1 = currentSum + fitness(i) if s1 < roulette picked = I end currentSum = currentSum + fitness(i); end selected = population( :, :, picked ); i currentSum fitness(i) s1 if s1 < roulette picked 1 0 20 20 Yes 1 2 20 16 36 Yes 2 3 36 20 56 No 2 4 56 21 77 No 2