non_domination_sort_mod.html ( File view )

  • By chghzz 2013-09-27
  • View(s):101
  • Download(s):5
  • Point(s): 1
			<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>Non-Donimation Sort</title>
      <meta name="generator" content="MATLAB 7.0">
      <meta name="date" content="2006-03-07">
      <meta name="m-file" content="non_domination_sort_mod"><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>Non-Donimation Sort</h1>
      <p>This function sort the current popultion based on non-domination. All the individuals in the first front are given a rank
         of 1, the second front individuals are assigned rank 2 and so on. After assigning the rank the crowding in each front is calculated.
      </p><pre class="codeinput">[N,M] = size(x);
<span class="keyword">switch</span> problem
    <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>
front = 1;

<span class="comment">% There is nothing to this assignment, used only to manipulate easily in</span>
<span class="comment">% MATLAB.</span>
F(front).f = [];
individual = [];
<span class="keyword">for</span> i = 1 : N
    <span class="comment">% Number of individuals that dominate this individual</span>
    individual(i).n = 0;
    <span class="comment">% Individuals which this individual dominate</span>
    individual(i).p = [];
    <span class="keyword">for</span> j = 1 : N
        dom_less = 0;
        dom_equal = 0;
        dom_more = 0;
        <span class="keyword">for</span> k = 1 : M
            <span class="keyword">if</span> (x(i,V + k) &lt; x(j,V + k))
                dom_less = dom_less + 1;
            <span class="keyword">elseif</span> (x(i,V + k) == x(j,V + k))
                dom_equal = dom_equal + 1;
            <span class="keyword">else</span>
                dom_more = dom_more + 1;
            <span class="keyword">end</span>
        <span class="keyword">end</span>
        <span class="keyword">if</span> dom_less == 0 &amp; dom_equal ~= M
            individual(i).n = individual(i).n + 1;
        <span class="keyword">elseif</span> dom_more == 0 &amp; dom_equal ~= M
            individual(i).p = [individual(i).p j];
        <span class="keyword">end</span>
    <span class="keyword">end</span>
    <span class="keyword">if</span> individual(i).n == 0
        x(i,M + V + 1) = 1;
        F(front).f = [F(front).f i];
    <span class="keyword">end</span>
<span class="keyword">end</span>
<span class="comment">% Find the subsequent fronts</span>
<span class="keyword">while</span> ~isempty(F(front).f)
   Q = [];
   <span class="keyword">for</span> i = 1 : length(F(front).f)
       <span class="keyword">if</span> ~isempty(individual(F(front).f(i)).p)
        	<span class="keyword">for</span> j = 1 : length(individual(F(front).f(i)).p)
            	individual(individual(F(front).f(i)).p(j)).n = <span class="keyword">...</span>
                	individual(individual(F(front).f(i)).p(j)).n - 1;
        	   	<span class="keyword">if</span> individual(individual(F(front).f(i)).p(j)).n == 0
               		x(individual(F(front).f(i)).p(j),M + V + 1) = <span class="keyword">...</span>
                        front + 1;
                    Q = [Q individual(F(front).f(i)).p(j)];
                <span class="keyword">end</span>
            <span class="keyword">end</span>
       <span class="keyword">end</span>
   <span class="keyword">end</span>
   front =  front + 1;
   F(front).f = Q;
<span class="keyword">end</span>
[temp,index_of_fronts] = sort(x(:,M + V + 1));
<span class="keyword">for</span> i = 1 : length(index_of_fronts)
    sorted_based_on_front(i,:) = x(index_of_fronts(i),:);
<span class="keyword">end</span>
current_index = 0;
<span class="comment">% Find the crowding distance for each individual in each front</span>
<span class="keyword">for</span> front = 1 : (length(F) - 1)
    objective = [];
    distance = 0;
    y = [];
    previous_index = current_index + 1;
    <span class="keyword">for</span> i = 1 : length(F(front).f)
        y(i,:) = sorted_based_on_front(current_index + i,:);
    <span class="keyword">end</span>
    current_index = current_index + i;
    <span class="comment">% Sort each individual based on the objective</span>
    sorted_based_on_objective = [];
    <span class="keyword">for</span> i = 1 : M
        [sorted_based_on_objective, index_of_objectives] = <span class="keyword">...</span>
            sort(y(:,V + i));
        sorted_based_on_objective = [];
        <span class="keyword">for</span> j = 1 : length(index_of_objectives)
            sorted_based_on_objective(j,:) = y(index_of_objectives(j),:);
        <span class="keyword">end</span>
        f_max = <span class="keyword">...</span>
            sorted_based_on_objective(length(index_of_objectives), V + i);
        f_min = sorted_based_on_objective(1, V + i);
        y(index_of_objectives(length(index_of_objectives)),M + V + 1 + i)<span class="keyword">...</span>
            = Inf;
        y(index_of_objectives(1),M + V + 1 + i) = Inf;
         <span class="keyword">for</span> j = 2 : length(index_of_objectives) - 1
            next_obj  = sorted_based_on_objective(j + 1,V + i);
            previous_obj  = sorted_based_on_objective(j - 1,V + i);
            <span class="keyword">if</span> (f_max - f_min == 0)
                y(index_of_objectives(j),M + V + 1 + i) = Inf;
            <span class="keyword">else</span>
                y(index_of_objectives(j),M + V + 1 + i) = <span class="keyword">...</span>
                     (next_obj - previous_obj)/(f_max - f_min);
            <span class="keyword">end</span>
         <span class="keyword">end</span>
    <span class="keyword">end</span>
    distance = [];
    distance(:,1) = zeros(length(F(front).f),1);
    <span class="keyword">for</span> i = 1 : M
        distance(:,1) = distance(:,1) + y(:,M + V + 1 + i);
    <span class="keyword">end</span>
    y(:,M + V + 2) = distance;
    y = y(:,1 : M + V + 2);
    z(previous_index:current_index,:) = y;
<span class="keyword">end</span>
f = z();
</pre><p class="footer"><br>
         Published with MATLAB&reg; 7.0<br></p>
      <!--
##### SOURCE BEGIN #####
%% Non-Donimation Sort
% This function sort the current popultion based on non-domination. All the
% individuals in the first front are given a rank of 1, the second front
% individuals are assigned rank 2 and so
...
...
(Please download the complete source code to view)
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 1

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
MOEA-NSGA-II0.00 B05-06-13|16:57
crowding_distance.m1.24 kB07-03-06|16:14
evaluate_objective.m970.00 B13-11-05|23:37
genetic_operator.m3.43 kB07-03-06|16:11
html0.00 B19-03-13|08:15
crowding_distance.html5.01 kB07-03-06|16:14
genetic_operator.html10.05 kB07-03-06|16:11
initialize_variables.html4.33 kB07-03-06|16:08
non_domination_sort_mod.html11.44 kB07-03-06|16:01
nsga_2.html13.43 kB07-03-06|15:59
replace_chromosome.html6.20 kB07-03-06|16:05
tournament_selection.html6.04 kB07-03-06|16:13
initialize_variables.m966.00 B07-03-06|16:08
non_domination_sort_mod.m4.02 kB07-03-06|16:01
nsga_2.m4.56 kB07-03-06|16:48
NSGA_2.pdf364.92 kB07-03-06|16:46
plot_objective.m476.00 B13-11-05|13:51
replace_chromosome.m1.93 kB07-03-06|16:05
solution.txt31.64 kB18-03-13|21:13
tournament_selection.m1.70 kB07-03-06|16:13
...
Sponsored links

non_domination_sort_mod.html (368.17 kB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D