Guest User

Untitled

a guest
May 20th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 KB | None | 0 0
  1.         private Genome RouletteSelection()
  2.         {
  3.             List<Genome> _sexRightsWheel = new List<Genome>();
  4.             Int32 slots = _thisGeneration.Count - _sexRightsWheel.Count;
  5.             Int32 usedSlots = 0;
  6.  
  7.             foreach (Genome genome in _thisGeneration)
  8.             {
  9.                 Int32 allocationAmount = Math.Min(slots - usedSlots, (Int32)Math.Ceiling(genome.Fitness/_totalFitness));
  10.                 usedSlots += allocationAmount;
  11.                 if (slots - usedSlots <= 0) break;
  12.                 else
  13.                 {
  14.                     while (allocationAmount != 0)
  15.                     {
  16.                         _sexRightsWheel.Add(genome);
  17.                         allocationAmount--;
  18.                     }
  19.                 }
  20.             }
  21.  
  22.             return (Genome)_sexRightsWheel[_random.Next(0, 99)];
  23.         }
Add Comment
Please, Sign In to add comment