Click here to Skip to main content
15,936,887 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi every one:
I need a code for selection part of genetic algorithm. I used the below code, but there is a problem with it: when random number is lower than first probability, this code always select the first chromosome as parent! Would you please guide me?
VB
sumfit=0;
for i=1:length(population)
    sumfit=midfit(i,1)+sumfit;
end

for i=1:length(population)
    fitprob(i,1)=midfit(i)/sumfit;
end
for a=1:length(midfit)
        if randselect1<fitprob(a)>
            for j=1:6
                parent1(a,j)=midpop(a,j);
            end 
            break
        end
 end
Posted
Updated 10-Jun-12 7:28am
v3
Comments
Sergey Alexandrovich Kryukov 27-Sep-12 17:59pm    
If it just two competing chromosomes (than such behavior would be correct), or an array of chromosomes?
Could you formulate the problem mathematically?
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900