コード例 #1
0
        public GeneticAlgorithm(double crossoverRate, double mutationRate, double elitism, double truncation, double chromosomeCount, ISelection selection, ICrossover crossover, IMutation mutation, FitnessCalculator fitnessCalculator)
        {
            CrossoverRate = crossoverRate;
            MutationRate = mutationRate;
            ElitismRate = elitism;
            TruncationRate = truncation;
            ChromosomeCount = chromosomeCount;

            this.selection = selection;
            this.mutation = mutation;
            this.crossover = crossover;

            this.fitnessCalculator = fitnessCalculator;

            random = new Random();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: dreasgrech/HATETRIS-GA
        static bool HandleCommandLineArgs(Game game, IEnumerable<string> args)
        {
            string fitnessType = "", crossoverType = "";
            bool status = true;
            options = new OptionSet
                          {
                              {"m|mutation=", "The mutation rate (0-1)", (double v) => mutationRate = v},
                              {"s|crossover=", "The crossover rate (0-1)", (double v) => crossoverRate = v},
                              {"e|elitism=", "The elitism rate (0-1)", (double v) => elitismRate = v},
                              {"c|crcount=", "The number of chromosomes per population (>1)", (int v) => chromosomeCount = v},
                              {"fitness=", "The fitness calculator [sum | levenshtein | hamming]", v => fitnessType = v},
                              {"ctype=", "The crossover type [one | two ]", v => crossoverType = v},
                              {"t|truncate=", "The rate of the chromosomes to keep from a population before advancing (0 < t <= 1)", (double v) => truncationRate = v},
                              {"?|h|help", "Show help", v => { status = false; }},
                              //{"<>", v => target = v} // this can be used for a seed
                          };
            try
            {
                options.Parse(args);
            }
            catch (OptionException ex)
            {
                status = false;
            }

            fitness = (FitnessCalculator)Activator.CreateInstance(GetOperationType(fitnessTypes, fitnessType), new object[] { game });
            crossover = (ICrossover)Activator.CreateInstance(GetOperationType(crossoverTypes, crossoverType), new object[] { fitness });
            mutation = new SinglePointMutation(new ReplayCharacterSet(), fitness);
            selection = new RouletteWheelSelection();

            if (mutationRate > 1 || crossoverRate > 1 || elitismRate > 1 || chromosomeCount <= 1 || truncationRate <= 0 || truncationRate > 1)
            {
                status = false;
            }

            return status;
        }
コード例 #3
0
 public OnePointCrossover(FitnessCalculator fitnessCalculator)
 {
     this.fitnessCalculator = fitnessCalculator;
     random = new Random();
 }
コード例 #4
0
ファイル: Chromosome.cs プロジェクト: dreasgrech/HATETRIS-GA
 public Chromosome(Replay replay, FitnessCalculator fitnessCalculator)
 {
     Replay = replay;
     Fitness = fitnessCalculator.CalculateFitness(this);
 }
コード例 #5
0
 public SinglePointMutation(CharacterSet characterSet, FitnessCalculator fitnessCalculator)
 {
     this.fitnessCalculator = fitnessCalculator;
     random = new Random();
     this.characterSet = characterSet;
 }