📄 replace_chromosome.html
字号:
<html xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <!--This HTML is auto-generated from an M-file.To make changes, update the M-file and republish this document. --> <title>replace_chromosome(intermediate_chromosome,pro,pop)</title> <meta name="generator" content="MATLAB 7.0"> <meta name="date" content="2006-03-07"> <meta name="m-file" content="replace_chromosome"><style>body { background-color: white; margin:10px;}h1 { color: #990000; font-size: x-large;}h2 { color: #990000; font-size: medium;}p.footer { text-align: right; font-size: xx-small; font-weight: lighter; font-style: italic; color: gray;}pre.codeinput { margin-left: 30px;}span.keyword {color: #0000FF}span.comment {color: #228B22}span.string {color: #A020F0}span.untermstring {color: #B20000}span.syscmd {color: #B28C00}pre.showbuttons { margin-left: 30px; border: solid black 2px; padding: 4px; background: #EBEFF3;}pre.codeoutput { color: gray; font-style: italic;}pre.error { color: red;}/* Make the text shrink to fit narrow windows, but not stretch too far in wide windows. On Gecko-based browsers, the shrink-to-fit doesn't work. */ p,h1,h2,div { /* for MATLAB's browser */ width: 600px; /* for Mozilla, but the "width" tag overrides it anyway */ max-width: 600px; /* for IE */ width:expression(document.body.clientWidth > 620 ? "600px": "auto" );} </style></head> <body> <h1>replace_chromosome(intermediate_chromosome,pro,pop)</h1> <p>This function replaces the chromosomes based on rank and crowding distance. Initially until the population size is reached each front is added one by one until addition of a complete front which results in exceeding the population size. At this point the chromosomes in that front is added subsequently to the population based on crowding distance. </p><pre class="codeinput">[N,V] = size(intermediate_chromosome);<span class="keyword">switch</span> pro <span class="keyword">case</span> 1 M = 2; V = 6; <span class="keyword">case</span> 2 M = 3; V = 12;<span class="keyword">end</span><span class="comment">% Get the index for the population sort based on the rank</span>[temp,index] = sort(intermediate_chromosome(:,M + V + 1));<span class="comment">% Now sort the individuals based on the index</span><span class="keyword">for</span> i = 1 : N sorted_chromosome(i,:) = intermediate_chromosome(index(i),:);<span class="keyword">end</span><span class="comment">% Find the maximum rank in the current population</span>max_rank = max(intermediate_chromosome(:,M + V + 1));<span class="comment">% Start adding each front based on rank and crowing distance until the</span><span class="comment">% whole population is filled.</span>previous_index = 0;<span class="keyword">for</span> i = 1 : max_rank current_index = max(find(sorted_chromosome(:,M + V + 1) == i)); <span class="keyword">if</span> current_index > pop remaining = pop - previous_index; temp_pop = <span class="keyword">...</span> sorted_chromosome(previous_index + 1 : current_index, :); [temp_sort,temp_sort_index] = <span class="keyword">...</span> sort(temp_pop(:, M + V + 2),<span class="string">'descend'</span>); <span class="keyword">for</span> j = 1 : remaining f(previous_index + j,:) = temp_pop(temp_sort_index(j),:); <span class="keyword">end</span> <span class="keyword">return</span>; <span class="keyword">elseif</span> current_index < pop f(previous_index + 1 : current_index, :) = <span class="keyword">...</span> sorted_chromosome(previous_index + 1 : current_index, :); <span class="keyword">else</span> f(previous_index + 1 : current_index, :) = <span class="keyword">...</span> sorted_chromosome(previous_index + 1 : current_index, :); <span class="keyword">return</span>; <span class="keyword">end</span> previous_index = current_index;<span class="keyword">end</span></pre><p class="footer"><br> Published with MATLAB® 7.0<br></p> <!--##### SOURCE BEGIN #####
%% replace_chromosome(intermediate_chromosome,pro,pop)
% This function replaces the chromosomes based on rank and crowding
% distance. Initially until the population size is reached each front is
% added one by one until addition of a complete front which results in
% exceeding the population size. At this point the chromosomes in that
% front is added subsequently to the population based on crowding distance.
[N,V] = size(intermediate_chromosome);
switch pro
case 1
M = 2;
V = 6;
case 2
M = 3;
V = 12;
end
% Get the index for the population sort based on the rank
[temp,index] = sort(intermediate_chromosome(:,M + V + 1));
% Now sort the individuals based on the index
for i = 1 : N
sorted_chromosome(i,:) = intermediate_chromosome(index(i),:);
end
% Find the maximum rank in the current population
max_rank = max(intermediate_chromosome(:,M + V + 1));
% Start adding each front based on rank and crowing distance until the
% whole population is filled.
previous_index = 0;
for i = 1 : max_rank
current_index = max(find(sorted_chromosome(:,M + V + 1) == i));
if current_index > pop
remaining = pop - previous_index;
temp_pop = ...
sorted_chromosome(previous_index + 1 : current_index, :);
[temp_sort,temp_sort_index] = ...
sort(temp_pop(:, M + V + 2),'descend');
for j = 1 : remaining
f(previous_index + j,:) = temp_pop(temp_sort_index(j),:);
end
return;
elseif current_index < pop
f(previous_index + 1 : current_index, :) = ...
sorted_chromosome(previous_index + 1 : current_index, :);
else
f(previous_index + 1 : current_index, :) = ...
sorted_chromosome(previous_index + 1 : current_index, :);
return;
end
previous_index = current_index;
end##### SOURCE END #####--> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -