private CombinedOperator CreateReseeder() { var reseeder = new CombinedOperator { Name = "Reseed Layer Zero if needed" }; var reseedingController = new ReseedingController { Name = "Reseeding needed (Generation % AgeGap == 0)?" }; var removeIndividuals = new SubScopesRemover(); var createIndividuals = new SolutionsCreator(); var initializeAgeProcessor = new UniformSubScopesProcessor(); var initializeAge = new VariableCreator { Name = "Initialize Age" }; var incrEvaluatedSolutionsAfterReseeding = new SubScopesCounter { Name = "Update EvaluatedSolutions" }; var rankAndCrowdingSorter = new RankAndCrowdingSorter(); reseeder.OperatorGraph.InitialOperator = reseedingController; reseedingController.GenerationsParameter.ActualName = "Generations"; reseedingController.AgeGapParameter.ActualName = AgeGapParameter.Name; reseedingController.FirstLayerOperator = removeIndividuals; reseedingController.Successor = null; removeIndividuals.Successor = createIndividuals; createIndividuals.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name; createIndividuals.Successor = initializeAgeProcessor; initializeAgeProcessor.Operator = initializeAge; initializeAgeProcessor.Successor = incrEvaluatedSolutionsAfterReseeding; initializeAge.CollectedValues.Add(new ValueParameter <DoubleValue>(AgeParameter.Name, new DoubleValue(0))); incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name; incrEvaluatedSolutionsAfterReseeding.AccumulateParameter.Value = new BoolValue(true); incrEvaluatedSolutionsAfterReseeding.Successor = rankAndCrowdingSorter; return(reseeder); }
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 NSGA2() { 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 ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(100))); Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction.")); Parameters.Add(new ValueParameter<PercentValue>("CrossoverProbability", "The probability that the crossover operator is applied on two parents.", new PercentValue(0.9))); Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross 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 OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions.")); Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer())); Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000))); Parameters.Add(new ValueParameter<IntValue>("SelectedParents", "Each two parents form a new child, typically this value should be twice the population size, but because the NSGA-II is maximally elitist it can be any multiple of 2 greater than 0.", new IntValue(200))); Parameters.Add(new FixedValueParameter<BoolValue>("DominateOnEqualQualities", "Flag which determines wether solutions with equal quality values should be treated as dominated.", new BoolValue(false))); RandomCreator randomCreator = new RandomCreator(); SolutionsCreator solutionsCreator = new SolutionsCreator(); SubScopesCounter subScopesCounter = new SubScopesCounter(); RankAndCrowdingSorter rankAndCrowdingSorter = new RankAndCrowdingSorter(); ResultsCollector resultsCollector = new ResultsCollector(); NSGA2MainLoop mainLoop = new NSGA2MainLoop(); OperatorGraph.InitialOperator = randomCreator; randomCreator.RandomParameter.ActualName = "Random"; randomCreator.SeedParameter.ActualName = SeedParameter.Name; randomCreator.SeedParameter.Value = null; randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name; randomCreator.SetSeedRandomlyParameter.Value = null; randomCreator.Successor = solutionsCreator; solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name; solutionsCreator.Successor = subScopesCounter; subScopesCounter.Name = "Initialize EvaluatedSolutions"; subScopesCounter.ValueParameter.ActualName = "EvaluatedSolutions"; subScopesCounter.Successor = rankAndCrowdingSorter; rankAndCrowdingSorter.DominateOnEqualQualitiesParameter.ActualName = DominateOnEqualQualitiesParameter.Name; rankAndCrowdingSorter.CrowdingDistanceParameter.ActualName = "CrowdingDistance"; rankAndCrowdingSorter.RankParameter.ActualName = "Rank"; rankAndCrowdingSorter.Successor = resultsCollector; resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", null, "EvaluatedSolutions")); resultsCollector.ResultsParameter.ActualName = "Results"; resultsCollector.Successor = mainLoop; mainLoop.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name; mainLoop.SelectorParameter.ActualName = SelectorParameter.Name; mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name; mainLoop.CrossoverProbabilityParameter.ActualName = CrossoverProbabilityParameter.Name; mainLoop.MaximumGenerationsParameter.ActualName = MaximumGenerationsParameter.Name; mainLoop.MutatorParameter.ActualName = MutatorParameter.Name; mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name; mainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName; mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name; mainLoop.ResultsParameter.ActualName = "Results"; mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions"; foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is ISingleObjectiveSelector)).OrderBy(x => x.Name)) SelectorParameter.ValidValues.Add(selector); ISelector tournamentSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("CrowdedTournamentSelector")); if (tournamentSelector != null) SelectorParameter.Value = tournamentSelector; ParameterizeSelectors(); paretoFrontAnalyzer = new RankBasedParetoFrontAnalyzer(); paretoFrontAnalyzer.RankParameter.ActualName = "Rank"; paretoFrontAnalyzer.RankParameter.Depth = 1; paretoFrontAnalyzer.ResultsParameter.ActualName = "Results"; ParameterizeAnalyzers(); UpdateAnalyzers(); AfterDeserialization(); }
private CombinedOperator CreateEldersEmigrator() { var eldersEmigrator = new CombinedOperator { Name = "Emigrate Elders" }; var selectorProcessor = new UniformSubScopesProcessor(); var eldersSelector = new EldersSelector(); var shiftToRightMigrator = new UnidirectionalRingMigrator { Name = "Shift elders to next layer" }; var mergingProcessor = new UniformSubScopesProcessor(); var mergingReducer = new MergingReducer(); var subScopesCounter1 = new SubScopesCounter(); var currentPopulationSizeComparator = new Comparator { Name = "Is CurrentPopulationSize greater than 1?" }; var currentPopulationSizeIsGreaterThanOne = new ConditionalBranch { Name = "CurrentPopulationSize > 1" }; var reduceToPopulationSizeBranch = new ConditionalBranch { Name = "ReduceToPopulationSize?" }; var countCalculator = new ExpressionCalculator { Name = "CurrentPopulationSize = Min(CurrentPopulationSize, PopulationSize)" }; var leftSelector = new LeftSelector(); var rankAndCrowdingSorter = new RankAndCrowdingSorter(); var subScopesCounter2 = new SubScopesCounter(); var rightReducer = new RightReducer(); eldersEmigrator.OperatorGraph.InitialOperator = selectorProcessor; selectorProcessor.Operator = eldersSelector; selectorProcessor.Successor = shiftToRightMigrator; eldersSelector.AgeParameter.ActualName = AgeParameter.Name; eldersSelector.AgeLimitsParameter.ActualName = AgeLimitsParameter.Name; eldersSelector.NumberOfLayersParameter.ActualName = NumberOfLayersParameter.Name; eldersSelector.LayerParameter.ActualName = "Layer"; eldersSelector.Successor = null; shiftToRightMigrator.ClockwiseMigrationParameter.Value = new BoolValue(true); shiftToRightMigrator.Successor = mergingProcessor; mergingProcessor.Operator = mergingReducer; mergingReducer.Successor = subScopesCounter1; subScopesCounter1.ValueParameter.ActualName = CurrentPopulationSizeParameter.Name; subScopesCounter1.AccumulateParameter.Value = new BoolValue(false); subScopesCounter1.Successor = currentPopulationSizeComparator; currentPopulationSizeComparator.LeftSideParameter.ActualName = CurrentPopulationSizeParameter.Name; currentPopulationSizeComparator.RightSideParameter.ActualName = OneParameter.Name; currentPopulationSizeComparator.ResultParameter.ActualName = "CurrentPopulationSizeIsGreaterThanOne"; currentPopulationSizeComparator.Comparison = new Comparison(ComparisonType.Greater); currentPopulationSizeComparator.Successor = currentPopulationSizeIsGreaterThanOne; currentPopulationSizeIsGreaterThanOne.ConditionParameter.ActualName = "CurrentPopulationSizeIsGreaterThanOne"; currentPopulationSizeIsGreaterThanOne.TrueBranch = rankAndCrowdingSorter; // We have to sort individuals before reducing, because if we shifted some of them to another layer, it can happen that they are not correctly sorted rankAndCrowdingSorter.DominateOnEqualQualitiesParameter.ActualName = DominateOnEqualQualitiesParameter.Name; rankAndCrowdingSorter.CrowdingDistanceParameter.ActualName = "CrowdingDistance"; rankAndCrowdingSorter.RankParameter.ActualName = "Rank"; rankAndCrowdingSorter.Successor = reduceToPopulationSizeBranch; reduceToPopulationSizeBranch.ConditionParameter.ActualName = ReduceToPopulationSizeParameter.Name; reduceToPopulationSizeBranch.TrueBranch = countCalculator; countCalculator.CollectedValues.Add(new LookupParameter <IntValue>(PopulationSizeParameter.Name)); countCalculator.CollectedValues.Add(new LookupParameter <IntValue>(CurrentPopulationSizeParameter.Name)); countCalculator.ExpressionParameter.Value = new StringValue("CurrentPopulationSize PopulationSize CurrentPopulationSize PopulationSize < if toint"); countCalculator.ExpressionResultParameter.ActualName = CurrentPopulationSizeParameter.Name; countCalculator.Successor = leftSelector; leftSelector.CopySelected = new BoolValue(false); leftSelector.NumberOfSelectedSubScopesParameter.ActualName = CurrentPopulationSizeParameter.Name; leftSelector.Successor = rightReducer; rightReducer.Successor = subScopesCounter2; subScopesCounter2.ValueParameter.ActualName = CurrentPopulationSizeParameter.Name; subScopesCounter2.AccumulateParameter.Value = new BoolValue(false); return(eldersEmigrator); }
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 }
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; }