Exemple #1
0
        static void Main(string[] args)
        {
            FileReader            fileReader       = new FileReader();
            List <double>         pregnantOutcomes = fileReader.ReadPregData();
            List <List <double> > population       = fileReader.ReadData();

            int    populationAmount  = 60;
            int    coefficientAmount = 19;
            int    min        = -1;
            int    max        = 1;
            double mR         = 0.01;
            double cR         = 0.9;
            bool   preserve   = true;
            int    iterations = 500;

            SeedGenerator    seedGenerator    = new SeedGenerator(populationAmount, coefficientAmount, min, max);
            FitnessEvaluator fitnessEvaluator = new FitnessEvaluator(population, pregnantOutcomes);
            ISelection       roulette         = new Roulette();
            ICrossover       crossover        = new TwoPointCrossover(cR);
            IMutation        mutation         = new Mutation(mR, min, max);
            Elitism          elitism          = new Elitism(preserve);
            GeneticAlgorithm geneticAlgorithm = new GeneticAlgorithm(seedGenerator, fitnessEvaluator, roulette, crossover, mutation, elitism);

            geneticAlgorithm.Run(populationAmount, iterations);
        }
Exemple #2
0
 public GeneticAlgorithm(SeedGenerator seedGenerator, FitnessEvaluator fitnessEvaluator, ISelection selection, ICrossover crossover, IMutation mutation, IElitism elitism)
 {
     this.seedGenerator    = seedGenerator;
     this.fitnessEvaluator = fitnessEvaluator;
     this.selection        = selection;
     this.crossover        = crossover;
     this.mutation         = mutation;
     this.elitism          = elitism;
 }