[关闭]
@rg070836rg 2018-07-03T10:47:53.000000Z 字数 877 阅读 845
  1. function f = replace_chromosome(intermediate_chromosome, M, V,pop)%精英选择策略
  2. [N, m] = size(intermediate_chromosome);
  3. [temp,index] = sort(intermediate_chromosome(:,M + V + 1));
  4. clear temp m
  5. for i = 1 : N
  6. sorted_chromosome(i,:) = intermediate_chromosome(index(i),:);
  7. end
  8. max_rank = max(intermediate_chromosome(:,M + V + 1));
  9. previous_index = 0;
  10. for i = 1 : max_rank
  11. current_index = max(find(sorted_chromosome(:,M + V + 1) == i));
  12. if current_index > pop
  13. remaining = pop - previous_index;
  14. temp_pop = ...
  15. sorted_chromosome(previous_index + 1 : current_index, :);
  16. [temp_sort,temp_sort_index] = ...
  17. sort(temp_pop(:, M + V + 2),'descend');
  18. for j = 1 : remaining
  19. f(previous_index + j,:) = temp_pop(temp_sort_index(j),:);
  20. end
  21. return;
  22. elseif current_index < pop
  23. f(previous_index + 1 : current_index, :) = ...
  24. sorted_chromosome(previous_index + 1 : current_index, :);
  25. else
  26. f(previous_index + 1 : current_index, :) = ...
  27. sorted_chromosome(previous_index + 1 : current_index, :);
  28. return;
  29. end
  30. previous_index = current_index;
  31. end
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注