Beispiel #1
0
        static void Main(string[] args)
        {
            Random random = new Random();

            Reader        reader   = new Reader();
            List <double> pregList = reader.GetPregnantData();

            allSeeds = reader.GetAllUserData();

            int    min     = -1;
            int    max     = 1;
            double mR      = 0.08;
            double cR      = 0.6;
            bool   elitism = true;
            int    populationSeedListSize = 50;
            int    seedDataSize           = 20;

            // Generate list of seeds and add them to a populations
            SeedGenerator seedGenerator = new SeedGenerator();
            List <Seed>   seeds         = seedGenerator.CreateListOfSeeds(populationSeedListSize, seedDataSize, random, max, min);
            Population    population    = new Population(seeds);

            IFitness fitness = new FitnessSSE();

            fitness.Fitness(allSeeds, pregList);
            ICrossover crossover = new SinglePointCrossover();

            crossover.Crossover(cR);

            ISelection selection = new Roulette();
            Mutation   mutation  = new Mutation(mR, max, min);
            Elitisme   elitisme  = new Elitisme();

            Genetic genetic = new Genetic(population, selection, crossover, fitness, elitisme, mutation, elitism);

            int iterations = 500;

            for (int i = 0; i < iterations; i++)
            {
                genetic.Run();
            }

            genetic.IsPregnent(elitisme.BestSeed, 8, allSeeds);

            Console.ReadLine();
        }
        public Genetic(Population _population, ISelection _selection, ICrossover _crossover, IFitness _fitness, Elitisme _elitisme, Mutation _mutation, bool _elit)
        {
            selection  = _selection;
            crossover  = _crossover;
            mutation   = _mutation;
            population = _population;
            fitness    = _fitness;
            elitisme   = _elitisme;
            elit       = _elit;

            fitness.Calculate(population.Seeds);
        }