public AlpsGeneticAlgorithm() : base() { #region Add parameters Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0))); Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true))); Parameters.Add(new FixedValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze all individuals from all layers combined.", new MultiAnalyzer())); Parameters.Add(new FixedValueParameter<MultiAnalyzer>("LayerAnalyzer", "The operator used to analyze each layer.", new MultiAnalyzer())); Parameters.Add(new ValueParameter<IntValue>("NumberOfLayers", "The number of layers.", new IntValue(10))); Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions in each layer.", new IntValue(100))); Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction.")); Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions.")); Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions.")); Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05))); Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1))); Parameters.Add(new FixedValueParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", new BoolValue(false)) { Hidden = true }); Parameters.Add(new ValueParameter<BoolValue>("PlusSelection", "Include the parents in the selection of the invividuals for the next generation.", new BoolValue(false))); Parameters.Add(new ValueParameter<EnumValue<AgingScheme>>("AgingScheme", "The aging scheme for setting the age-limits for the layers.", new EnumValue<AgingScheme>(ALPS.AgingScheme.Polynomial))); Parameters.Add(new ValueParameter<IntValue>("AgeGap", "The frequency of reseeding the lowest layer and scaling factor for the age-limits for the layers.", new IntValue(20))); Parameters.Add(new ValueParameter<DoubleValue>("AgeInheritance", "A weight that determines the age of a child after crossover based on the older (1.0) and younger (0.0) parent.", new DoubleValue(1.0)) { Hidden = true }); Parameters.Add(new ValueParameter<IntArray>("AgeLimits", "The maximum age an individual is allowed to reach in a certain layer.", new IntArray(new int[0])) { Hidden = true }); Parameters.Add(new ValueParameter<IntValue>("MatingPoolRange", "The range of layers used for creating a mating pool. (1 = current + previous layer)", new IntValue(1)) { Hidden = true }); Parameters.Add(new ValueParameter<BoolValue>("ReduceToPopulationSize", "Reduce the CurrentPopulationSize after elder migration to PopulationSize", new BoolValue(true)) { Hidden = true }); Parameters.Add(new ValueParameter<MultiTerminator>("Terminator", "The termination criteria that defines if the algorithm should continue or stop.", new MultiTerminator())); #endregion #region Create operators var globalRandomCreator = new RandomCreator(); var layer0Creator = new SubScopesCreator() { Name = "Create Layer Zero" }; var layer0Processor = new SubScopesProcessor(); var localRandomCreator = new LocalRandomCreator(); var layerSolutionsCreator = new SolutionsCreator(); var initializeAgeProcessor = new UniformSubScopesProcessor(); var initializeAge = new VariableCreator() { Name = "Initialize Age" }; var initializeCurrentPopulationSize = new SubScopesCounter() { Name = "Initialize CurrentPopulationCounter" }; var initializeLocalEvaluatedSolutions = new Assigner() { Name = "Initialize LayerEvaluatedSolutions" }; var initializeGlobalEvaluatedSolutions = new DataReducer() { Name = "Initialize EvaluatedSolutions" }; var resultsCollector = new ResultsCollector(); var mainLoop = new AlpsGeneticAlgorithmMainLoop(); #endregion #region Create and parameterize operator graph OperatorGraph.InitialOperator = globalRandomCreator; globalRandomCreator.RandomParameter.ActualName = "GlobalRandom"; globalRandomCreator.SeedParameter.Value = null; globalRandomCreator.SeedParameter.ActualName = SeedParameter.Name; globalRandomCreator.SetSeedRandomlyParameter.Value = null; globalRandomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name; globalRandomCreator.Successor = layer0Creator; layer0Creator.NumberOfSubScopesParameter.Value = new IntValue(1); layer0Creator.Successor = layer0Processor; layer0Processor.Operators.Add(localRandomCreator); layer0Processor.Successor = initializeGlobalEvaluatedSolutions; localRandomCreator.Successor = layerSolutionsCreator; layerSolutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name; layerSolutionsCreator.Successor = initializeAgeProcessor; initializeAgeProcessor.Operator = initializeAge; initializeAgeProcessor.Successor = initializeCurrentPopulationSize; initializeCurrentPopulationSize.ValueParameter.ActualName = "CurrentPopulationSize"; initializeCurrentPopulationSize.Successor = initializeLocalEvaluatedSolutions; initializeAge.CollectedValues.Add(new ValueParameter<DoubleValue>("Age", new DoubleValue(0))); initializeAge.Successor = null; initializeLocalEvaluatedSolutions.LeftSideParameter.ActualName = "LayerEvaluatedSolutions"; initializeLocalEvaluatedSolutions.RightSideParameter.ActualName = "CurrentPopulationSize"; initializeLocalEvaluatedSolutions.Successor = null; initializeGlobalEvaluatedSolutions.ReductionOperation.Value.Value = ReductionOperations.Sum; initializeGlobalEvaluatedSolutions.TargetOperation.Value.Value = ReductionOperations.Assign; initializeGlobalEvaluatedSolutions.ParameterToReduce.ActualName = "LayerEvaluatedSolutions"; initializeGlobalEvaluatedSolutions.TargetParameter.ActualName = "EvaluatedSolutions"; initializeGlobalEvaluatedSolutions.Successor = resultsCollector; resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", null, "EvaluatedSolutions")); resultsCollector.Successor = mainLoop; mainLoop.GlobalRandomParameter.ActualName = "GlobalRandom"; mainLoop.LocalRandomParameter.ActualName = localRandomCreator.LocalRandomParameter.Name; mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions"; mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name; mainLoop.LayerAnalyzerParameter.ActualName = LayerAnalyzerParameter.Name; mainLoop.NumberOfLayersParameter.ActualName = NumberOfLayersParameter.Name; mainLoop.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name; mainLoop.CurrentPopulationSizeParameter.ActualName = "CurrentPopulationSize"; mainLoop.SelectorParameter.ActualName = SelectorParameter.Name; mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name; mainLoop.MutatorParameter.ActualName = MutatorParameter.Name; mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name; mainLoop.ElitesParameter.ActualName = ElitesParameter.Name; mainLoop.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name; mainLoop.PlusSelectionParameter.ActualName = PlusSelectionParameter.Name; mainLoop.AgeParameter.ActualName = "Age"; mainLoop.AgeGapParameter.ActualName = AgeGapParameter.Name; mainLoop.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name; mainLoop.AgeLimitsParameter.ActualName = AgeLimitsParameter.Name; mainLoop.MatingPoolRangeParameter.ActualName = MatingPoolRangeParameter.Name; mainLoop.ReduceToPopulationSizeParameter.ActualName = ReduceToPopulationSizeParameter.Name; mainLoop.TerminatorParameter.ActualName = TerminatorParameter.Name; #endregion #region Set selectors foreach (var selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(s => !(s is IMultiObjectiveSelector)).OrderBy(s => Name)) SelectorParameter.ValidValues.Add(selector); var defaultSelector = SelectorParameter.ValidValues.OfType<GeneralizedRankSelector>().FirstOrDefault(); if (defaultSelector != null) { defaultSelector.PressureParameter.Value = new DoubleValue(4.0); SelectorParameter.Value = defaultSelector; } #endregion #region Create analyzers qualityAnalyzer = new BestAverageWorstQualityAnalyzer(); layerQualityAnalyzer = new BestAverageWorstQualityAnalyzer(); ageAnalyzer = new OldestAverageYoungestAgeAnalyzer(); layerAgeAnalyzer = new OldestAverageYoungestAgeAnalyzer(); ageDistributionAnalyzer = new AgeDistributionAnalyzer(); layerAgeDistributionAnalyzer = new AgeDistributionAnalyzer(); #endregion #region Create terminators generationsTerminator = new ComparisonTerminator<IntValue>("Generations", ComparisonType.Less, new IntValue(1000)) { Name = "Generations" }; evaluationsTerminator = new ComparisonTerminator<IntValue>("EvaluatedSolutions", ComparisonType.Less, new IntValue(int.MaxValue)) { Name = "Evaluations" }; qualityTerminator = new SingleObjectiveQualityTerminator() { Name = "Quality" }; executionTimeTerminator = new ExecutionTimeTerminator(this, new TimeSpanValue(TimeSpan.FromMinutes(5))); #endregion #region Parameterize UpdateAnalyzers(); ParameterizeAnalyzers(); ParameterizeSelectors(); UpdateTerminators(); ParameterizeAgeLimits(); #endregion Initialize(); }
private AlpsGeneticAlgorithmMainLoop(AlpsGeneticAlgorithmMainLoop original, Cloner cloner) : base(original, cloner) { }
private AlpsGeneticAlgorithmMainLoop(AlpsGeneticAlgorithmMainLoop original, Cloner cloner) : base(original, cloner) { }
public AlpsGeneticAlgorithm() : base() { #region Add parameters Parameters.Add(new ValueParameter <IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0))); Parameters.Add(new ValueParameter <BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true))); Parameters.Add(new FixedValueParameter <MultiAnalyzer>("Analyzer", "The operator used to analyze all individuals from all layers combined.", new MultiAnalyzer())); Parameters.Add(new FixedValueParameter <MultiAnalyzer>("LayerAnalyzer", "The operator used to analyze each layer.", new MultiAnalyzer())); Parameters.Add(new ValueParameter <IntValue>("NumberOfLayers", "The number of layers.", new IntValue(10))); Parameters.Add(new ValueParameter <IntValue>("PopulationSize", "The size of the population of solutions in each layer.", new IntValue(100))); Parameters.Add(new ConstrainedValueParameter <ISelector>("Selector", "The operator used to select solutions for reproduction.")); Parameters.Add(new ConstrainedValueParameter <ICrossover>("Crossover", "The operator used to cross solutions.")); Parameters.Add(new OptionalConstrainedValueParameter <IManipulator>("Mutator", "The operator used to mutate solutions.")); Parameters.Add(new ValueParameter <PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05))); Parameters.Add(new ValueParameter <IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1))); Parameters.Add(new FixedValueParameter <BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", new BoolValue(false)) { Hidden = true }); Parameters.Add(new ValueParameter <BoolValue>("PlusSelection", "Include the parents in the selection of the invividuals for the next generation.", new BoolValue(false))); Parameters.Add(new ValueParameter <EnumValue <AgingScheme> >("AgingScheme", "The aging scheme for setting the age-limits for the layers.", new EnumValue <AgingScheme>(ALPS.AgingScheme.Polynomial))); Parameters.Add(new ValueParameter <IntValue>("AgeGap", "The frequency of reseeding the lowest layer and scaling factor for the age-limits for the layers.", new IntValue(20))); Parameters.Add(new ValueParameter <DoubleValue>("AgeInheritance", "A weight that determines the age of a child after crossover based on the older (1.0) and younger (0.0) parent.", new DoubleValue(1.0)) { Hidden = true }); Parameters.Add(new ValueParameter <IntArray>("AgeLimits", "The maximum age an individual is allowed to reach in a certain layer.", new IntArray(new int[0])) { Hidden = true }); Parameters.Add(new ValueParameter <IntValue>("MatingPoolRange", "The range of layers used for creating a mating pool. (1 = current + previous layer)", new IntValue(1)) { Hidden = true }); Parameters.Add(new ValueParameter <BoolValue>("ReduceToPopulationSize", "Reduce the CurrentPopulationSize after elder migration to PopulationSize", new BoolValue(true)) { Hidden = true }); Parameters.Add(new ValueParameter <MultiTerminator>("Terminator", "The termination criteria that defines if the algorithm should continue or stop.", new MultiTerminator())); #endregion #region Create operators var globalRandomCreator = new RandomCreator(); var layer0Creator = new SubScopesCreator() { Name = "Create Layer Zero" }; var layer0Processor = new SubScopesProcessor(); var localRandomCreator = new LocalRandomCreator(); var layerSolutionsCreator = new SolutionsCreator(); var initializeAgeProcessor = new UniformSubScopesProcessor(); var initializeAge = new VariableCreator() { Name = "Initialize Age" }; var initializeCurrentPopulationSize = new SubScopesCounter() { Name = "Initialize CurrentPopulationCounter" }; var initializeLocalEvaluatedSolutions = new Assigner() { Name = "Initialize LayerEvaluatedSolutions" }; var initializeGlobalEvaluatedSolutions = new DataReducer() { Name = "Initialize EvaluatedSolutions" }; var resultsCollector = new ResultsCollector(); var mainLoop = new AlpsGeneticAlgorithmMainLoop(); #endregion #region Create and parameterize operator graph OperatorGraph.InitialOperator = globalRandomCreator; globalRandomCreator.RandomParameter.ActualName = "GlobalRandom"; globalRandomCreator.SeedParameter.Value = null; globalRandomCreator.SeedParameter.ActualName = SeedParameter.Name; globalRandomCreator.SetSeedRandomlyParameter.Value = null; globalRandomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name; globalRandomCreator.Successor = layer0Creator; layer0Creator.NumberOfSubScopesParameter.Value = new IntValue(1); layer0Creator.Successor = layer0Processor; layer0Processor.Operators.Add(localRandomCreator); layer0Processor.Successor = initializeGlobalEvaluatedSolutions; localRandomCreator.Successor = layerSolutionsCreator; layerSolutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name; layerSolutionsCreator.Successor = initializeAgeProcessor; initializeAgeProcessor.Operator = initializeAge; initializeAgeProcessor.Successor = initializeCurrentPopulationSize; initializeCurrentPopulationSize.ValueParameter.ActualName = "CurrentPopulationSize"; initializeCurrentPopulationSize.Successor = initializeLocalEvaluatedSolutions; initializeAge.CollectedValues.Add(new ValueParameter <DoubleValue>("Age", new DoubleValue(0))); initializeAge.Successor = null; initializeLocalEvaluatedSolutions.LeftSideParameter.ActualName = "LayerEvaluatedSolutions"; initializeLocalEvaluatedSolutions.RightSideParameter.ActualName = "CurrentPopulationSize"; initializeLocalEvaluatedSolutions.Successor = null; initializeGlobalEvaluatedSolutions.ReductionOperation.Value.Value = ReductionOperations.Sum; initializeGlobalEvaluatedSolutions.TargetOperation.Value.Value = ReductionOperations.Assign; initializeGlobalEvaluatedSolutions.ParameterToReduce.ActualName = "LayerEvaluatedSolutions"; initializeGlobalEvaluatedSolutions.TargetParameter.ActualName = "EvaluatedSolutions"; initializeGlobalEvaluatedSolutions.Successor = resultsCollector; resultsCollector.CollectedValues.Add(new LookupParameter <IntValue>("Evaluated Solutions", null, "EvaluatedSolutions")); resultsCollector.Successor = mainLoop; mainLoop.GlobalRandomParameter.ActualName = "GlobalRandom"; mainLoop.LocalRandomParameter.ActualName = localRandomCreator.LocalRandomParameter.Name; mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions"; mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name; mainLoop.LayerAnalyzerParameter.ActualName = LayerAnalyzerParameter.Name; mainLoop.NumberOfLayersParameter.ActualName = NumberOfLayersParameter.Name; mainLoop.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name; mainLoop.CurrentPopulationSizeParameter.ActualName = "CurrentPopulationSize"; mainLoop.SelectorParameter.ActualName = SelectorParameter.Name; mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name; mainLoop.MutatorParameter.ActualName = MutatorParameter.Name; mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name; mainLoop.ElitesParameter.ActualName = ElitesParameter.Name; mainLoop.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name; mainLoop.PlusSelectionParameter.ActualName = PlusSelectionParameter.Name; mainLoop.AgeParameter.ActualName = "Age"; mainLoop.AgeGapParameter.ActualName = AgeGapParameter.Name; mainLoop.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name; mainLoop.AgeLimitsParameter.ActualName = AgeLimitsParameter.Name; mainLoop.MatingPoolRangeParameter.ActualName = MatingPoolRangeParameter.Name; mainLoop.ReduceToPopulationSizeParameter.ActualName = ReduceToPopulationSizeParameter.Name; mainLoop.TerminatorParameter.ActualName = TerminatorParameter.Name; #endregion #region Set selectors foreach (var selector in ApplicationManager.Manager.GetInstances <ISelector>().Where(s => !(s is IMultiObjectiveSelector)).OrderBy(s => Name)) { SelectorParameter.ValidValues.Add(selector); } var defaultSelector = SelectorParameter.ValidValues.OfType <GeneralizedRankSelector>().FirstOrDefault(); if (defaultSelector != null) { defaultSelector.PressureParameter.Value = new DoubleValue(4.0); SelectorParameter.Value = defaultSelector; } #endregion #region Create analyzers qualityAnalyzer = new BestAverageWorstQualityAnalyzer(); layerQualityAnalyzer = new BestAverageWorstQualityAnalyzer(); ageAnalyzer = new OldestAverageYoungestAgeAnalyzer(); layerAgeAnalyzer = new OldestAverageYoungestAgeAnalyzer(); ageDistributionAnalyzer = new AgeDistributionAnalyzer(); layerAgeDistributionAnalyzer = new AgeDistributionAnalyzer(); #endregion #region Create terminators generationsTerminator = new ComparisonTerminator <IntValue>("Generations", ComparisonType.Less, new IntValue(1000)) { Name = "Generations" }; evaluationsTerminator = new ComparisonTerminator <IntValue>("EvaluatedSolutions", ComparisonType.Less, new IntValue(int.MaxValue)) { Name = "Evaluations" }; qualityTerminator = new SingleObjectiveQualityTerminator() { Name = "Quality" }; executionTimeTerminator = new ExecutionTimeTerminator(this, new TimeSpanValue(TimeSpan.FromMinutes(5))); #endregion #region Parameterize UpdateAnalyzers(); ParameterizeAnalyzers(); ParameterizeSelectors(); UpdateTerminators(); ParameterizeAgeLimits(); #endregion Initialize(); }