Exemplo n.º 1
0
        public static void RunExampleOnce()
        {
            List <Person>       population        = new List <Person>();
            List <double>       coefficient       = new List <double>();
            List <CoupleParent> coupleParents     = new List <CoupleParent>();
            List <string>       crossoverChildren = new List <string>();

            FileReader.CoefficientRead(coefficient);
            FileReader.ReadFile(population, 5);
            Fitness.CalculateSSE(population);
            Fitness.CalculateCoefSSE(coefficient, population);

            //Stap 1 t/m 5
            RouletteWheel.DoCalculation(population);

            //Crossover Methods
            //SinglePointCrossover.DoCrossover(coupleParents, crossoverChildren);
            TwoPointCrossover.DoCrossover(coupleParents, crossoverChildren, crossOverPercentage, population);

            //Mutation
            Mutation.MutationChildren(crossoverChildren);

            //Recalculate Fitness for Childrens
            List <Person> childrenPopulation = Fitness.CalculateCoefSSEChild(coefficient, crossoverChildren);

            //Elitism best solution
            var bestPerson = Elitism.ChildHighestFit(childrenPopulation, crossOverPercentage);

            Console.ReadKey();
        }
Exemplo n.º 2
0
 public static void RunGeneticAlgorithm()
 {
     for (int i = 0; i < iterations; i++)
     {
         List <Person> population        = new List <Person>();
         List <double> coefficient       = new List <double>();
         List <string> crossoverChildren = new List <string>();
         FileReader.CoefficientRead(coefficient);
         FileReader.ReadFile(population, populationAmount);
         List <CoupleParent> coupleParents = new List <CoupleParent>();
         Fitness.CalculateSSE(population);
         Fitness.CalculateCoefSSE(coefficient, population);
         RouletteWheel.DoCalculation(population);
         RunCrossOver(coupleParents, crossoverChildren, population);
         Mutation.MutationChildren(crossoverChildren);
         //Recalculate Fitness for Childrens
         List <Person> childrenPopulation = Fitness.CalculateCoefSSEChild(coefficient, crossoverChildren);
         //Elitism best solution
         RunElitism(i, childrenPopulation);
     }
 }