⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tournament_selection.html

📁 NSGA-II多目标优化的matlab代码
💻 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>function f = selection_individuals(chromosome,pool_size,tour_size)</title>
      <meta name="generator" content="MATLAB 7.0">
      <meta name="date" content="2006-03-07">
      <meta name="m-file" content="tournament_selection"><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>function f = selection_individuals(chromosome,pool_size,tour_size)</h1><pre class="codeinput"><span class="comment">% function selection_individuals(chromosome,pool_size,tour_size) is the</span>
<span class="comment">% selection policy for selecting the individuals for the mating pool. The</span>
<span class="comment">% selection is based on tournament selection. Argument 'chromosome' is the</span>
<span class="comment">% current generation population from which the individuals are selected to</span>
<span class="comment">% form a mating pool of size 'pool_size' after performing tournament</span>
<span class="comment">% selection, with size of the tournament being 'tour_size'. By varying the</span>
<span class="comment">% tournament size the selection pressure can be adjusted.</span>

[pop,variables] = size(chromosome);
rank = variables - 1;
distance = variables;

<span class="keyword">for</span> i = 1 : pool_size
    <span class="keyword">for</span> j = 1 : tour_size
        candidate(j) = round(pop*rand(1));
        <span class="keyword">if</span> candidate(j) == 0
            candidate(j) = 1;
        <span class="keyword">end</span>
        <span class="keyword">if</span> j &gt; 1
            <span class="keyword">while</span> ~isempty(find(candidate(1 : j - 1) == candidate(j)))
                candidate(j) = round(pop*rand(1));
                <span class="keyword">if</span> candidate(j) == 0
                    candidate(j) = 1;
                <span class="keyword">end</span>
            <span class="keyword">end</span>
        <span class="keyword">end</span>
    <span class="keyword">end</span>
    <span class="keyword">for</span> j = 1 : tour_size
        c_obj_rank(j) = chromosome(candidate(j),rank);
        c_obj_distance(j) = chromosome(candidate(j),distance);
    <span class="keyword">end</span>
    min_candidate = <span class="keyword">...</span>
        find(c_obj_rank == min(c_obj_rank));
    <span class="keyword">if</span> length(min_candidate) ~= 1
        max_candidate = <span class="keyword">...</span>
        find(c_obj_distance(min_candidate) == max(c_obj_distance(min_candidate)));
        <span class="keyword">if</span> length(max_candidate) ~= 1
            max_candidate = max_candidate(1);
        <span class="keyword">end</span>
        f(i,:) = chromosome(candidate(min_candidate(max_candidate)),:);
    <span class="keyword">else</span>
        f(i,:) = chromosome(candidate(min_candidate(1)),:);
    <span class="keyword">end</span>
<span class="keyword">end</span>
</pre><p class="footer"><br>
         Published with MATLAB&reg; 7.0<br></p>
      <!--
##### SOURCE BEGIN #####
%% function f = selection_individuals(chromosome,pool_size,tour_size)

% function selection_individuals(chromosome,pool_size,tour_size) is the
% selection policy for selecting the individuals for the mating pool. The
% selection is based on tournament selection. Argument 'chromosome' is the
% current generation population from which the individuals are selected to 
% form a mating pool of size 'pool_size' after performing tournament 
% selection, with size of the tournament being 'tour_size'. By varying the 
% tournament size the selection pressure can be adjusted. 

[pop,variables] = size(chromosome);
rank = variables - 1;
distance = variables;

for i = 1 : pool_size
    for j = 1 : tour_size
        candidate(j) = round(pop*rand(1));
        if candidate(j) == 0
            candidate(j) = 1;
        end
        if j > 1
            while ~isempty(find(candidate(1 : j - 1) == candidate(j)))
                candidate(j) = round(pop*rand(1));
                if candidate(j) == 0
                    candidate(j) = 1;
                end
            end
        end
    end
    for j = 1 : tour_size
        c_obj_rank(j) = chromosome(candidate(j),rank);
        c_obj_distance(j) = chromosome(candidate(j),distance);
    end
    min_candidate = ...
        find(c_obj_rank == min(c_obj_rank));
    if length(min_candidate) ~= 1
        max_candidate = ...
        find(c_obj_distance(min_candidate) == max(c_obj_distance(min_candidate)));
        if length(max_candidate) ~= 1
            max_candidate = max_candidate(1);
        end
        f(i,:) = chromosome(candidate(min_candidate(max_candidate)),:);
    else
        f(i,:) = chromosome(candidate(min_candidate(1)),:);
    end
end
##### SOURCE END #####
-->
   </body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -