how to generate random population of GA with decimal constraint

2 views (last 30 days)
i have to max this function max f(x1,x2)=21.5+x1sin(4pix1)+x2sin(20pix2) where -3<=x1<=12.1 4.1<=x2<=5.8 using genetic algo i have to maximize and for ga i have to encode these x1 x2 into binary strings. i want to genrate an initial population of x1 and x2 in binary form with in this decimal range
%Binary number generation
P = randi([0,1],5,33) % Generate a 5-by-33 random binary matrix.
c=P(1:5,1:18); % x1 values extraction rom random population
d=P(1:5,19:33);
x1=bi2de(c); %conversion of x1 values to decimal
x2=bi2de(d);
f=zeros(1,5);
for i=1:5
f(i)=21.5+x1(i,1)*sin(4*360*x1(i,1))+x2(i,1)*sin(20*360*x2(i,1));
f(1,i)=f(i);
end
f %evaluation of fitness values
F=sum(f) %total fitness of the population
right now i have coded this but my problem is the population of binary number which is being generated randomly is not with in constraint of x1 and x2.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!