0% found this document useful (0 votes)
15 views12 pages

Swarm Unit2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views12 pages

Swarm Unit2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

19-08-2024

Evolutionary Computing
• Evolutionary computing is a area of computer science which is inspired by the
process of natural evolution.

Unit 2
Evolutionary Algorithms
By
Dr. Naeem Ahmad
Assistant Professor
NIT Raipur, India

1 2

Evolutionary Computing Biological Inspiration


•Principal of Natural Selection
•Genetics
Evolutionary Computing
Natural Evolution Generate & Test

Evolution Problem Solving


Environment Problem
Individual Candidate Solution
Fittest Quality
3 4

Principal of Natural Selection Principal of Natural Selection


• Survival of Fittest • Giraffes with longer neck can eat leaves of higher branches.
• They have better chance of survival.
o Accept the best and reject the rest based on • Favorable characteristics of survival of giraffes are propagated through generation
phenotypic traits by mutation.
• Now the species have longer neck.

5 6

1
19-08-2024

Evolutionary Computing Genetics


Animal cell is collection of many small
Initial Population “factories” working together.

Survival of Fittest

Millions of
years Reproduction by
selected population

Evolved Species The nucleus is in the center of the cell.


This nucleus contains genetic information.

8
7

Chromosomes Genes
• Genetic information is encoded in • Visible properties like eye color or fur color can be determined by genes.
chromosomes.
• Each chromosomes is built of
DNA.
• Chromosomes are divided into
several parts called genes.
• Genes are the properties of
species.
• Genes are the functional units of
inheritance encoding phenotypic
characteristics.
9 10

Genetics basics Reproduction


• Allele- An allele is one of the possible value that a gene can have. • Moitosis – copying the same genetic information into the new offspring’s.
• Genome- The set of all the genes of a specific species is called genome. • There is no exchange of information.
• Locus- Each and every gene has a unique position on the genome called • Multicell structure.
locus.
• Genotype- for a particular individual, the entire combination of gene is
called genotype.
• Phenotype- It describes the physical aspect or characteristics.
• Individual genotypes encodes its phenotypes.
• The phenotype is affected by changes to the underlying genetic code.
• Selection is based on phenotypes while reproduction is based on
genotypes.
11 12

2
19-08-2024

Reproduction Evolutionary Computing Algorithm


• Meiosis – it is a basis for reproduction. • Given a population of individual within environment that has limited resources.
• Population starts competition for these resources. (Survival of fittest)
• After two division two gametes o These competition is basis for natural selection.
appeared. o Rise in the fitness of population.

• In reproduction two gametes conjugate • Given a quality function is to be maximized, we can randomly creates a set of
candidate solution.
to zygote which will become a new
• Apply quality function to these and find the fitness value (higher means better)
individual.
• On the basis of fitness values, some of the better candidates are chosen to seed the
• Crossover leads to a new genotype. next generation.
• This can be done by applying recombination and/or mutation.
• These create a set of new candidates (offsprings) which compete the old candidates
based on their fitness value, for a place in next generation.
13 14

Evolutionary Computing What are Genetic Algorithms?


• GAs are adaptive meta-heuristic search algorithms.
• It is based on the evolutionary ideas of natural selection and genetics.
• Genetic algorithm simulate the natural evolution of species through
natural selection for optimization.
• It is used in computing to find true or approximate solutions to
optimization and search problem.

Genetic Algorithms are intelligent search techniques maintaining a


population of candidate solutions for a given problem and search the
solution space by applying variation operators.

15 16

Characteristics GA vs Convention Methods


• Randomness • GAs operate with coded version of the problem parameters rather than
• GA always considers a population of solutions. parameter itself.
• Robustness- it can be applied to resolve any problem. • Almost all conventional optimization methods search from a single
point but GA always operates on a whole population of points.
• GA uses fitness function for evaluation rather than derivatives. As a
result, they can be applied to any kind of continuous or discrete
Limitation optimization problem.
• Gas are guaranteed to find global optimum solution. • GAs search by stochastic operators, not by deterministic rules.

17 18

3
19-08-2024

Natural Evolution and GA Individual Representation: Phenotype and Genotype


• An individual is defined by a chromosome. A chromosome stores genetic
information (called phenotype) for an individual.
Natural Evolution Genetic Algorithm • Here, a chromosome is expressed in terms of factors defining a problem.
Chromosomes String
Gene Feature of character
Allele Feature value
Locus String position
Genotype Structure or coded string
Phenotype Parameter set

19 20

Start

Initialize

Evaluate Solution

No

Optimum Selection
Solution?

Yes Crossover
Stop

Mutation

22

Pseudocode GA Process
Begin • Encode potential solution in terms of chromosomes like data structure.
INITIALIZE population with random candidate solution • Select parent on the basis of fitness of the solutions to produce
Evaluate each solution (calculate fittest function) offsprings for next generation, which contain the characteristics of the
REPEAT UNTIL (Termination condition satisfied) { both parent.
Selection • Employ recombination operators (Selection, Crossover, Mutation)
Crossover repeatedly to preserve the good portion of the string.
Mutation • Good portions of the string usually lead to optimal or near optimal
Calculate fittest function solution. The method is applied over a desired number of generations.
} • If well designed, population will converge faster.
End

23 24

4
19-08-2024

Encoding Chromosomes Encoding


• It is a process of representing individual gene. • It is a process of representing individual gene.
• This process can be performed using bits, numbers, trees, arrays etc. • This process can be performed using
o Binary Encoding
o Real value Encoding
Binary encoding Octal encoding
o Permutation Encoding
Chromosomes 1 110100011010 Chromosomes 1 03467216
o Tree Encoding
Chromosomes 2 011111111100 Chromosomes 2 15723314

Hexadecimal encoding Permutation encoding


Chromosomes 1 9CE7 Chromosomes 1 153264798
Chromosomes 2 3DBA Chromosomes 2 856723149

25 26

Selection Selection Operators


• A process which selects solutions among multiple solution. There are multiple option available in genetic algorithm to
• The focus is on selecting only good solution and eliminating bad implement selection.
solution in population. • Roulette Wheel Selection (with and without scaling)
“Survival of fittest – select the best and reject the rest” • Rank Selection
• Random Selection
Function: • Tournament Selection
• Boltzmann Selection
• Identify the good solutions in the population.
• Make copies of solutions
• Eliminate bad solutions
Write assignment on Tournament and Boltzmann Selection.

27 28

Fitness Function Crossover (Recombination)


• A fitness value is assigned to each solution by fitness function. • Crossover is the process of taking two parent solutions and
• Fitness the value determine the solution is close enough to optimal producing a child using them.
solution or not. • It is recombination operator that uses in 3 steps:
• It is useful for rank of solutions in population. oSelect a pair of two individual strings at random.
Select oA cross site is selected at random along with the string length.
Criteria oFinally the position values are swapped between the two strings
following the cross site.
Fitness
S 10
Function Parent 1 Child 1

Parent 2 Child 2

29 30

5
19-08-2024

Types of Crossover Mutation


• Single point crossover • Mutation is a process to introduce new features in solution string in population
pool to maintain diversity.
• Two point crossover
• Mutation prevent algorithm to be trapped in a local minima.
• Multipoint crossover • Process of generating new offspring from single parent.
• Uniform crossover
• Three-parent crossover
• Shuffle crossover

Write assignment on Uniform crossover, Three-parent crossover and Shuffle crossover.

31 32

Mutation Implementation Mutation Probability


• Flipping • It decides how often parts of chromosomes will be mutated.
• Interchanging • If no mutation then offsprings are generated immediate after
• Reversing crossover.
• If there is mutation i.e. some parts of chromosomes are
changed.
• Mutation probability Pm = 100% (whole chromosome is
changed).
• Mutation probability Pm = 0% (Nothing is changed).

33 34

GA-Evolutionary Cycle Encoding Problems


Based on fitness Function Crossover and Mutation • Types of encoding a solution to the problem into chromosomes
Parents
Selection Modification • Binary encoding
Modified o Difficult to apply directly 1 0 0 1 1 1 0 1
Offsprings o Not a natural encoding
Evaluated
Initiate and Offsprings • Value or real number encoding
Population Evaluation 2.3352 5.3254 6.2387 4.1524
Evaluate o For constrained optimization problems
Deleted • Permutation encoding
Offsprings 3 5 1 2 4 8 7 6
o For combinatorial optimization problems
o TS or Quadratic assignment problems
Discard
Termination Criteria • Tree encoding
o Maximum number of generation or
o No improvement in the fitness value for fixed generation
35 36

6
19-08-2024

Encoding Problem Encoding Problem


• Feasibility of chromosomes
Solution Space oSolution decoded from a chromosomes lie in a feasible region of
Coding Space the problem.
Infeasible one

feasible one
Feasible Space • Legality of a chromosomes
oChromosomes represent a solution to a problem.
• Uniqueness of a mapping (between chromosomes and
1-n mapping
solution to a problem)
Coding Space
oOf these mappings, one to one mapping is highly desirable with
Solution Space
n-1 mapping one chromosome representing only one solution to a problem.

1-1 mapping
37 38

Initialization Initialization
• Create initial population of solutions • Population of solutions
o Through a process of randomization • Fitness of solutions are evaluated (= objective function)
o Through a local search procedure
Solution No. Fitness Value
o Selecting only feasible solution
1 0 1 0 0 1 0 1 1 0 1 0 1 13.2783
0 1 1 0 1 0 1 0 0 1 0 1 2 20.3749
• Consider a problem: Minimize F(x1,x2,x3)
0 0 1 0 1 0 1 1 1 1 0 0 3 19.8302
• With binary encoding, we have 0 1 0 1 0 0 1 0 0 0 1 1 4 52.9405
1 0 0 0 1 0 1 0 1 0 0 1 5 25.8302
1 0 1 1 0 0 1 1 1 0 0 1 1 0 1 1 1 1 0 0 0 0 1 1 6 36.0282
0 0 1 0 1 0 1 1 0 1 1 0 7 70.9202
x1 x2 x3 0 1 1 1 1 0 0 1 1 1 0 1 8 38.9022
0 1 0 1 0 1 0 1 1 0 0 1 9 29.0292
1 0 0 0 1 1 1 1 1 1 0 0 10 21.9292
39 40

Survival of Fittest Reproduction


Selection probability Pk for kth individual
• Sampling mechanisms : select chromosomes 𝒇𝒌 • Crossover operation (based on crossover probability)
from sampling space 𝑷𝒌 = 𝒑𝒐𝒑_𝒔𝒊𝒛𝒆
σ𝒋=𝟏 𝒇𝒋 • Select parents from population based on crossover probability
• Stochastic sampling • Randomly select two points between strings to perform crossover operation
• Roulette Wheel Selection • Perform crossover operations on selected strings
o Determine survival probability proportional to Calculate cumulative probability and construct
fitness value Roulette Wheel Selection based on Pk • Known for local search operation
o Randomly generate number between [0,1] and
select the individual Crossover points

• Deterministic sampling Zone of the


Parent 1 Offspring 1
kth individual
o Select best individuals from the parents and
offsprings with no duplication of the individuals Parent 2 Offspring 2
• Mixed sampling fk is the fitness value of
o Both random and deterministic sampling the kth individual

41 42

7
19-08-2024

Reproduction Reproduction
• For the example of optimization problem Solution Parent Selected Offsprings
o Let the crossover probability be 0.8 Selected
Ok for
Solution No. Chromosomes Random value [0,1] Crossover ? 2 0 1 1 0 1 0 1 0 0 1 0 1 0 1 1 0 1 0 1 1 0 1 0 1

1 1 0 1 0 0 1 0 1 1 0 1 0 0.9502 >0.8 No 3 0 0 1 0 1 0 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 0 0
2 0 1 1 0 1 0 1 0 0 1 0 1 0.2191 <0.8 Yes
3 0 0 1 0 1 0 1 1 1 1 0 0 0.4607 <0.8 Yes 4 0 1 0 1 0 0 1 0 0 0 1 1 0 1 0 1 0 0 1 1 0 1 1 1
4 0 1 0 1 0 0 1 0 0 0 1 1 0.6081 <0.8 Yes 7 0 0 1 0 1 0 1 1 0 1 1 0 0 0 1 0 1 0 1 0 0 0 1 0
5 1 0 0 0 1 0 1 0 1 0 0 1 0.8128 >0.8 No
6 1 0 1 1 1 1 0 0 0 0 1 1 0.9256 >0.8 No 8 0 1 1 1 1 0 0 1 1 1 0 1 0 1 0 0 1 0 0 1 1 1 0 1
7 0 0 1 0 1 0 1 1 0 1 1 0 0.7779 <0.8 Yes 10 1 0 0 0 1 1 1 1 1 1 0 0 1 0 1 1 1 1 1 1 1 1 0 0
8 0 1 1 1 1 0 0 1 1 1 0 1 0.4596 <0.8 Yes
9 0 1 0 1 0 1 0 1 1 0 0 1 0.9817 >0.8 No
10 1 0 0 0 1 1 1 1 1 1 0 0 0.7784 <0.8 Yes
43 44

Reproduction Reproduction
• Mutation operation (based on mutation probability) • For optimization problem
• Each bit of every individual is modified with probability P m. Minimize f(x1,x2,x3)
0 1 1 0 1 0 1 1 0 1 0 1
• Main operator for global search (looking at new areas of search space) • Let Pm = 1/12 = 0.083
0.12 0.57 0.62 0.31 0.01 0.73 0.83 0.63 0.02 0.26 0.94 0.63
• Pm is usually small {0.0001, …., 0.01}. • Generate a random number [0,1]
• Rule of thumb Pm = 1/ (no of bits in chromosome) for each bit
Mutation
• Select bit having probability less
than Pm.
• Interchanging the bits with each 0 1 1 0 0 0 1 1 1 1 0 1
other.

45 46

Generating offsprings Summary of GA


• Direct the search towards the promising region in search space. Begin
• Basic issues involved in selection: INITIALIZE population with random candidate solution
o Sampling space: parents and offsprings Evaluate each solution (calculate fittest function)
o Regular sampling space: all offsprings + few parents = pop_size
o Enlarged sampling space: all offsprings + all parents REPEAT UNTIL (Termination condition satisfied) {
Selection
Crossover
Mutation
Evaluate population based on fittest function
}
End

47 48

8
19-08-2024

Parameters of GA When to use GAs?


• Population Size – it is problem specific. A good population size is about 20-30, • Alternate solutions are too slow or overly complicated.
however even sizes of 50-100 are reported. • Need an exploratory tool to examine new approaches.
• The best population size depends on the size of encoded string (chromosomes). • Problem is similar to one that has already been successfully solved by using GA.
More the encoded size, more should be the size of population.
• Want to hybridize with an existing solution.
• Crossover probability – It should be high generally, about 80-95% (for some
problems it could be even as low as 60%) • Benefits of the GA technology meet key problem requirements.
o Near optimal solution will suffice.
• Mutation rate – It should be very low. Best rate seems to be about 0.5-1%.
o Adequate computational power is available.
• Crossover and mutation type – Operators depend on the chosen encoding and on o The problem does converge to an optimal solution.
the problem

49 50

Applications of GAs GA-Example-1


Domain Application Types • Maximize (x2 + 1) over (0, 1, …., 31)
Control Gas Pipelining. Pol Balancing, Missile Evasion, Pursuit
• Representation : Binary code e.g. 01101 for 13
Design Semiconductor Layout, Aircraft Design, Keyboard Configuration, Communication
Networks • Chromosome length is 5 (11111 for 31)
Scheduling Manufacturing, Facility Scheduling, Resource Allocation • Population size is 4.
Robotics Trajectory Planning • 1- point crossover
Machine Learning Designing Neural Networks, Improving Classification Algorithm, Classifier System
• Roulette Wheel Selection
Signal Processing Filter Design
Game Playing Pokers, Checkers, Prisoner's Dilemma
Combinatorial Set Covering, TSP, Routing, Bin Packing, Graph Coloring, Partitioning Randomly generated 01101 13
Problems initial population 11000 24
01000 8
10010 18
51 52

GA-Example 1: Selection GA-Example 1


Roulette Wheel String Mating Crossover Offsprings after X value Fitness
no. Pool point crossover 𝒇 𝒙 = 𝒙𝟐 + 𝟏
String no. Initial X Fitness Prob. Exp. Actual
Population Value 𝒇 𝒙 = 𝒙𝟐 + 𝟏 Count Count 1 01101 4 01100 12 145
𝒇𝒊 / ෍ 𝒇𝒊 𝒇𝒊 6%
2 11000 4 11001 25 626
29%
𝒇𝒂𝒗𝒈
3 11000 2 11010 26 677
1 01101 13 170 0.15 0.60 1 4 10010 2 10000 16 257
50%
2 11000 24 577 0.50 2.00 2
3 01000 8 65 0.06 0.24 0
15%
Sum σ 𝒇𝒊 1705
4 10010 18 325 0.29 1.16 1 Average 𝒇𝒂𝒗𝒈 426.25
Sumσ 𝒇𝒊 1137 1.00
1 2 3 4
Maximum 677
Average 284.25 0.25
𝒇𝒂𝒗𝒈
Solution improved from 577 to 677 after crossover
Maximum 577

53 54

9
19-08-2024

GA-Example 1 GA-Example 1
• Mutation probability Pm = 1/5 = 0.2 (We can also consider 0.01, 0.1 etc.)
String Offsprings Offsprings X value Fitness
• Generate random number for all 20 genes. no. after after mutation 𝒇 𝒙 = 𝒙𝟐 + 𝟏
crossover
String No. Random numbers 1 01100 01100 12 145
2 11001 11100 28 785
1 0.6787 0.7577 0.7431 0.3922 0.6555 3 11010 11010 26 677
2 0.7712 0.7060 0.1318 0.2769 0.0462 4 10000 10000 16 257
3 0.5971 0.8235 0.6948 0.3171 0.9502 Sum σ 𝒇𝒊 1864
Average 𝒇𝒂𝒗𝒈 466
4 0.3644 0.4387 0.3816 0.7655 0.7952
Maximum 785

• Genes in the above highlighted places are to be flipped (0 to 1 and 1 to 0). Best in this iteration (final)

55 56

Random number used for crossover


GA-Example-2 GA-Example-2 (Selection Criteria:
Crossover prob. (Cp) = 0.8)
• A supply chain of computer manufacturing industry. • Fitness value (f) of string = (100 - D) String no. Iteration 1 Iteration 2
o Demand of each customer zone is satisfied exactly by one production plant. • Selection: expected count (= f/𝑓𝑎𝑣𝑔 ) 1 0.98 0.47
o Each production plant supplies to exactly one customer zone. • Crossover procedure 2 0.93 0.55
3 0.45 0.88
Customer Zone 1 Customer Zone 2 Customer Zone 3 Customer Zone 4 4 0.57 0.93
Plant 1 20 25 17 22 Before crossover After crossover
Plant 2 14 9 19 6 Iteration 1
Parent 1 a b c d Child 1 l j k i String 3and 4 are selected for
Plant 3 13 15 23 30
crossover as their random number are
Plant 4 8 25 12 7 Parent 2 Child 2 less than Cp.
i j k l d b c a
Iteration 2
• Distance matrix shown in km. String 3and 4 are selected for
• Objective function: Min Distance crossover as their random number are
less than Cp.
57 58

GA-Example-2 CZ-1 CZ-2 CZ-3 CZ-4 GA-Example-2


Plant 1 20 25 17 22
Plant 2 14 9 19 6 Initial population
Plant 3 13 15 23 30
Plant 4 8 25 12 7 String Details Objective function Fitness Expected
Initial population value (D) function Count
String Details Objective function Fitness function value (100-D)
value (D) value (100-D) 1 1-2-3-4 20+9+23+7 = 59 41 1.21  1
1 1-2-3-4 20+9+23+7 = 59 41 2 2-4-1-3 14+25+17+30 =86 14 0.41  0
2 2-4-1-3 14+25+17+30 =86 14 3 3-1-4-2 13+25+12+6 = 56 44 1.30  2
3 3-1-4-2 13+25+12+6 = 56 44 4 4-3-2-1 8+15+19+22 = 64 36 1.07  1
4 4-3-2-1 8+15+19+22 = 64 36 ftotal = 135
favg = 33.75

59 60

10
19-08-2024

GA-Example-2 GA-Example-2
Mating pool After crossover Iteration 2
Crossover between string
String Details 3 and 4 String Details String Details Objective function Fitness Expected
1 1-2-3-4 1 1-2-3-4 value (D) function Count
Prt 1: 3–1–4–2 value (100-D)
2 2-4-1-3 2 3-1-4-2
Prt 2: 4–3–2–1 1 1-2-3-4 20+9+23+7 = 59 41 1.14  1
3 3-1-4-2 3 1-3-2-4
2 3-1-4-2 13+25+12+6 = 56 44 1.23  2
4 4-3-2-1 4 2-1-4-3
Ch 1: 1–3–2–4 3 1-3-2-4 20+15+19+7 = 61 39 1.03  1
Ch 2: 2–1–4–3 4 2-1-4-3 14+25+12+30 = 81 19 0.53  0
ftotal = 143
favg = 35.75

61 62

GA-Example-2 Maximum fitness value = 44 Knapsack Problem


Best solution is 56
Iteration 3 • Items are available in different sizes and values. Fill up the knapsack
of given size so as maximizes its value.
String Details Objective function Fitness Expected
value (D) function Count • Example: knapsack of size 50 to be filled with as many of the
value (100-D) following items:
1 2-1-4-3 14+25+12+30 = 81 19 0.54  0 S.No. Item Size Value
2 4-2-3-1 8+9+23+22 = 62 38 1.08  1 1 A 11 22
2 B 5 12
3 3-1-4-2 13+25+12+6 = 56 44 1.25  2
3 C 7 18
4 1-3-2-4 20+15+19+7=61 39 1.11  1 4 D 12 31
ftotal = 1430 5 E 21 39
favg = 35 6 F 18 32

63 64

0/1 Knapsack Problem 0/1 Knapsack Problem


S.No. Item Size Value
• Knapsack size 50 1 A 11 22 • Fitness function convert the constraint problem to an unconstraint
• Encoding : binary 0-1. 2 B 5 12 problem.
• How many genes in a chromosomes. 3 C 7 18 • How? Use a penalty function !
𝑛 4 D 12 31
𝑛 𝑛
5 E 21 39
• Formulation 𝑀𝑎𝑥𝑖𝑚𝑖𝑧𝑒 ෍ 𝑣𝑖 𝑥𝑖 • Fitness function: 𝑀𝑎𝑥𝑖𝑚𝑖𝑧𝑒 ෍ 𝑣𝑖 𝑥𝑖 + 𝑀𝑖𝑛(0,1000 ∗ (50 − ෍ 𝑠𝑖 𝑥𝑖 ))
6 F 18 32
𝑖=0
𝑖=0 𝑖=0
𝑛

𝑠𝑢𝑐ℎ 𝑡ℎ𝑎𝑡 ෍ 𝑠𝑖 𝑥𝑖 ≤ 50
𝑖=0 • Chromosome A: 101100
• What should be the fitness function? • Chromosome B : 110111

65 66

11
19-08-2024

0/1 Knapsack Problem: Crossover & Mutation


• Single point crossover

• Parent 1: 101 100; Parent 2: 110 111  Child 1: 101 111; Child 2: 110 100

• Two point crossover


• Parent 1: 10 11 00; Parent 2: 11 01 11  Child 1: 10 01 00; Child 2: 11 11 11
Thank You
• Mutation: Bit inversion 100100  110100

67

12

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy