Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private Genome RouletteSelection()
- {
- List<Genome> _sexRightsWheel = new List<Genome>();
- Int32 slots = _thisGeneration.Count - _sexRightsWheel.Count;
- Int32 usedSlots = 0;
- foreach (Genome genome in _thisGeneration)
- {
- Int32 allocationAmount = Math.Min(slots - usedSlots, (Int32)Math.Ceiling(genome.Fitness/_totalFitness));
- usedSlots += allocationAmount;
- if (slots - usedSlots <= 0) break;
- else
- {
- while (allocationAmount != 0)
- {
- _sexRightsWheel.Add(genome);
- allocationAmount--;
- }
- }
- }
- return (Genome)_sexRightsWheel[_random.Next(0, 99)];
- }
Add Comment
Please, Sign In to add comment