matlab program for comparison and loop
1 次查看(过去 30 天)
显示 更早的评论
Chromosome[1] = [12;05;23;08] Chromosome[2] = [02;21;18;03] Chromosome[3] = [10;04;13;14] Chromosome[4] = [20;01;10;06] Chromosome[5] = [01;04;13;19] Chromosome[6] = [20;05;17;01]
R[1] = 0.201 R[2] = 0.284 R[3] = 0.099 R[4] = 0.822 R[5] = 0.398 R[6] = 0.501
C[1] = 0.1254 C[2] = 0.2710 C[3] = 0.4118 C[4] = 0.6639 C[5] = 0.7882 C[6] = 1.0
i want to write a simple matlab program in which i have to compare the r(k) with value of c(k) if r(k) lies within the range of c(k) then it will return chromosome of that particular k. actually it is part of genetic algorithm i have write 30% program but i am confused at roulette stage how to write it.
the response of the above program must return the following output.
Chromosome[1] = [02;21;18;03] Chromosome[2] = [10;04;13;14] Chromosome[3] = [12;05;23;08] Chromosome[4] = [20;05;17;01] Chromosome[5] = [10;04;13;14] Chromosome[6] = [20;01;10;06]
manual calculation are as follow.
as r1=0.201 doesnot lie in the range of c1=0.125 (c1<r1), so we move forward and compare it with next, means with c2. as r1=0.201<c2 = 0.2710 it means it must replace chromosome of 1 with 2.
following is the table of replacement.
NewChromosome[1] = Chromosome[2] NewChromosome[2] = Chromosome[3] NewChromosome[3] = Chromosome[1] NewChromosome[4] = Chromosome[6] NewChromosome[5] = Chromosome[3] NewChromosome[6] = Chromosome[4]
3 个评论
采纳的回答
Geoff Hayes
2014-10-3
Mudasir - from your roulette selection scheme to select parents, where the vector R seems to be the randomly assigned values (between 0 and 1) for each parent, and C is the cumulative probability distribution vector, then you can implement the following to get the parent selection
R(1) = 0.201;
R(2) = 0.284;
R(3) = 0.099;
R(4) = 0.822;
R(5) = 0.398;
R(6) = 0.501;
C(1) = 0.1254;
C(2) = 0.2710;
C(3) = 0.4118;
C(4) = 0.6639;
C(5) = 0.7882;
C(6) = 1.0;
for k=1:length®
% use find to find the first (1) element of
% C that is greater than R(k)
idx = find(C>R(k),1);
if isempty(idx)
idx = length(C);
end
% select chromosome idx as new parent
end
The above determines the idx according to R and C; you just need to map the population chromosomes to the new parent set.
3 个评论
Geoff Hayes
2014-10-6
Mudasir - looking at his paper (in the link you provided), the statement which you highlighted in bold does not make all that much sense. I think that you can ignore it. He may be alluding to how other mutation processes work where you mutate the gene only if the random number generated for that gene is less than the mutation rate. But when he states that Mutation process is done by generating a random integer between 1 and total_gen (1 to 24). If generated random number is smaller than mutation_rate(ρm) variable then marked the position of gen in chromosomes, it is unclear how an randomly generated integer between 1 and 24 can ever be less than the mutation rate, which will always be less than one!
I think if you follow his next steps and just realize that if the mutation rate is 10%, then 10% of the genes in the whole population should be mutated. So this is just
numGenes = 4; % number of genes per chromosome (number of variables)
numChrom = 6; % number of chromosomes (population size)
mutRate = 0.1; % mutation rate
totalNumGenes = numGenes*numChrom; % total number of genes
% across all chromosomes
numGenesToMut = floor(0.1* totalNumGenes); % number of genes to mutate
So there are two genes to mutate, from numGenesToMut. And so we must randomly generate two integers from 1 to 24. In his example, the random numbers are 12 and 18. If we consider 12, since there are 4 genes per chromosome, then the mutation occurs in the 4th gene of the 3rd chromosome as he has shown above (since 12=4+4+4). With 18, again since there are 4 genes per chromosome (imagine all 6 chromosomes lined up, side by side), then the mutation occurs at the second gene of the fifth chromosome (since 18=4+4+4+4+2).
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Point Cloud Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!