Info
此问题已关闭。 请重新打开它进行编辑或回答。
if i have a code for genetic algorithm but its need some alter how to do them?
1 次查看(过去 30 天)
显示 更早的评论
i have this code for genetic algorithm
% i need a minimum value for the fitness function
%nPop = 10 , MaxIt = 100
% pc = 0.6; % Crossover Percentage
% nc = 2*round(pc*nPop/2); % Number Of offsprings (also Parents)
%%generate populations
Matrix_pop = [];
val = [];
for k=1 : nPop % 10 is the population size
Matrix_pop{k} = randi ([0 1] , 10,10) % create a binary (10,10) matrix
fit = sum(sum(Matrix_pop{k})); % fitness function is compute the total number of ones in Matrix.
val(k) = fit ;
end
value = sort(val , 'ascend');
%%Main algorithm
for it=1:MaxIt %maximum number of iteration
for i=1: nc/2 % number of parent
for k=1 : value.length
i1 = ([1 k]);
i2 = ([1 k+1]);
p1=Matrix_pop{i1};
p2=Matrix_pop{i2};
after this how can i perform the crossover and mutation and create a new population to get the minimum value for the fitness function and after that the solution will display as the matrix which have the minimum value ????
can any one give me help , thank you
0 个评论
回答(0 个)
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!