private void Initialize() { #region Create parameters Parameters.Add(new ValueLookupParameter <IRandom>("GlobalRandom", "A pseudo random number generator.")); Parameters.Add(new ValueLookupParameter <IRandom>("LocalRandom", "A pseudo random number generator.")); Parameters.Add(new ValueLookupParameter <BoolArray>("Maximization", "True if an objective should be maximized, or false if it should be minimized.")); Parameters.Add(new ScopeTreeLookupParameter <DoubleArray>("Qualities", "The vector of quality values.")); Parameters.Add(new ValueLookupParameter <IntValue>("NumberOfLayers", "The number of layers.")); Parameters.Add(new ValueLookupParameter <IntValue>("PopulationSize", "The population size.")); Parameters.Add(new LookupParameter <IntValue>("CurrentPopulationSize", "The current size of the population.")); Parameters.Add(new ValueLookupParameter <IOperator>("Selector", "The operator used to select solutions for reproduction.")); Parameters.Add(new ValueLookupParameter <PercentValue>("CrossoverProbability", "The probability that the crossover operator is applied on a solution.")); Parameters.Add(new ValueLookupParameter <IOperator>("Crossover", "The operator used to cross solutions.")); Parameters.Add(new ValueLookupParameter <PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.")); Parameters.Add(new ValueLookupParameter <IOperator>("Mutator", "The operator used to mutate solutions.")); Parameters.Add(new ScopeTreeLookupParameter <DoubleValue>("Age", "The age of individuals.")); Parameters.Add(new ValueLookupParameter <IntValue>("AgeGap", "The frequency of reseeding the lowest layer and scaling factor for the age-limits for the layers.")); Parameters.Add(new ValueLookupParameter <DoubleValue>("AgeInheritance", "A weight that determines the age of a child after crossover based on the older (1.0) and younger (0.0) parent.")); Parameters.Add(new ValueLookupParameter <IntArray>("AgeLimits", "The maximum age an individual is allowed to reach in a certain layer.")); Parameters.Add(new ValueLookupParameter <IntValue>("MatingPoolRange", "The range of sub - populations used for creating a mating pool. (1 = current + previous sub-population)")); Parameters.Add(new ValueLookupParameter <BoolValue>("ReduceToPopulationSize", "Reduce the CurrentPopulationSize after elder migration to PopulationSize")); Parameters.Add(new ValueLookupParameter <IOperator>("Evaluator", "The operator used to evaluate solutions. This operator is executed in parallel, if an engine is used which supports parallelization.")); Parameters.Add(new ValueLookupParameter <VariableCollection>("Results", "The variable collection where results should be stored.")); Parameters.Add(new ValueLookupParameter <IOperator>("Analyzer", "The operator used to analyze each generation.")); Parameters.Add(new ValueLookupParameter <IOperator>("LayerAnalyzer", "The operator used to analyze each layer.")); Parameters.Add(new ValueLookupParameter <IOperator>("FinalAnalyzer", "The operator used to finally analyze the solution (after termination of the algorithm).")); Parameters.Add(new LookupParameter <IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated.")); Parameters.Add(new ValueLookupParameter <BoolValue>("DominateOnEqualQualities", "Flag which determines whether solutions with equal quality values should be treated as dominated.")); Parameters.Add(new ValueLookupParameter <IOperator>("Terminator", "The termination criteria that defines if the algorithm should continue or stop")); Parameters.Add(new FixedValueParameter <IntValue>("Zero", "Zero Value.", new IntValue(0))); Parameters.Add(new FixedValueParameter <IntValue>("One", "1 as a Value.", new IntValue(1))); #endregion #region Create operators and operator graph var variableCreator = new VariableCreator { Name = "Initialize" }; var resultsCollector1 = new ResultsCollector(); var initLayerAnalyzerProcessor = new SubScopesProcessor(); var layerVariableCreator = new VariableCreator { Name = "Initialize Layer" }; var initLayerAnalyzerPlaceholder = new Placeholder { Name = "LayerAnalyzer (Placeholder)" }; var initAnalyzerPlaceholder = new Placeholder { Name = "Analyzer (Placeholder)" }; var initFinalAnalyzerPlaceholder = new Placeholder { Name = "FinalAnalyzer (Placeholder)" }; var matingPoolCreator = new MatingPoolCreator { Name = "Create Mating Pools" }; var matingPoolProcessor = new UniformSubScopesProcessor { Name = "Process Mating Pools" }; var initializeLayer = new Assigner { Name = "Reset LayerEvaluatedSolutions" }; var mainOperator = new AlpsNsga2MainOperator(); var generationsIncrementer = new IntCounter { Name = "Increment Generations" }; var evaluatedSolutionsReducer = new DataReducer { Name = "Increment EvaluatedSolutions" }; var eldersEmigrator = CreateEldersEmigrator(); var layerOpener = CreateLayerOpener(); var layerReseeder = CreateReseeder(); var currentPopulationSizeComparator = new Comparator { Name = "Isn't CurrentPopulationSize 0?" }; var currentPopulationSizeIsNotZeroBranch = new ConditionalBranch { Name = "CurrentPopulationSize != Zero" }; var layerAnalyzerProcessor = new UniformSubScopesProcessor(); var layerAnalyzerPlaceholder = new Placeholder { Name = "LayerAnalyzer (Placeholder)" }; var analyzerPlaceholder = new Placeholder { Name = "Analyzer (Placeholder)" }; var termination = new TerminationOperator(); var rankAndCrowdingSorter = new RankAndCrowdingSorter(); var mergingReducer = new MergingReducer(); var leftSelector = new LeftSelector(); var rightReducer = new RightReducer(); OperatorGraph.InitialOperator = variableCreator; variableCreator.CollectedValues.Add(new ValueParameter <IntValue>("Generations", new IntValue(0))); variableCreator.CollectedValues.Add(new ValueParameter <IntValue>("OpenLayers", new IntValue(1))); variableCreator.Successor = initLayerAnalyzerProcessor; initLayerAnalyzerProcessor.Operators.Add(layerVariableCreator); initLayerAnalyzerProcessor.Successor = initAnalyzerPlaceholder; layerVariableCreator.CollectedValues.Add(new ValueParameter <IntValue>("Layer", new IntValue(0))); layerVariableCreator.CollectedValues.Add(new ValueParameter <ResultCollection>("LayerResults")); layerVariableCreator.Successor = initLayerAnalyzerPlaceholder; initLayerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name; initLayerAnalyzerPlaceholder.Successor = null; initAnalyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name; initAnalyzerPlaceholder.Successor = resultsCollector1; resultsCollector1.CollectedValues.Add(new LookupParameter <IntValue>("Generations")); resultsCollector1.CollectedValues.Add(new ScopeTreeLookupParameter <ResultCollection>("LayerResults", "Result set for each Layer", "LayerResults")); resultsCollector1.CollectedValues.Add(new LookupParameter <IntValue>("OpenLayers")); resultsCollector1.CopyValue = new BoolValue(false); resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name; resultsCollector1.Successor = matingPoolCreator; matingPoolCreator.MatingPoolRangeParameter.Value = null; matingPoolCreator.MatingPoolRangeParameter.ActualName = MatingPoolRangeParameter.Name; matingPoolCreator.Successor = matingPoolProcessor; matingPoolProcessor.Parallel.Value = true; matingPoolProcessor.Operator = initializeLayer; matingPoolProcessor.Successor = generationsIncrementer; initializeLayer.LeftSideParameter.ActualName = "LayerEvaluatedSolutions"; initializeLayer.RightSideParameter.Value = new IntValue(0); initializeLayer.Successor = mainOperator; mainOperator.RandomParameter.ActualName = LocalRandomParameter.Name; mainOperator.EvaluatorParameter.ActualName = EvaluatorParameter.Name; mainOperator.EvaluatedSolutionsParameter.ActualName = "LayerEvaluatedSolutions"; mainOperator.QualityParameter.ActualName = QualitiesParameter.Name; mainOperator.MaximizationParameter.ActualName = MaximizationParameter.Name; mainOperator.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name; mainOperator.SelectorParameter.ActualName = SelectorParameter.Name; mainOperator.CrossoverParameter.ActualName = CrossoverParameter.Name; mainOperator.CrossoverProbabilityParameter.ActualName = CrossoverProbabilityParameter.Name; mainOperator.MutatorParameter.ActualName = MutatorParameter.ActualName; mainOperator.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name; mainOperator.AgeParameter.ActualName = AgeParameter.Name; mainOperator.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name; mainOperator.AgeIncrementParameter.Value = new DoubleValue(1.0); mainOperator.Successor = null; generationsIncrementer.ValueParameter.ActualName = "Generations"; generationsIncrementer.Increment = new IntValue(1); generationsIncrementer.Successor = evaluatedSolutionsReducer; evaluatedSolutionsReducer.ParameterToReduce.ActualName = "LayerEvaluatedSolutions"; evaluatedSolutionsReducer.TargetParameter.ActualName = EvaluatedSolutionsParameter.Name; evaluatedSolutionsReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum); evaluatedSolutionsReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Sum); evaluatedSolutionsReducer.Successor = eldersEmigrator; eldersEmigrator.Successor = layerOpener; layerOpener.Successor = layerReseeder; layerReseeder.Successor = layerAnalyzerProcessor; // Layer analyzer is only performed if individuals count is not 0 layerAnalyzerProcessor.Operator = currentPopulationSizeComparator; layerAnalyzerProcessor.Successor = analyzerPlaceholder; currentPopulationSizeComparator.LeftSideParameter.ActualName = CurrentPopulationSizeParameter.Name; currentPopulationSizeComparator.RightSideParameter.ActualName = ZeroParameter.Name; currentPopulationSizeComparator.ResultParameter.ActualName = "CurrentPopulationSizeIsNotZero"; currentPopulationSizeComparator.Comparison = new Comparison(ComparisonType.NotEqual); currentPopulationSizeComparator.Successor = currentPopulationSizeIsNotZeroBranch; currentPopulationSizeIsNotZeroBranch.ConditionParameter.ActualName = "CurrentPopulationSizeIsNotZero"; currentPopulationSizeIsNotZeroBranch.TrueBranch = layerAnalyzerPlaceholder; layerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name; analyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name; analyzerPlaceholder.Successor = termination; termination.TerminatorParameter.ActualName = TerminatorParameter.Name; termination.ContinueBranch = matingPoolCreator; termination.TerminateBranch = mergingReducer; mergingReducer.Successor = rankAndCrowdingSorter; rankAndCrowdingSorter.DominateOnEqualQualitiesParameter.ActualName = DominateOnEqualQualitiesParameter.Name; rankAndCrowdingSorter.CrowdingDistanceParameter.ActualName = "CrowdingDistance"; rankAndCrowdingSorter.RankParameter.ActualName = "Rank"; rankAndCrowdingSorter.Successor = leftSelector; leftSelector.CopySelected = new BoolValue(false); leftSelector.NumberOfSelectedSubScopesParameter.ActualName = PopulationSizeParameter.Name; leftSelector.Successor = rightReducer; rightReducer.Successor = initFinalAnalyzerPlaceholder; initFinalAnalyzerPlaceholder.OperatorParameter.ActualName = FinalAnalyzerParameter.Name; #endregion }
private CombinedOperator CreateLayerOpener() { var layerOpener = new CombinedOperator { Name = "Open new Layer if needed" }; var maxLayerReached = new Comparator { Name = "MaxLayersReached = OpenLayers >= NumberOfLayers" }; var maxLayerReachedBranch = new ConditionalBranch { Name = "MaxLayersReached?" }; var openNewLayerCalculator = new ExpressionCalculator { Name = "OpenNewLayer = Generations >= AgeLimits[OpenLayers - 1]" }; var openNewLayerBranch = new ConditionalBranch { Name = "OpenNewLayer?" }; var layerCreator = new LastLayerCloner { Name = "Create Layer" }; var updateLayerNumber = new Assigner { Name = "Layer = OpenLayers" }; var historyWiper = new ResultsHistoryWiper { Name = "Clear History in Results" }; var createChildrenViaCrossover = new AlpsNsga2MainOperator(); var incrEvaluatedSolutionsForNewLayer = new SubScopesCounter { Name = "Update EvaluatedSolutions" }; var incrOpenLayers = new IntCounter { Name = "Incr. OpenLayers" }; var newLayerResultsCollector = new ResultsCollector { Name = "Collect new Layer Results" }; layerOpener.OperatorGraph.InitialOperator = maxLayerReached; maxLayerReached.LeftSideParameter.ActualName = "OpenLayers"; maxLayerReached.RightSideParameter.ActualName = NumberOfLayersParameter.Name; maxLayerReached.ResultParameter.ActualName = "MaxLayerReached"; maxLayerReached.Comparison = new Comparison(ComparisonType.GreaterOrEqual); maxLayerReached.Successor = maxLayerReachedBranch; maxLayerReachedBranch.ConditionParameter.ActualName = "MaxLayerReached"; maxLayerReachedBranch.FalseBranch = openNewLayerCalculator; openNewLayerCalculator.CollectedValues.Add(new LookupParameter <IntArray>(AgeLimitsParameter.Name)); openNewLayerCalculator.CollectedValues.Add(new LookupParameter <IntValue>("Generations")); openNewLayerCalculator.CollectedValues.Add(new LookupParameter <IntValue>(NumberOfLayersParameter.Name)); openNewLayerCalculator.CollectedValues.Add(new LookupParameter <IntValue>("OpenLayers")); openNewLayerCalculator.ExpressionResultParameter.ActualName = "OpenNewLayer"; openNewLayerCalculator.ExpressionParameter.Value = new StringValue("Generations 1 + AgeLimits OpenLayers 1 - [] >"); openNewLayerCalculator.Successor = openNewLayerBranch; openNewLayerBranch.ConditionParameter.ActualName = "OpenNewLayer"; openNewLayerBranch.TrueBranch = layerCreator; layerCreator.NewLayerOperator = updateLayerNumber; layerCreator.Successor = incrOpenLayers; updateLayerNumber.LeftSideParameter.ActualName = "Layer"; updateLayerNumber.RightSideParameter.ActualName = "OpenLayers"; updateLayerNumber.Successor = historyWiper; historyWiper.ResultsParameter.ActualName = "LayerResults"; historyWiper.Successor = createChildrenViaCrossover; createChildrenViaCrossover.RandomParameter.ActualName = LocalRandomParameter.Name; createChildrenViaCrossover.EvaluatorParameter.ActualName = EvaluatorParameter.Name; createChildrenViaCrossover.EvaluatedSolutionsParameter.ActualName = "LayerEvaluatedSolutions"; createChildrenViaCrossover.QualityParameter.ActualName = QualitiesParameter.Name; createChildrenViaCrossover.MaximizationParameter.ActualName = MaximizationParameter.Name; createChildrenViaCrossover.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name; createChildrenViaCrossover.SelectorParameter.ActualName = SelectorParameter.Name; createChildrenViaCrossover.CrossoverParameter.ActualName = CrossoverParameter.Name; createChildrenViaCrossover.CrossoverProbabilityParameter.ActualName = CrossoverProbabilityParameter.Name; createChildrenViaCrossover.MutatorParameter.ActualName = MutatorParameter.Name; createChildrenViaCrossover.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name; createChildrenViaCrossover.AgeParameter.ActualName = AgeParameter.Name; createChildrenViaCrossover.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name; createChildrenViaCrossover.AgeIncrementParameter.Value = new DoubleValue(0.0); createChildrenViaCrossover.Successor = incrEvaluatedSolutionsForNewLayer; incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name; incrEvaluatedSolutionsForNewLayer.AccumulateParameter.Value = new BoolValue(true); incrOpenLayers.ValueParameter.ActualName = "OpenLayers"; incrOpenLayers.Increment = new IntValue(1); incrOpenLayers.Successor = newLayerResultsCollector; newLayerResultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter <ResultCollection>("LayerResults", "Result set for each layer", "LayerResults")); newLayerResultsCollector.CopyValue = new BoolValue(false); newLayerResultsCollector.Successor = null; return(layerOpener); }
private AlpsNsga2MainOperator(AlpsNsga2MainOperator original, Cloner cloner) : base(original, cloner) { }