You are on page 1of 10

1 Mention types of cross-over, mutation and selector operators.

1.1 Types of Cross-over


After selection of the best parent in the mating pool, the genes of the parents need to be exchanged
in order to produce a suitable offspring. Cross-over is one of the operations that helps in exchanging
the genes from the chromosomes and produce new offspring with different chromosome set.

1.1.1 Single point cross-over


In single point cross over we randomly select a point of separation in the chromosomes of both the
parents and then the genes on either side of the separation point are interchanged with each parent.
This leads in formation of new chromosome set to produce an offspring. Consider the following
example with single point cross over at 3rd point:

Parent 1 → 100 | 101011

Parent 2 → 110 | 001101

Offspring 1 → 110101011

Offspring 2 → 100001101

1.1.2 Two-point cross-over


In two-point cross over we randomly select two points of separation in the chromosomes of the
parents and then the genes are swapped. Consider the following example:

Parent 1 → 100 | 101 | 011

Parent 2 → 110 | 001 | 101

Offspring 1 → 100001011

Offspring 2 → 110101101

1.1.3 Uniform cross over


In uniform cross over multiple separation points are randomly selected and a uniform cross over is
performed on both the parent. Consider the following example:

Parent 1 → 101 | 100 | 110 | 101 | 100 | 101

Parent 2 → 110 | 010 | 000 | 110 | 010 | 110

Offspring 1 → 101 | 010 | 110 | 110 | 100 | 110

Offspring 2 → 110 | 100 | 000 | 101 | 010 | 101

1.2 Types of mutation


Mutations are operation performed within the chromosomes of same parent or offspring. Thus two
parents are not required for the mutation process.

1.2.1 Bit flip


When chromosomes are primarily formed of binary digits i.e. (0,1) then the bit flip mutation
operation can be performed in which random genes in a chromosome of parents are flipped to the
opposite binary value i.e. a 0 bit is flipped to 1 and 1 bit is flipped to 0

Chromosome → 10010010111
Mutation → 10110010101

1.2.2 Swap mutation


In swap mutation any two random bits in the chromosomes are flipped in their positions to create a
mutated chromosome. Consider following example:

Chromosome → 10010010111

Mutation → 10110010011

1.2.3 Scrambled mutation


In scrambled mutation a series of bits within the chromosomes are scrambled in their order. Consider
following example:

Chromosome → 10010010111

Mutation → 10111000011

1.3 Types of selection operators


1.3.1 Roulette wheel selection
Roulette wheel is a device used in casinos to randomize outcomes in the game of gambling. In genetic
algorithm a roulette wheel approach can be used in determining a random factor between 0 and 1.
This factor is helpful in selecting the parent with highest probability chance of getting selected.
𝑓𝑖
Probability of choosing individual ‘i’ is equal to 𝑝𝑖 = ∑𝑁 , where fj is the fitness of ‘i’ and N is the
𝑗=1 𝑓𝑗
size of current generation (note that in this method one individual can be drawn multiple times).

1.3.2 Boltzmann selection


In Boltzmann selection, a continuously varying temperature controls the rate of selection according to
a pre-set schedule. The temperature starts out high, which means that the selection pressure is low.
The temperature is gradually lowered, which gradually increases the selection pressure, thereby
allowing the GA to narrow in more closely to the best part of the search space while maintaining the
appropriate degree of diversity.

2 Genetic Algorithm in any language


2.1 Code:
Sub geneticA()

Dim i, j, k, t, iterno, popno, maxnumlen, popsize, counter, ofscount As Integer

Dim fitness, prob, excount, roulette, minrange, maxrange, ofsv, ofsv1, ofsv2, ofsv3, ofsv4 As Double

Dim chrom1, ofs, ofs1, ofs2, ofs3, ofs4 As String

Dim rng, rngc, rngclr As Range

Set rngclr = Range(Cells(7, 8), Cells(6 + Cells(5, 8), 20))

rngclr.ClearContents
iterno = 0 'iteration count

popno = 0 'population count

minrange = Cells(6, 2)

maxrange = Cells(6, 3)

popsize = Cells(7, 3)

maxnumlen = Len(Application.WorksheetFunction.Dec2Bin(maxrange))

'initial population

For i = 1 To popsize

20 Cells(6 + i, 10) = Application.WorksheetFunction.RandBetween(minrange, maxrange)

If i = 1 Then

GoTo 10

End If

For j = 1 To i - 1

If Cells(6 + i, 10) = Cells(6 + j, 10) Then

GoTo 20

End If

Next j

10 Next i

'algorithm

Do While Cells(5, 9) = 0

iterno = iterno + 1
fitness = 0

'print iteration number

For i = 1 To popsize

Cells(6 + i + popsize * (iterno - 1), 8) = iterno

Next i

For i = 1 To popsize

popno = popno + 1

'print population number

Cells(6 + i + popsize * (iterno - 1), 9) = popno

'print next population

If iterno > 1 Then

Cells(6 + i + popsize * (iterno - 1), 10) = Cells(6 + i + popsize * (iterno - 2), 20)

End If

'print chromosomes

chrom1 = Application.WorksheetFunction.Dec2Bin(Cells(6 + i + popsize * (iterno - 1), 10),


maxnumlen)

Cells(6 + i + popsize * (iterno - 1), 11) = chrom1

'function evaluation

Cells(6 + i + popsize * (iterno - 1), 12) = Cells(6 + i + popsize * (iterno - 1), 10) ^ 2

'fitness sum

fitness = fitness + Cells(6 + i + popsize * (iterno - 1), 12)


Next i

'print fitness sum

For i = 1 To popsize

Cells(6 + i + popsize * (iterno - 1), 13) = fitness

Next i

For i = 1 To popsize

'print probability

Cells(6 + i + popsize * (iterno - 1), 14) = Cells(6 + i + popsize * (iterno - 1), 12) / Cells(6 + i +
popsize * (iterno - 1), 13)

'print expected count

Cells(6 + i + popsize * (iterno - 1), 15) = Cells(6 + i + popsize * (iterno - 1), 14) * popsize

Next i

'select range

Set rng = Range(Cells(7 + popsize * (iterno - 1), 15), Cells(6 + popsize + popsize * (iterno - 1), 15))

Set rngc = Range(Cells(7 + popsize * (iterno - 1), 11), Cells(6 + popsize + popsize * (iterno - 1), 11))

For i = 1 To (popsize + 2) / 2

'largest expected count

Cells(6 + i + popsize * (iterno - 1), 16) = Application.WorksheetFunction.Large(rng, i)

'selecting parent

Cells(6 + i + popsize * (iterno - 1), 17) = Application.WorksheetFunction.Index(rngc,


Application.WorksheetFunction.Match(Cells(6 + i + popsize * (iterno - 1), 16), rng, 0))

Next i
For i = 1 To ((popsize + 2) / 2) - 1

'one point crossover

30 Cells(7 + i + popsize * (iterno - 1), 18) = Application.WorksheetFunction.RandBetween(1,


maxnumlen - 1)

'generation of offspring

'offspring 1

ofs = ""

ofsv = 0

For k = 1 To Cells(7 + i + popsize * (iterno - 1), 18)

ofs = ofs & Mid(Cells(7 + i + popsize * (iterno - 1), 17), k, 1)

Next k

For j = Cells(7 + i + popsize * (iterno - 1), 18) + 1 To maxnumlen

ofs = ofs & Mid(Cells(7 + popsize * (iterno - 1), 17), j, 1)

Next j

ofsv = Application.WorksheetFunction.Bin2Dec(ofs)

Cells(5 + 2 * i + popsize * (iterno - 1), 19) = ofs

Cells(5 + 2 * i + popsize * (iterno - 1), 20) = ofsv

If CInt(ofsv) > maxrange Then

GoTo 30

End If

'offspring 2

ofs2 = ""

ofsv2 = 0

For k = 1 To Cells(7 + i + popsize * (iterno - 1), 18)

ofs2 = ofs2 & Mid(Cells(7 + popsize * (iterno - 1), 17), k, 1)

Next k

For j = Cells(7 + i + popsize * (iterno - 1), 18) + 1 To maxnumlen


ofs2 = ofs2 & Mid(Cells(7 + i + popsize * (iterno - 1), 17), j, 1)

Next j

ofsv2 = Application.WorksheetFunction.Bin2Dec(ofs2)

Cells(6 + 2 * i + popsize * (iterno - 1), 19) = ofs2

Cells(6 + 2 * i + popsize * (iterno - 1), 20) = ofsv2

If CInt(ofsv2) > maxrange Then

GoTo 30

End If

Next i

'termination criteria

ofscount = 0

If Cells(6 + popsize * iterno, 9) > 25 Then

For i = 1 To 25

If (Abs((Cells(6 + popsize * iterno, 20)) - (Cells(6 - i + popsize * iterno, 20))) = 0) Or ((Abs((Cells(6


+ popsize * iterno, 20)) - (Cells(6 - i + popsize * iterno, 20))) > 0) And (Abs((Cells(6 + popsize * iterno,
20)) - (Cells(6 - i + popsize * iterno, 20))) < 1)) Then

ofscount = ofscount + 1

End If

Next i

End If

If ofscount > 20 Then

Cells(5, 9) = 1

End If

Loop

Cells(5, 9) = 0

End Sub
2.2 Result:
3 Write algorithm for SASEGASA (Self Adaptive Segregate Genetic Algorithm
with Simulated Annealing aspects)
4 Genetic Algorithm
• Genetic algorithm is one of the techniques which is a subset of guided random search
techniques.
• Genetic algorithm is a bio inspired algorithm which is based on the success of evolution that
takes place in nature. In nature it is seen that an evolutionary process is a never-ending
ongoing process adapting constantly to changing environment and needs.
• This evolution in nature takes place with subtle changes in the DNA of the organism over a
long period of time.
• Each offspring in nature being a better than the previous one and improving little by little in
every generation.
• Genetic algorithm also works on the similar principles of evolving until the optimum solution
is reached.
• The initial population is represented in terms of binary or a form which can be termed as a
chromosome. The individual bit of the chromosomes is termed as genes.
• The initial population is primarily tested for its fitness and the fittest values are put in the
mating pool. These are termed as parents.
• The parents in mating pool are mated using the operation of cross over and the resulting
chromosomes are termed as the off springs. These off springs are expected to be fitter than
the parents and they are further used in the iteration process to check the fitness.
• These iterations are carried on till an optimum solution is reached.

5 Application of genetic programming.


• Bio inspired algorithms like genetic algorithm programming are particularly useful in
optimization of complex functions which could require intense computational effort.
• The conventional mathematical operations used for optimization may most of the time
converge to a local maximum or a local minimum, however the genetic algorithm leads us to
the global maximum and global minimum.
• Genetic programming can be used in travelling salesman problem to determine the optimum
path and reduce the cost of travel and time.
• Ergonomics: Ergonomics is the branch of operational science in which maximum comfort is
aimed at using a particular object, genetic programming can be used in finding the optimum
solution.
• Economics: Can be used to describe various models such as the game theory, cobweb model,
asset pricing, and schedule optimization.
• Some of the applications of GP are curve fitting, data modelling, symbolic regression, feature
selection, classification, etc.

You might also like