/// <summary> /// Create a population with random genomes. /// </summary> private void Populate() { for (int i = 0; i < GenomeCount; i++) { Genomes.Add(new Genome(InputCount, OutputCount, Config.weightInitRandomValue)); } }
//constructor public Population(int size, int inputDims) { _inputDims = inputDims; AddedConnections = new Dictionary <string, int>(); for (int i = 0; i < size; i++) { Genomes.Add(new Genome(inputDims)); } }
public MasterMindPopulation(int numberOfGenomes) { Genomes.Clear(); for (int i = 0; i < numberOfGenomes; i++) { MastermindGenome aGenome = new MastermindGenome(kLength, 1, 9); aGenome.SetCrossoverPoint(kCrossover); aGenome.CalculateFitness(); Genomes.Add(aGenome); } }
/// <summary> /// Create a population of a set number of genes, with a crossover type, and the ideal path ends /// </summary> /// <param name="numberOfGenomes"></param> /// <param name="crossOver"></param> /// <param name="originPosition"></param> /// <param name="destinationPosition"></param> public Population(int numberOfGenomes, CrossOver crossOver, Coordinate originPosition, Coordinate destinationPosition, float mutationStrength) { NumberOfGenomes = numberOfGenomes; CrossOver = crossOver; OriginPosition = originPosition; DestinationPosition = destinationPosition; MutationStrength = (int)(mutationStrength * 100); for (int i = 0; i < NumberOfGenomes; i++) { Genomes.Add(new Genome(OriginPosition)); } }
private void CreateStartPopulation(int genomes, int numChromosoneBits, int numGeneBits) { //clear existing population Genomes.Clear(); for (int i = 0; i < genomes; i++) { var genome = new TGenome(); genome.Initialize(numChromosoneBits, numGeneBits); Genomes.Add(genome); } //reset all variables Generation = 0; TotalFitnessScore = 0; }
private void CreateStartPopulation(int genomes, Action <TGenome> genomeCreationMethod) { //clear existing population Genomes.Clear(); for (int i = 0; i < genomes; i++) { var genome = new TGenome(); genomeCreationMethod(genome); Genomes.Add(genome); } //reset all variables Generation = 0; TotalFitnessScore = 0; GeneLength = -1; ChromosoneLength = Genomes.First().Genes.Sum(g => g.Length); }
public void CreateStartPopulation() { // clear existing population Genomes.Clear(); //Parallel.For(0, _settings.PopulationSize, (i) => for (int i = 0; i < _settings.PopulationSize; i++) { var genome = new Genome <TMainModel, TCombinationModel>(_settings); // Make sure all genomes are initially different int initPasses = 0; do { genome.Initialize(); initPasses++; lock (Genomes) { if (!Genomes.AsParallel().Any(g => g.GetUniqueGenesString().Equals(genome.GetUniqueGenesString()))) { break; // we are all good } if (initPasses > 10) { throw new InvalidOperationException("No more combinations possible, reduce population size!"); } } } while (true); lock (Genomes) { Genomes.Add(genome); } //Debug.WriteLineIf(initPasses>1, $"# Re-initialized because of duplicate genome ({initPasses})"); } ; //reset all variables Generation = 0; TotalFitnessScore = 0; }
/// <summary> /// Add Genome to Species and Update it's ID /// </summary> public void Add(Genome genome) { Genomes.Add(genome); genome.SpeciesID = this.ID; }