public void SetupForEvolution(Population the_population, FitnessDirection fd ) { this.direction = fd; this.CurrentGeneration = new Generation(0); this.CurrentGeneration.population = the_population ; if ( this.CurrentGeneration.population.IsEmpty ) { throw new GeneticError("Cannot start with empty population"); } }
public void SortPopulation( Population p, FitnessDirection fd ) { if ( fd==FitnessDirection.Minimize ) { p.Sort( Environment.m_min_comparer ); // Double-check the sort if (p[ 0 ].Fitness >p[ p.Size-1 ].Fitness ) { throw new GeneticError("Sort did not work"); } } else { p.Sort( Environment.m_max_comparer ); // Double-check the sort if (p[ 0 ].Fitness <p[ p.Size-1 ].Fitness ) { throw new GeneticError("Sort did not work"); } } }
Population GetRandomMembersFromPopulation( Population p, int num) { Population organisms = new Population( p.Capacity ); for (int i=0;i<num;i++) { int index = p.GetIndexOfRandomMember( ); Organism p0 = p[ index ]; organisms.AddOrganism( p0 ); } return organisms; }
public Organism FindBestOrganismInPopulation( Population p) { if ( p.IsEmpty ) { throw new GeneticError("Is empty"); } Organism best_organism = p[ 0 ]; return best_organism; }
public Generation(int id) { this.population = null; this.ID = id; this.create_date = System.DateTime.Now; }