Term Project: Genetic Algorithm in Engineering Process Modelling
Term Project: Genetic Algorithm in Engineering Process Modelling
MEMBERS
Problem Statement:
The particular integral is important when studying the long time or steady state response of
the oscillator. This solution is
Figure shows the amplitude and phase for different values of the damping coefficient β. The
damping ensures that the amplitude is finite for all values of ω. Also the change in the phase
is more gradual.
The low frequency and high frequency behaviour are exactly the same as the undamped
situation. The changes due to damping are mainly in the vicinity of ω = ω0. The amplitude is
maximum at,
Here we perform iterations (only one) on initial values of ω, to show how GA works to improve the
overall fitness of the population.
1st Generation:
Favg = 0.90
2nd Generation:
Mating pool CS ωn DV Fi
Favg = 1.14
DV = Decoded Value
Fi = Fitness of individual string in the population
Favg = Average Fitness Value of the population
AC = Actual Count of the String
CS = Crossing Site
• We note that the least fit members get 0 copies in the mating pool. Selection here
has been done on the basis of Proportionate Selection Method.
• It is observed that in the 2nd generation, the Favg value increases to 1.14 from 0.90 in
the 1st generation. Hence, with each succeeding generation, the Favg value
increases, moving closer to the peak value of amplitude, at which all ω values
converge around the resonant value of ω.
• The maximum fitness value in each generation is highlighted by the blue colour. It is
noticed that the maximum fitness value reduces as we move to the 2nd generation.
This observation is not constant with each generation or each set of population
members selected. Only the Favg value is found to increase with every generation.
• We use a mutation constant (Pm) of 2% (i.e. 1/50). Mutation is performed and shown
in the 2nd table, highlighted by the pink colour. Here, of the available 48 bits, we
randomly choose 1 bit to mutate.
• Cross-over constant (Pc) is taken almost equal to 1 i.e. each pair of members selected
undergo cross-over almost definitely. The crossing sites are selected randomly, as
shown in the 2nd generation table (3,4 and 5 are taken as the random crossing sites).
• The decoded value (DV) is the actual integer value of the binary string representing
the member. The decoding algorithm has been included in the GA code on the
following pages.
THE CODE (IMPLEMENTED IN C)
#include<stdio.h>
#include<conio.h> //to use the getche function
#include<stdlib.h> //to use the rand function
#include<math.h>
printf("\nWelcome to our first Genetic Algorithm. \nThe Algorithm’s function is to find the
maximum amplitude and the corresponding resonance frequency for a forced damped oscillator.
y = 1/√(1-x^2)^2+4x^2 is the amplitude function that we ty to maximise using GA here...\n");
for(j=0;j<6;j++)
popcurrent[j]=popnext[j]; //copy the members of popnext to popcurrent
} // loop back until no. of iterations is exceeded
} //end of main
} // end of for(j)
return(0);
} //end of evpop function
float x(chrom popcurrent) //x function that evaluate the value of a given chrom
{
float z;
z=(popcurrent.bit[0]*1)+(popcurrent.bit[1]*2)+(popcurrent.bit[2]*4)+(popcurrent.bit[3]*8)+(popcur
rent.bit[4]*16)+(popcurrent.bit[5]*32)+(popcurrent.bit[6]*64)+(popcurrent.bit[7]*128);
return(z/100); //return the value of z/100, to account for precision decimal places
} // end x function
float y(float x) // the y function that we look for it's maximum value takes x value
{
float y;
y=1/sqrt((1-x*x)*(1-x*x)+4*x*x); // the function is y= 1/√(1-x^2)^2+4x^2)
return(y);
} // end of y function
void *selection(chrom popcurrent[6]) // selection takes a pointer to array of chroms
{
int i,j;
chrom temp; //temp member to use in sorting
} // end of if
} // end of for loop
for(i=0;i<6;i++)
printf("\nSorting:popnext[%d] fitness=%d",i,popcurrent[i].fit); //printing the result
printf("\n"); //print new line
flushall(); //flush the input buffer
return(0);
} //end of pick members
function
for(i=0;i<6;i++)
popnext[i].fit=y(x(popnext[i])); // calculating the fitness values for the new set
for(i=0;i<6;i++)
printf("\nCrossOver popnext[%d]=%d%d%d%d%d%d%d%d value=%d fitness = %d", i,
popnext[i].bit[7], popnext[i].bit[6], popnext[i].bit[5], popnext[i].bit[4], popnext[i].bit[3],
popnext[i].bit[2], popnext[i].bit[1], popnext[i].bit[0], x(popnext[i]), popnext[i].fit);
// printing the bits, value and fitness for the members of the new set
return(0);
} // end crossover function