Esempio n. 1
0
 /// <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));
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Crossover all pairs of genomes
        /// </summary>
        /// <param name="parentGenomes"></param>
        /// <returns></returns>
        private List <Genome> GetCrossOverGenomes(List <Genome> parentGenomes, int requiredChildren)
        {
            List <Genome> offspring = new List <Genome>();

            while (offspring.Count < requiredChildren)
            {
                Genome parent1 = parentGenomes[StaticUtils.Random.Next(parentGenomes.Count - 1)];
                Genome parent2 = parentGenomes[StaticUtils.Random.Next(parentGenomes.Count - 1)];
                offspring.Add(CrossOver.CrossOverGenomes(parent1, parent2, OriginPosition));
            }
            return(offspring);
        }
Esempio n. 3
0
 /// <summary>
 /// Create new algorithm instance and initial population
 /// </summary>
 /// <param name="numberOfGenomes"></param>
 /// <param name="iterationsPerGeneration"></param>
 /// <param name="originPosition"></param>
 /// <param name="destinationPosition"></param>
 public GeneticAlgorithm(int numberOfGenomes, int iterationsPerGeneration, Coordinate originPosition, Coordinate destinationPosition, float mutationStrength, CrossOver.CrossOverType crossOverType) //fitness threshold? percentage of fit individuals?
 {
     NumberOfGenomes            = numberOfGenomes;
     OriginPosition             = originPosition;
     InitialDestinationPosition = new Coordinate(destinationPosition);
     DestinationPosition        = destinationPosition;
     MutationStrength           = mutationStrength;
     IterationsPerGeneration    = iterationsPerGeneration;
     CrossOver = CrossOver.GetCrossOver(crossOverType);
     BeginNewPopulation();
     //add mutation strength?
 }