title: Selection operator and minimizing the fitness function in Genetic Algorithms
body: <p>I'm developing a nurse rostering tool im matlab using genetic algorithms, without using GA toolbox.<br>
  The individual is a weekly schedule and is represented as a 2-d array with rows equals to the number of nurses and seven columns because it is a weekly schedule.<br>
  The fitness function takes the entire population and returns an array with size equal to the population size containing fitness values.  </p>
  
  <p>The fitness function should be minimized so the best schedule is the one having the lowest fitness value.
  My fitness function is:</p>
  
  <pre><code>function fitness_values =Fitness_Function( thePopulation)
  %UNTITLED Summary of this function goes here
  %   Detailed explanation goes here
  [Ar1 Ar2 popsize num_nur]  = Return_Data( 0,0,0,0 );
  [prev_sched OffArr]=Return_Data1(0,0);
  constraints=cell(popsize,1);
  fitness_values=zeros(popsize,1); 
  size=[1 7];
  c1=zeros(popsize,1);
  c1values=cell(popsize,1);
  W1=0.25; %hard
  W2=0.25; %hard
  W3=0.25; %hard
  W4=0.125; %soft
  W5=0.125; %soft
  
  for i=1: popsize
  c1values{i}=zeros(size);
  end
  % Checking Constraint c1 (the difference between night and day shifts in
  % each day of the schedule 
  for i=1:popsize
  for j=1:7
  day_sum=0;
  night_sum=0;
      for k=1:num_nur
        if thePopulation{i}(k,j)==1
            day_sum=day_sum+1;
        elseif thePopulation{i}(k,j)==2
            night_sum=night_sum+1;
        end
      end 
      abs_diff=abs(day_sum-night_sum);
      c1values{i}(1,j)=abs_diff.^2;
  end
  c1(i)=sum(c1values{i}(1,:));
  
  
  %celldisp(c1values);
  %defining the array that will hold the result of multiplying the number of
  %violations with the correspondig weight,a cell array where each cell
  %containts num_nur rows and 4 columns for c2, c3,c4 and c5.
  
  nurse_fitness=zeros(num_nur,1);
  for in=1:popsize
  constraints{in}=zeros(num_nur,4);
  end
  
  for j=1:num_nur
        v2=0;
        v3=0;
        v4=0;
        %check violations with the previous schedule(the last day of the
        %previous schedule with the first day of the evaluated schedule
        % c2
        if prev_sched(j,7)==2 &amp;&amp; thePopulation{i}(j,1)==1
            v2=v2+1;
        end
        % c3
        %check the last day of the previous schedule
         if prev_sched(j,7)==1 &amp;&amp; thePopulation{i}(j,1)==1 &amp;&amp; thePopulation{i}(j,2)~=3
                v3=v3+1;
         %check the last 2 days of the previous schedule       
         elseif prev_sched(j,6)==1 &amp;&amp;prev_sched(j,7)==1 &amp;&amp; thePopulation{i}(j,2)~=3
                v3=v3+1;
         end
         %c4
         %check the last day of the previous schedule
         if prev_sched(j,7)==2 &amp;&amp; thePopulation{i}(j,1)==3 &amp;&amp;thePopulation{i}(j,2)==1
                v4=v4+1;
         %check the last 2 days of the previous schedule       
         elseif prev_sched(j,6)==2 &amp;&amp;prev_sched(j,7)==3 &amp;&amp; thePopulation{i}(j,2)==1
                v4=v4+1;
         end
         %check violations of constraints c2,c3 and c4 in the
         %evaluated schedule
         for k=1:6 
         %check violations of c2 N-&gt;N or N-&gt;O (hard)
         if thePopulation{i}(j,k)==2 &amp;&amp;  thePopulation{i}(j,k+1)==1 
            v2=v2+1;
         end
         end
         %check violations of c3 D-&gt;D-&gt;O     (hard)
        for k=1:5
            if thePopulation{i}(j,k)==1 &amp;&amp; thePopulation{i}(j,k+1)==1 &amp;&amp; thePopulation{i}(j,k+2)~=3
                v3=v3+1;
            end
         %check violations of c4 N-&gt;O-&gt;N or N-&gt;O-&gt;O (soft)
            if thePopulation{i}(j,k)==2 &amp;&amp; thePopulation{i}(j,k+1)==3 &amp;&amp; thePopulation{i}(j,k+2)==1
                v4=v4+1;
            end
        end
        constraints{i}(j,1)=v2*W2;
        constraints{i}(j,2)=v3*W3;
        constraints{i}(j,3)=v4*W4;
        %check violations of c5 (perefrences of each nurse)
        offdays=find(thePopulation{i}(j,:)==3);
        %disp(offdays);
        %disp(OffArr(j,:));
        %find intersection between the perefreces and the days off in the
        %schedule of each nurse
        inters=intersect(offdays,OffArr(j,:));
        num_inters=length(inters);
        if(length(offdays)==1)
        %for head nurse
        if num_inters==1
        constraints{i}(j,4)=0;
        else
        constraints{i}(j,4)=3*W5;
        end
        else
        penalty=3-num_inters;
        constraints{i}(j,4)=penalty*W5;
        end
        nurse_fitness(j)=sum(constraints{i}(j,:));
     end 
    %calculating the fitness value for the whole schedule 
  
    fitness_values(i)=W1*c1(i)+sum(nurse_fitness);
     end
    end
  </code></pre>
  
  <p>I'll summarize how it works: it takes a cell array (the population) each cell contains a schedule represented as matrix having rows =number of nurses and 7 columns (weekly schedule),,the problem has 3 hard constraints and 2 soft constraints, so the fitness will check the violation of these constraints in each schedule,,the violation is penalized by multiplying the number of violations in each nurse with the corresponding  wheight of the constraint so the final fitness value is the sum of penalty values of each nurse. finally the fitness value of the the evaluated schedule is saved in an array of fitness values (the same index where the evaluated scheule is stored in the population array).</p>
  
  <p>My question is what is the suitable selection operator to select parents for crossover and mutation operators?</p>