예제 #1
0
		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");
			}
		}
예제 #2
0
		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");
				}
			}
		}
예제 #3
0
		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;
		}
예제 #4
0
		public Organism FindBestOrganismInPopulation( Population p)
		{
			if ( p.IsEmpty )
			{
				throw new GeneticError("Is empty");
			}

			Organism best_organism = p[ 0 ];
			return best_organism;
		}
예제 #5
0
		public Generation(int id)
		{
			this.population = null;
			this.ID = id;
			this.create_date = System.DateTime.Now;
		}