예제 #1
0
        public static void Main(string[] args)
        {
            _ads = SetupAppDomain();


            const double crossoverProbability = 0.65;
            const double mutationProbability  = 0.08;
            const int    elitismPercentage    = 5;

            //create the population
            //var population = new Population(100, 44, false, false);

            var population = new Population();

            //create the chromosomes
            for (var p = 0; p < 10; p++)
            {
                var chromosome = new Chromosome();
                for (int i = 0; i < 2; i++)
                {
                    ConfigVars v = new ConfigVars();
                    v.vars ["EMA_VAR1"] = RandomNumberBetweenInt(0, 20);
                    v.vars ["EMA_VAR2"] = RandomNumberBetweenInt(0, 100);
                    //v.vars ["LTD3"] = RandomNumberBetweenInt (0, 100);
                    //v.vars ["LTD4"] = RandomNumberBetweenInt (2, 200);

                    chromosome.Genes.Add(new Gene(v));
                }
                chromosome.Genes.ShuffleFast();
                population.Solutions.Add(chromosome);
            }



            //create the genetic operators
            var elite = new Elite(elitismPercentage);

            var crossover = new Crossover(crossoverProbability, true)
            {
                CrossoverType = CrossoverType.SinglePoint
            };

            var mutation = new BinaryMutate(mutationProbability, true);

            //create the GA itself
            var ga = new GeneticAlgorithm(population, CalculateFitness);

            //subscribe to the GAs Generation Complete event
            ga.OnGenerationComplete += ga_OnGenerationComplete;

            //add the operators to the ga process pipeline
//			ga.Operators.Add(elite);
//			ga.Operators.Add(crossover);
//			ga.Operators.Add(mutation);

            var cv_operator = new ConfigVarsOperator();

            ga.Operators.Add(cv_operator);

            //run the GA
            ga.Run(Terminate);
        }
예제 #2
0
        public static void Main(string[] args)
        {
            _ads = SetupAppDomain ();

            const double crossoverProbability = 0.65;
            const double mutationProbability = 0.08;
            const int elitismPercentage = 5;

            //create the population
            //var population = new Population(100, 44, false, false);

            var population = new Population();

            //create the chromosomes
            for (var p = 0; p < 10; p++)
            {

                var chromosome = new Chromosome();
                for (int i = 0; i < 2; i++) {
                    ConfigVars v = new ConfigVars ();
                    v.vars ["EMA_VAR1"] = RandomNumberBetweenInt (0, 20);
                    v.vars ["EMA_VAR2"] = RandomNumberBetweenInt (0, 100);
                    //v.vars ["LTD3"] = RandomNumberBetweenInt (0, 100);
                    //v.vars ["LTD4"] = RandomNumberBetweenInt (2, 200);

                    chromosome.Genes.Add (new Gene (v));
                }
                chromosome.Genes.ShuffleFast();
                population.Solutions.Add(chromosome);
            }

            //create the genetic operators
            var elite = new Elite(elitismPercentage);

            var crossover = new Crossover(crossoverProbability, true)
            {
                CrossoverType = CrossoverType.SinglePoint
            };

            var mutation = new BinaryMutate(mutationProbability, true);

            //create the GA itself
            var ga = new GeneticAlgorithm(population, CalculateFitness);

            //subscribe to the GAs Generation Complete event
            ga.OnGenerationComplete += ga_OnGenerationComplete;

            //add the operators to the ga process pipeline
            //			ga.Operators.Add(elite);
            //			ga.Operators.Add(crossover);
            //			ga.Operators.Add(mutation);

            var cv_operator = new ConfigVarsOperator ();
            ga.Operators.Add (cv_operator);

            //run the GA
            ga.Run(Terminate);
        }