Logo Search packages:      
Sourcecode: gaffitter version File versions  Download package

void GeneticAlgorithm::DirectedMutation ( Genome g  )  const [protected]

Select at random a gene and then change it to better fit the target.

If 'g' is feasible then change the gene to '0', otherwise try change the gene to '1'.

Definition at line 282 of file GeneticAlgorithm.cc.

References Genome::AddSize(), Genome::Diff(), Genome::Gene(), Random::Int(), Genome::Length(), Optimizer::m_files, and Genome::OverTarget().

Referenced by Generation().

{
   int r = Random::Int(0, g.Length()-1);

   if (g.OverTarget())
   {
      if (!g.Gene(r))
      {
         if (r<=g.Length()/2)  
            while (++r < g.Length() && !g.Gene(r)); 
         else 
            while (--r >= 0 && !g.Gene(r));

         if (r>=0 && r<g.Length())
         {
            g.Gene(r, false);
            g.Diff(g.Diff() + m_files[r].Size());
         }
      }
      else // equal 'true'
      {
         g.Gene(r, false);
         g.Diff(g.Diff() + m_files[r].Size());
      }
   }
   else
   {
      if (g.Gene(r))
      {
         if (r<=g.Length()/2)  
            while (++r < g.Length() && g.Gene(r)); 
         else 
            while (--r >= 0 && g.Gene(r));

         if (r>=0 && r<g.Length())
         {
            g.AddSize(r, m_files[r].Size());
         }
      }
      else // equal 'false'
      {
         g.AddSize(r, m_files[r].Size());
      }
   }
}


Generated by  Doxygen 1.6.0   Back to index