/// <summary> /// Create an initial population. /// </summary> /// <param name="rnd">Random number generator.</param> /// <param name="codec">The codec, the type of network to use.</param> /// <returns>The population.</returns> public static IPopulation InitPopulation(IGenerateRandom rnd, RBFNetworkGenomeCODEC codec) { // Create a RBF network to get the length. var network = new RBFNetwork(codec.InputCount, codec.RbfCount, codec.OutputCount); int size = network.LongTermMemory.Length; // Create a new population, use a single species. IPopulation result = new BasicPopulation(PopulationSize, new DoubleArrayGenomeFactory(size)); var defaultSpecies = new BasicSpecies {Population = result}; result.Species.Add(defaultSpecies); // Create a new population of random networks. for (int i = 0; i < PopulationSize; i++) { var genome = new DoubleArrayGenome(size); network.Reset(rnd); Array.Copy(network.LongTermMemory, 0, genome.Data, 0, size); defaultSpecies.Add(genome); } // Set the genome factory to use the double array genome. result.GenomeFactory = new DoubleArrayGenomeFactory(size); return result; }
/** * Create the initial random population. * * @return The population. */ private IPopulation InitPopulation() { IPopulation result = new BasicPopulation(PlantUniverse.PopulationSize, null); BasicSpecies defaultSpecies = new BasicSpecies(); defaultSpecies.Population = result; for (int i = 0; i < PlantUniverse.PopulationSize; i++) { DoubleArrayGenome genome = RandomGenome(); defaultSpecies.Add(genome); } result.GenomeFactory = new DoubleArrayGenomeFactory(PlantUniverse.GenomeSize); result.Species.Add(defaultSpecies); return result; }
/// <summary> /// Create an initial random population of random paths through the cities. /// </summary> /// <param name="rnd">The random population.</param> /// <returns>The population</returns> private IPopulation InitPopulation(IGenerateRandom rnd) { IPopulation result = new BasicPopulation(PopulationSize, null); var defaultSpecies = new BasicSpecies(); defaultSpecies.Population = result; for (int i = 0; i < PopulationSize; i++) { IntegerArrayGenome genome = RandomGenome(rnd); defaultSpecies.Add(genome); } result.GenomeFactory = new IntegerArrayGenomeFactory(_cities.Length); result.Species.Add(defaultSpecies); return result; }
/// <summary> /// Create an initial random population. /// </summary> /// <param name="rnd">A random number generator.</param> /// <param name="eval">The expression evaluator.</param> /// <returns>The new population.</returns> private IPopulation InitPopulation(IGenerateRandom rnd, EvaluateExpression eval) { IPopulation result = new BasicPopulation(PopulationSize, null); var defaultSpecies = new BasicSpecies(); defaultSpecies.Population = result; for (int i = 0; i < PopulationSize; i++) { TreeGenome genome = RandomGenome(rnd, eval); defaultSpecies.Add(genome); } result.GenomeFactory = new TreeGenomeFactory(eval); result.Species.Add(defaultSpecies); return result; }