private void Initialize() { #region Create parameters Parameters.Add(new ValueLookupParameter <IRandom>("Random", "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>("PopulationSize", "The population size.")); 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 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 <IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.")); 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 LookupParameter <IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated.")); Parameters.Add(new ValueLookupParameter <BoolValue>("DominateOnEqualQualities", "Flag which determines wether solutions with equal quality values should be treated as dominated.")); #endregion #region Create operators VariableCreator variableCreator = new VariableCreator(); ResultsCollector resultsCollector1 = new ResultsCollector(); Placeholder analyzer1 = new Placeholder(); Placeholder selector = new Placeholder(); SubScopesProcessor subScopesProcessor1 = new SubScopesProcessor(); ChildrenCreator childrenCreator = new ChildrenCreator(); UniformSubScopesProcessor uniformSubScopesProcessor1 = new UniformSubScopesProcessor(); StochasticBranch crossoverStochasticBranch = new StochasticBranch(); Placeholder crossover = new Placeholder(); ParentCopyCrossover noCrossover = new ParentCopyCrossover(); StochasticBranch mutationStochasticBranch = new StochasticBranch(); Placeholder mutator = new Placeholder(); SubScopesRemover subScopesRemover = new SubScopesRemover(); UniformSubScopesProcessor uniformSubScopesProcessor2 = new UniformSubScopesProcessor(); Placeholder evaluator = new Placeholder(); SubScopesCounter subScopesCounter = new SubScopesCounter(); MergingReducer mergingReducer = new MergingReducer(); RankAndCrowdingSorter rankAndCrowdingSorter = new RankAndCrowdingSorter(); LeftSelector leftSelector = new LeftSelector(); RightReducer rightReducer = new RightReducer(); IntCounter intCounter = new IntCounter(); Comparator comparator = new Comparator(); Placeholder analyzer2 = new Placeholder(); ConditionalBranch conditionalBranch = new ConditionalBranch(); variableCreator.CollectedValues.Add(new ValueParameter <IntValue>("Generations", new IntValue(0))); resultsCollector1.CollectedValues.Add(new LookupParameter <IntValue>("Generations")); resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name; analyzer1.Name = "Analyzer"; analyzer1.OperatorParameter.ActualName = AnalyzerParameter.Name; selector.Name = "Selector"; selector.OperatorParameter.ActualName = SelectorParameter.Name; childrenCreator.ParentsPerChild = new IntValue(2); crossoverStochasticBranch.ProbabilityParameter.ActualName = CrossoverProbabilityParameter.Name; crossoverStochasticBranch.RandomParameter.ActualName = RandomParameter.Name; crossover.Name = "Crossover"; crossover.OperatorParameter.ActualName = CrossoverParameter.Name; noCrossover.Name = "Clone parent"; noCrossover.RandomParameter.ActualName = RandomParameter.Name; mutationStochasticBranch.ProbabilityParameter.ActualName = MutationProbabilityParameter.Name; mutationStochasticBranch.RandomParameter.ActualName = RandomParameter.Name; mutator.Name = "Mutator"; mutator.OperatorParameter.ActualName = MutatorParameter.Name; subScopesRemover.RemoveAllSubScopes = true; uniformSubScopesProcessor2.Parallel.Value = true; evaluator.Name = "Evaluator"; evaluator.OperatorParameter.ActualName = EvaluatorParameter.Name; subScopesCounter.Name = "Increment EvaluatedSolutions"; subScopesCounter.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name; rankAndCrowdingSorter.DominateOnEqualQualitiesParameter.ActualName = DominateOnEqualQualitiesParameter.Name; rankAndCrowdingSorter.CrowdingDistanceParameter.ActualName = "CrowdingDistance"; rankAndCrowdingSorter.RankParameter.ActualName = "Rank"; leftSelector.CopySelected = new BoolValue(false); leftSelector.NumberOfSelectedSubScopesParameter.ActualName = PopulationSizeParameter.Name; intCounter.Increment = new IntValue(1); intCounter.ValueParameter.ActualName = "Generations"; comparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual); comparator.LeftSideParameter.ActualName = "Generations"; comparator.ResultParameter.ActualName = "Terminate"; comparator.RightSideParameter.ActualName = MaximumGenerationsParameter.Name; analyzer2.Name = "Analyzer"; analyzer2.OperatorParameter.ActualName = "Analyzer"; conditionalBranch.ConditionParameter.ActualName = "Terminate"; #endregion #region Create operator graph OperatorGraph.InitialOperator = variableCreator; variableCreator.Successor = resultsCollector1; resultsCollector1.Successor = analyzer1; analyzer1.Successor = selector; selector.Successor = subScopesProcessor1; subScopesProcessor1.Operators.Add(new EmptyOperator()); subScopesProcessor1.Operators.Add(childrenCreator); subScopesProcessor1.Successor = mergingReducer; childrenCreator.Successor = uniformSubScopesProcessor1; uniformSubScopesProcessor1.Operator = crossoverStochasticBranch; uniformSubScopesProcessor1.Successor = uniformSubScopesProcessor2; crossoverStochasticBranch.FirstBranch = crossover; crossoverStochasticBranch.SecondBranch = noCrossover; crossoverStochasticBranch.Successor = mutationStochasticBranch; crossover.Successor = null; noCrossover.Successor = null; mutationStochasticBranch.FirstBranch = mutator; mutationStochasticBranch.SecondBranch = null; mutationStochasticBranch.Successor = subScopesRemover; mutator.Successor = null; subScopesRemover.Successor = null; uniformSubScopesProcessor2.Operator = evaluator; uniformSubScopesProcessor2.Successor = subScopesCounter; evaluator.Successor = null; subScopesCounter.Successor = null; mergingReducer.Successor = rankAndCrowdingSorter; rankAndCrowdingSorter.Successor = leftSelector; leftSelector.Successor = rightReducer; rightReducer.Successor = intCounter; intCounter.Successor = comparator; comparator.Successor = analyzer2; analyzer2.Successor = conditionalBranch; conditionalBranch.FalseBranch = selector; conditionalBranch.TrueBranch = null; conditionalBranch.Successor = null; #endregion }
public AlpsNsga2MainOperator() : base() { Parameters.Add(new ValueLookupParameter <IRandom>("Random", "A pseudo random number generator.")); 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 <IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated.")); Parameters.Add(new ScopeTreeLookupParameter <DoubleValue>("Quality", "The value which represents the quality of a solution.")); Parameters.Add(new ValueLookupParameter <BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false.")); Parameters.Add(new ValueLookupParameter <IntValue>("PopulationSize", "The size of the population of solutions in each layer.")); Parameters.Add(new ValueLookupParameter <IOperator>("Selector", "The operator used to select solutions for reproduction.")); Parameters.Add(new ValueLookupParameter <IOperator>("Crossover", "The operator used to cross solutions.")); Parameters.Add(new ValueLookupParameter <PercentValue>("CrossoverProbability", "The probability that the crossover operator is applied on a solution.")); Parameters.Add(new ValueLookupParameter <IOperator>("Mutator", "The operator used to mutate solutions.")); Parameters.Add(new ValueLookupParameter <PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.")); Parameters.Add(new ScopeTreeLookupParameter <DoubleValue>("Age", "The age of individuals.")); 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 <DoubleValue>("AgeIncrement", "The value the age the individuals is incremented if they survives a generation.")); Parameters.Add(new ValueLookupParameter <BoolValue>("DominateOnEqualQualities", "Flag which determines whether solutions with equal quality values should be treated as dominated.")); var selector = new Placeholder { Name = "Selector (Placeholder)" }; var subScopesProcessor1 = new SubScopesProcessor(); var childrenCreator = new ChildrenCreator(); var uniformSubScopesProcessor1 = new UniformSubScopesProcessor(); var crossoverStochasticBranch = new StochasticBranch { Name = "CrossoverProbability" }; var crossover = new Placeholder { Name = "Crossover (Placeholder)" }; var noCrossover = new ParentCopyCrossover(); var mutationStochasticBranch = new StochasticBranch { Name = "MutationProbability" }; var mutator = new Placeholder { Name = "Mutator (Placeholder)" }; var ageCalculator = new WeightingReducer { Name = "Calculate Age" }; var subScopesRemover = new SubScopesRemover(); var uniformSubScopesProcessor2 = new UniformSubScopesProcessor(); var evaluator = new Placeholder { Name = "Evaluator (Placeholder)" }; var subScopesCounter = new SubScopesCounter { Name = "Increment EvaluatedSolutions" }; var mergingReducer = new MergingReducer(); var rankAndCrowdingSorter1 = new RankAndCrowdingSorter(); var rankAndCrowdingSorter2 = new RankAndCrowdingSorter(); var leftSelector = new LeftSelector(); var rightReducer = new RightReducer(); var incrementAgeProcessor = new UniformSubScopesProcessor(); var ageIncrementer = new DoubleCounter { Name = "Increment Age" }; OperatorGraph.InitialOperator = rankAndCrowdingSorter1; rankAndCrowdingSorter1.DominateOnEqualQualitiesParameter.ActualName = DominateOnEqualQualitiesParameter.Name; rankAndCrowdingSorter1.CrowdingDistanceParameter.ActualName = "CrowdingDistance"; rankAndCrowdingSorter1.RankParameter.ActualName = "Rank"; rankAndCrowdingSorter1.Successor = selector; selector.OperatorParameter.ActualName = SelectorParameter.Name; selector.Successor = subScopesProcessor1; subScopesProcessor1.Operators.Add(new EmptyOperator()); subScopesProcessor1.Operators.Add(childrenCreator); subScopesProcessor1.Successor = mergingReducer; childrenCreator.ParentsPerChild = new IntValue(2); childrenCreator.Successor = uniformSubScopesProcessor1; uniformSubScopesProcessor1.Operator = crossoverStochasticBranch; uniformSubScopesProcessor1.Successor = uniformSubScopesProcessor2; crossoverStochasticBranch.ProbabilityParameter.ActualName = CrossoverProbabilityParameter.Name; crossoverStochasticBranch.RandomParameter.ActualName = RandomParameter.Name; crossoverStochasticBranch.FirstBranch = crossover; crossoverStochasticBranch.SecondBranch = noCrossover; crossoverStochasticBranch.Successor = mutationStochasticBranch; crossover.Name = "Crossover"; crossover.OperatorParameter.ActualName = CrossoverParameter.Name; crossover.Successor = null; noCrossover.Name = "Clone parent"; noCrossover.RandomParameter.ActualName = RandomParameter.Name; noCrossover.Successor = null; mutationStochasticBranch.ProbabilityParameter.ActualName = MutationProbabilityParameter.Name; mutationStochasticBranch.RandomParameter.ActualName = RandomParameter.Name; mutationStochasticBranch.FirstBranch = mutator; mutationStochasticBranch.SecondBranch = null; mutationStochasticBranch.Successor = ageCalculator; mutator.Name = "Mutator"; mutator.OperatorParameter.ActualName = MutatorParameter.Name; mutator.Successor = null; ageCalculator.ParameterToReduce.ActualName = AgeParameter.Name; ageCalculator.TargetParameter.ActualName = AgeParameter.Name; ageCalculator.WeightParameter.ActualName = AgeInheritanceParameter.Name; ageCalculator.Successor = subScopesRemover; subScopesRemover.RemoveAllSubScopes = true; subScopesRemover.Successor = null; uniformSubScopesProcessor2.Parallel.Value = true; uniformSubScopesProcessor2.Operator = evaluator; uniformSubScopesProcessor2.Successor = subScopesCounter; evaluator.OperatorParameter.ActualName = EvaluatorParameter.Name; evaluator.Successor = null; subScopesCounter.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name; subScopesCounter.AccumulateParameter.Value = new BoolValue(true); subScopesCounter.Successor = null; mergingReducer.Successor = rankAndCrowdingSorter2; rankAndCrowdingSorter2.DominateOnEqualQualitiesParameter.ActualName = DominateOnEqualQualitiesParameter.Name; rankAndCrowdingSorter2.CrowdingDistanceParameter.ActualName = "CrowdingDistance"; rankAndCrowdingSorter2.RankParameter.ActualName = "Rank"; rankAndCrowdingSorter2.Successor = leftSelector; leftSelector.CopySelected = new BoolValue(false); leftSelector.NumberOfSelectedSubScopesParameter.ActualName = PopulationSizeParameter.Name; leftSelector.Successor = rightReducer; rightReducer.Successor = incrementAgeProcessor; incrementAgeProcessor.Operator = ageIncrementer; incrementAgeProcessor.Successor = null; ageIncrementer.ValueParameter.ActualName = AgeParameter.Name; ageIncrementer.IncrementParameter.Value = null; ageIncrementer.IncrementParameter.ActualName = AgeIncrementParameter.Name; ageIncrementer.Successor = null; }