예제 #1
0
        private AlpsGeneticAlgorithm CreateAlpsGaSymRegSample()
        {
            AlpsGeneticAlgorithm alpsGa = new AlpsGeneticAlgorithm();

            #region Problem Configuration
            var provider       = new VladislavlevaInstanceProvider();
            var instance       = provider.GetDataDescriptors().Single(x => x.Name.StartsWith("Vladislavleva-5 F5"));
            var symbRegProblem = new SymbolicRegressionSingleObjectiveProblem();
            symbRegProblem.Load(provider.LoadData(instance));

            symbRegProblem.MaximumSymbolicExpressionTreeDepth.Value  = 35;
            symbRegProblem.MaximumSymbolicExpressionTreeLength.Value = 35;

            var grammar = (TypeCoherentExpressionGrammar)symbRegProblem.SymbolicExpressionTreeGrammar;
            grammar.Symbols.OfType <Exponential>().Single().Enabled = false;
            grammar.Symbols.OfType <Logarithm>().Single().Enabled   = false;

            #endregion
            #region Algorithm Configuration
            alpsGa.Name        = "ALPS Genetic Programming - Symbolic Regression";
            alpsGa.Description = "An ALPS-GP to solve a symbolic regression problem (Vladislavleva-5 dataset)";
            alpsGa.Problem     = symbRegProblem;
            SamplesUtils.ConfigureAlpsGeneticAlgorithmParameters <GeneralizedRankSelector, SubtreeCrossover, MultiSymbolicExpressionTreeManipulator>(alpsGa,
                                                                                                                                                     numberOfLayers: 1000,
                                                                                                                                                     popSize: 100,
                                                                                                                                                     mutationRate: 0.25,
                                                                                                                                                     elites: 1,
                                                                                                                                                     plusSelection: false,
                                                                                                                                                     agingScheme: AgingScheme.Polynomial,
                                                                                                                                                     ageGap: 15,
                                                                                                                                                     ageInheritance: 1.0,
                                                                                                                                                     maxGens: 500);
            #endregion
            return(alpsGa);
        }
예제 #2
0
        private AlpsGeneticAlgorithm CreateAlpsGaTspSample()
        {
            AlpsGeneticAlgorithm alpsGa = new AlpsGeneticAlgorithm();

            #region Problem Configuration
            var provider = new TSPLIBTSPInstanceProvider();
            var instance = provider.GetDataDescriptors().Single(x => x.Name == "ch130");
            TravelingSalesmanProblem tspProblem = new TravelingSalesmanProblem();
            tspProblem.Load(provider.LoadData(instance));
            tspProblem.UseDistanceMatrix.Value = true;
            #endregion
            #region Algorithm Configuration
            alpsGa.Name        = "ALPS Genetic Algorithm - TSP";
            alpsGa.Description = "An age-layered population structure genetic algorithm which solves the \"ch130\" traveling salesman problem (imported from TSPLIB)";
            alpsGa.Problem     = tspProblem;
            SamplesUtils.ConfigureAlpsGeneticAlgorithmParameters <GeneralizedRankSelector, MultiPermutationCrossover, InversionManipulator>(alpsGa,
                                                                                                                                            numberOfLayers: 1000,
                                                                                                                                            popSize: 100,
                                                                                                                                            mutationRate: 0.05,
                                                                                                                                            elites: 1,
                                                                                                                                            plusSelection: true,
                                                                                                                                            agingScheme: AgingScheme.Polynomial,
                                                                                                                                            ageGap: 20,
                                                                                                                                            ageInheritance: 1.0,
                                                                                                                                            maxGens: 1000);
            var checkedCrossovers = new[] { typeof(EdgeRecombinationCrossover), typeof(MaximalPreservativeCrossover), typeof(OrderCrossover2) };
            var multiCrossover    = (MultiPermutationCrossover)alpsGa.Crossover;
            var crossovers        = multiCrossover.Operators.Where(c => checkedCrossovers.Any(cc => cc.IsInstanceOfType(c))).ToList();
            foreach (var c in multiCrossover.Operators)
            {
                multiCrossover.Operators.SetItemCheckedState(c, crossovers.Contains(c));
            }
            #endregion
            return(alpsGa);
        }
예제 #3
0
        public static void ConfigureAlpsGeneticAlgorithmParameters <S, C, M>(AlpsGeneticAlgorithm ga, int numberOfLayers, int popSize, double mutationRate, int elites, bool plusSelection, AgingScheme agingScheme, int ageGap, double ageInheritance, int maxGens)
            where S : ISelector
            where C : ICrossover
            where M : IManipulator
        {
            ga.Seed.Value            = 0;
            ga.SetSeedRandomly.Value = true;

            ga.NumberOfLayers.Value = numberOfLayers;
            ga.PopulationSize.Value = popSize;

            ga.Selector  = ga.SelectorParameter.ValidValues.OfType <S>().Single();
            ga.Crossover = ga.CrossoverParameter.ValidValues.OfType <C>().Single();
            ga.Mutator   = ga.MutatorParameter.ValidValues.OfType <M>().Single();
            ga.MutationProbability.Value = mutationRate;
            ga.Elites.Value  = elites;
            ga.PlusSelection = plusSelection;

            ga.AgingScheme          = new EnumValue <AgingScheme>(agingScheme);
            ga.AgeGap.Value         = ageGap;
            ga.AgeInheritance.Value = ageInheritance;

            ga.MaximumGenerations = maxGens;

            ga.Engine = new ParallelEngine.ParallelEngine();
        }