private void GenerateRandomPopulation(BasicGA <T> ga) { int popSize, attemptNum; bool allowDuplicates; List <string> unique; Genotype member; popSize = ga.PopulationSize; allowDuplicates = ga.AllowInitializationDuplicates; unique = new List <string>(popSize); attemptNum = 0; while (Members.Count < popSize) { member = ga.GenerateRandomMember(); if (!allowDuplicates && unique.Contains(member.ToString())) { if (++attemptNum > MAX_RETRY_ATTEMPTS) { throw new Exception("Reached the maximum number of retry attempts to generate a unique random population member"); } else { continue; } } unique.Add(member.ToString()); Members.Add(member); attemptNum = 0; } }
public Population(BasicGA /*<T>*/ ga) { GenerateRandomPopulation(ga); }