protected ExpressionCalculator(ExpressionCalculator original, Cloner cloner) : base(original, cloner) { this.Calculator = cloner.Clone(original.Calculator); }
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 AlpsOffspringSelectionGeneticAlgorithmMainOperator(); 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; // Maybe use only crossover and no elitism instead of "default operator" createChildrenViaCrossover.RandomParameter.ActualName = LocalRandomParameter.Name; createChildrenViaCrossover.EvaluatorParameter.ActualName = EvaluatorParameter.Name; createChildrenViaCrossover.EvaluatedSolutionsParameter.ActualName = "LayerEvaluatedSolutions"; createChildrenViaCrossover.QualityParameter.ActualName = QualityParameter.Name; createChildrenViaCrossover.MaximizationParameter.ActualName = MaximizationParameter.Name; createChildrenViaCrossover.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name; createChildrenViaCrossover.SelectorParameter.ActualName = SelectorParameter.Name; createChildrenViaCrossover.CrossoverParameter.ActualName = CrossoverParameter.Name; createChildrenViaCrossover.MutatorParameter.ActualName = MutatorParameter.ActualName; createChildrenViaCrossover.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name; createChildrenViaCrossover.ElitesParameter.ActualName = ElitesParameter.Name; createChildrenViaCrossover.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name; createChildrenViaCrossover.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name; createChildrenViaCrossover.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name; createChildrenViaCrossover.CurrentSuccessRatioParameter.ActualName = "CurrentSuccessRatio"; createChildrenViaCrossover.SelectionPressureParameter.ActualName = "SelectionPressure"; createChildrenViaCrossover.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name; createChildrenViaCrossover.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name; createChildrenViaCrossover.FillPopulationWithParentsParameter.ActualName = FillPopulationWithParentsParameter.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 CombinedOperator CreateEldersEmigrator() { var eldersEmigrator = new CombinedOperator() { Name = "Emigrate Elders" }; var selectorProsessor = new UniformSubScopesProcessor(); var eldersSelector = new EldersSelector(); var shiftToRightMigrator = new UnidirectionalRingMigrator() { Name = "Shift elders to next layer" }; var mergingProsessor = new UniformSubScopesProcessor(); var mergingReducer = new MergingReducer(); var subScopesCounter = new SubScopesCounter(); var reduceToPopulationSizeBranch = new ConditionalBranch() { Name = "ReduceToPopulationSize?" }; var countCalculator = new ExpressionCalculator() { Name = "CurrentPopulationSize = Min(CurrentPopulationSize, PopulationSize)" }; var bestSelector = new BestSelector(); var rightReducer = new RightReducer(); eldersEmigrator.OperatorGraph.InitialOperator = selectorProsessor; selectorProsessor.Operator = eldersSelector; selectorProsessor.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 = mergingProsessor; mergingProsessor.Operator = mergingReducer; mergingReducer.Successor = subScopesCounter; subScopesCounter.ValueParameter.ActualName = CurrentPopulationSizeParameter.Name; subScopesCounter.AccumulateParameter.Value = new BoolValue(false); subScopesCounter.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 = bestSelector; bestSelector.NumberOfSelectedSubScopesParameter.ActualName = CurrentPopulationSizeParameter.Name; bestSelector.CopySelected = new BoolValue(false); bestSelector.Successor = rightReducer; return eldersEmigrator; }
protected ExpressionCalculator(ExpressionCalculator original, Cloner cloner) : base(original, cloner) { this.Calculator = cloner.Clone(original.Calculator); }
private void Initialize() { #region Create parameters Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator.")); Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false.")); Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution.")); 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>("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>("Elites", "The numer of elite solutions which are kept in each generation.")); Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)")); 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 ValueLookupParameter<IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated.")); Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population.")); Parameters.Add(new ValueLookupParameter<IntValue>("MinimumPopulationSize", "The minimum size of the population of solutions.")); Parameters.Add(new ValueLookupParameter<IntValue>("MaximumPopulationSize", "The maximum size of the population of solutions.")); Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactor", "The comparison factor.")); Parameters.Add(new ValueLookupParameter<IntValue>("Effort", "The maximum number of offspring created in each generation.")); Parameters.Add(new ValueLookupParameter<IntValue>("BatchSize", "The number of children that should be created during one iteration of the offspring creation process.")); Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions.")); Parameters.Add(new ScopeParameter("CurrentScope", "The current scope which represents a population of solutions on which the genetic algorithm should be applied.")); #endregion #region Create operators VariableCreator variableCreator = new VariableCreator(); Assigner assigner1 = new Assigner(); ResultsCollector resultsCollector = new ResultsCollector(); Placeholder analyzer1 = new Placeholder(); Placeholder selector = new Placeholder(); SubScopesProcessor subScopesProcessor1 = new SubScopesProcessor(); ChildrenCreator childrenCreator = new ChildrenCreator(); UniformSubScopesProcessor uniformSubScopesProcessor = new UniformSubScopesProcessor(); Placeholder crossover = new Placeholder(); StochasticBranch stochasticBranch = new StochasticBranch(); Placeholder mutator = new Placeholder(); Placeholder evaluator = new Placeholder(); WeightedParentsQualityComparator weightedParentsQualityComparator = new WeightedParentsQualityComparator(); SubScopesRemover subScopesRemover = new SubScopesRemover(); IntCounter intCounter1 = new IntCounter(); IntCounter intCounter2 = new IntCounter(); ConditionalSelector conditionalSelector = new ConditionalSelector(); RightReducer rightReducer1 = new RightReducer(); DuplicatesSelector duplicateSelector = new DuplicatesSelector(); LeftReducer leftReducer1 = new LeftReducer(); ProgressiveOffspringPreserver progressiveOffspringSelector = new ProgressiveOffspringPreserver(); SubScopesCounter subScopesCounter2 = new SubScopesCounter(); ExpressionCalculator calculator1 = new ExpressionCalculator(); ConditionalBranch conditionalBranch1 = new ConditionalBranch(); Comparator comparator1 = new Comparator(); ConditionalBranch conditionalBranch2 = new ConditionalBranch(); LeftReducer leftReducer2 = new LeftReducer(); SubScopesProcessor subScopesProcessor2 = new SubScopesProcessor(); BestSelector bestSelector = new BestSelector(); RightReducer rightReducer2 = new RightReducer(); ScopeCleaner scopeCleaner = new ScopeCleaner(); ScopeRestorer scopeRestorer = new ScopeRestorer(); MergingReducer mergingReducer = new MergingReducer(); IntCounter intCounter3 = new IntCounter(); SubScopesCounter subScopesCounter3 = new SubScopesCounter(); ExpressionCalculator calculator2 = new ExpressionCalculator(); Comparator comparator2 = new Comparator(); ConditionalBranch conditionalBranch3 = new ConditionalBranch(); Placeholder analyzer2 = new Placeholder(); Comparator comparator3 = new Comparator(); ConditionalBranch conditionalBranch4 = new ConditionalBranch(); Comparator comparator4 = new Comparator(); ConditionalBranch conditionalBranch5 = new ConditionalBranch(); Assigner assigner3 = new Assigner(); Assigner assigner4 = new Assigner(); Assigner assigner5 = new Assigner(); ConditionalBranch reevaluateElitesBranch = new ConditionalBranch(); UniformSubScopesProcessor uniformSubScopesProcessor2 = new UniformSubScopesProcessor(); Placeholder evaluator2 = new Placeholder(); SubScopesCounter subScopesCounter4 = new SubScopesCounter(); variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); // Class RAPGA expects this to be called Generations variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("CurrentPopulationSize", new IntValue(0))); variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("NumberOfCreatedOffspring", new IntValue(0))); variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("NumberOfSuccessfulOffspring", new IntValue(0))); variableCreator.CollectedValues.Add(new ValueParameter<ScopeList>("OffspringList", new ScopeList())); assigner1.Name = "Initialize CurrentPopulationSize"; assigner1.LeftSideParameter.ActualName = "CurrentPopulationSize"; assigner1.RightSideParameter.ActualName = PopulationSizeParameter.Name; resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Generations")); resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("CurrentPopulationSize")); resultsCollector.ResultsParameter.ActualName = "Results"; analyzer1.Name = "Analyzer"; analyzer1.OperatorParameter.ActualName = "Analyzer"; selector.Name = "Selector"; selector.OperatorParameter.ActualName = "Selector"; childrenCreator.ParentsPerChild = new IntValue(2); uniformSubScopesProcessor.Parallel.Value = true; crossover.Name = "Crossover"; crossover.OperatorParameter.ActualName = "Crossover"; stochasticBranch.ProbabilityParameter.ActualName = "MutationProbability"; stochasticBranch.RandomParameter.ActualName = "Random"; mutator.Name = "Mutator"; mutator.OperatorParameter.ActualName = "Mutator"; evaluator.Name = "Evaluator"; evaluator.OperatorParameter.ActualName = "Evaluator"; weightedParentsQualityComparator.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name; weightedParentsQualityComparator.LeftSideParameter.ActualName = QualityParameter.Name; weightedParentsQualityComparator.MaximizationParameter.ActualName = MaximizationParameter.Name; weightedParentsQualityComparator.RightSideParameter.ActualName = QualityParameter.Name; weightedParentsQualityComparator.ResultParameter.ActualName = "SuccessfulOffspring"; subScopesRemover.RemoveAllSubScopes = true; intCounter1.Name = "Increment NumberOfCreatedOffspring"; intCounter1.ValueParameter.ActualName = "NumberOfCreatedOffspring"; intCounter1.Increment = null; intCounter1.IncrementParameter.ActualName = BatchSizeParameter.Name; intCounter2.Name = "Increment EvaluatedSolutions"; intCounter2.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name; intCounter2.Increment = null; intCounter2.IncrementParameter.ActualName = BatchSizeParameter.Name; conditionalSelector.ConditionParameter.ActualName = "SuccessfulOffspring"; conditionalSelector.ConditionParameter.Depth = 1; conditionalSelector.CopySelected.Value = false; duplicateSelector.CopySelected.Value = false; progressiveOffspringSelector.OffspringListParameter.ActualName = "OffspringList"; progressiveOffspringSelector.ElitesParameter.ActualName = ElitesParameter.Name; progressiveOffspringSelector.MaximumPopulationSizeParameter.ActualName = MaximumPopulationSizeParameter.Name; subScopesCounter2.Name = "Count Successful Offspring"; subScopesCounter2.ValueParameter.ActualName = "NumberOfSuccessfulOffspring"; calculator1.Name = "NumberOfSuccessfulOffspring == MaximumPopulationSize - Elites"; calculator1.CollectedValues.Add(new ValueLookupParameter<IntValue>("NumberOfSuccessfulOffspring")); calculator1.CollectedValues.Add(new ValueLookupParameter<IntValue>("MaximumPopulationSize")); calculator1.CollectedValues.Add(new ValueLookupParameter<IntValue>("Elites")); calculator1.ExpressionParameter.Value = new StringValue("NumberOfSuccessfulOffspring MaximumPopulationSize Elites - =="); calculator1.ExpressionResultParameter.ActualName = "Break"; conditionalBranch1.Name = "Break?"; conditionalBranch1.ConditionParameter.ActualName = "Break"; comparator1.Name = "NumberOfCreatedOffspring >= Effort"; comparator1.Comparison = new Comparison(ComparisonType.GreaterOrEqual); comparator1.LeftSideParameter.ActualName = "NumberOfCreatedOffspring"; comparator1.RightSideParameter.ActualName = EffortParameter.Name; comparator1.ResultParameter.ActualName = "Break"; conditionalBranch2.Name = "Break?"; conditionalBranch2.ConditionParameter.ActualName = "Break"; bestSelector.CopySelected = new BoolValue(false); bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name; bestSelector.NumberOfSelectedSubScopesParameter.ActualName = "Elites"; bestSelector.QualityParameter.ActualName = QualityParameter.Name; intCounter3.Name = "Increment Generations"; intCounter3.Increment = new IntValue(1); intCounter3.ValueParameter.ActualName = "Generations"; subScopesCounter3.Name = "Update CurrentPopulationSize"; subScopesCounter3.ValueParameter.ActualName = "CurrentPopulationSize"; subScopesCounter3.AccumulateParameter.Value = new BoolValue(false); calculator2.Name = "Evaluate ActualSelectionPressure"; calculator2.CollectedValues.Add(new ValueLookupParameter<IntValue>("NumberOfCreatedOffspring")); calculator2.CollectedValues.Add(new ValueLookupParameter<IntValue>("Elites")); calculator2.CollectedValues.Add(new ValueLookupParameter<IntValue>("CurrentPopulationSize")); calculator2.ExpressionParameter.Value = new StringValue("NumberOfCreatedOffspring Elites + CurrentPopulationSize /"); calculator2.ExpressionResultParameter.ActualName = "ActualSelectionPressure"; comparator2.Name = "CurrentPopulationSize < 1"; comparator2.Comparison = new Comparison(ComparisonType.Less); comparator2.LeftSideParameter.ActualName = "CurrentPopulationSize"; comparator2.RightSideParameter.Value = new IntValue(1); comparator2.ResultParameter.ActualName = "Terminate"; conditionalBranch3.Name = "Terminate?"; conditionalBranch3.ConditionParameter.ActualName = "Terminate"; analyzer2.Name = "Analyzer"; analyzer2.OperatorParameter.ActualName = "Analyzer"; comparator3.Name = "Generations >= MaximumGenerations"; comparator3.Comparison = new Comparison(ComparisonType.GreaterOrEqual); comparator3.LeftSideParameter.ActualName = "Generations"; comparator3.ResultParameter.ActualName = "Terminate"; comparator3.RightSideParameter.ActualName = MaximumGenerationsParameter.Name; conditionalBranch4.Name = "Terminate?"; conditionalBranch4.ConditionParameter.ActualName = "Terminate"; comparator4.Name = "CurrentPopulationSize < MinimumPopulationSize"; comparator4.Comparison = new Comparison(ComparisonType.Less); comparator4.LeftSideParameter.ActualName = "CurrentPopulationSize"; comparator4.RightSideParameter.ActualName = MinimumPopulationSizeParameter.Name; comparator4.ResultParameter.ActualName = "Terminate"; conditionalBranch5.Name = "Terminate?"; conditionalBranch5.ConditionParameter.ActualName = "Terminate"; assigner3.Name = "Reset NumberOfCreatedOffspring"; assigner3.LeftSideParameter.ActualName = "NumberOfCreatedOffspring"; assigner3.RightSideParameter.Value = new IntValue(0); assigner4.Name = "Reset NumberOfSuccessfulOffspring"; assigner4.LeftSideParameter.ActualName = "NumberOfSuccessfulOffspring"; assigner4.RightSideParameter.Value = new IntValue(0); assigner5.Name = "Reset OffspringList"; assigner5.LeftSideParameter.ActualName = "OffspringList"; assigner5.RightSideParameter.Value = new ScopeList(); reevaluateElitesBranch.ConditionParameter.ActualName = "ReevaluateElites"; reevaluateElitesBranch.Name = "Reevaluate elites ?"; uniformSubScopesProcessor2.Parallel.Value = true; evaluator2.Name = "Evaluator (placeholder)"; evaluator2.OperatorParameter.ActualName = EvaluatorParameter.Name; subScopesCounter4.Name = "Increment EvaluatedSolutions"; subScopesCounter4.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name; #endregion #region Create operator graph OperatorGraph.InitialOperator = variableCreator; variableCreator.Successor = assigner1; assigner1.Successor = resultsCollector; resultsCollector.Successor = analyzer1; analyzer1.Successor = selector; selector.Successor = subScopesProcessor1; subScopesProcessor1.Operators.Add(new EmptyOperator()); subScopesProcessor1.Operators.Add(childrenCreator); subScopesProcessor1.Successor = calculator1; childrenCreator.Successor = uniformSubScopesProcessor; uniformSubScopesProcessor.Operator = crossover; uniformSubScopesProcessor.Successor = intCounter1; crossover.Successor = stochasticBranch; stochasticBranch.FirstBranch = mutator; stochasticBranch.SecondBranch = null; mutator.Successor = null; stochasticBranch.Successor = evaluator; evaluator.Successor = weightedParentsQualityComparator; weightedParentsQualityComparator.Successor = subScopesRemover; intCounter1.Successor = intCounter2; intCounter2.Successor = conditionalSelector; conditionalSelector.Successor = rightReducer1; rightReducer1.Successor = duplicateSelector; duplicateSelector.Successor = leftReducer1; leftReducer1.Successor = progressiveOffspringSelector; progressiveOffspringSelector.Successor = subScopesCounter2; calculator1.Successor = conditionalBranch1; conditionalBranch1.FalseBranch = comparator1; conditionalBranch1.TrueBranch = subScopesProcessor2; comparator1.Successor = conditionalBranch2; conditionalBranch2.FalseBranch = leftReducer2; conditionalBranch2.TrueBranch = subScopesProcessor2; leftReducer2.Successor = selector; subScopesProcessor2.Operators.Add(bestSelector); subScopesProcessor2.Operators.Add(scopeCleaner); subScopesProcessor2.Successor = mergingReducer; bestSelector.Successor = rightReducer2; rightReducer2.Successor = reevaluateElitesBranch; reevaluateElitesBranch.TrueBranch = uniformSubScopesProcessor2; uniformSubScopesProcessor2.Operator = evaluator2; uniformSubScopesProcessor2.Successor = subScopesCounter4; evaluator2.Successor = null; subScopesCounter4.Successor = null; reevaluateElitesBranch.FalseBranch = null; reevaluateElitesBranch.Successor = null; scopeCleaner.Successor = scopeRestorer; mergingReducer.Successor = intCounter3; intCounter3.Successor = subScopesCounter3; subScopesCounter3.Successor = calculator2; calculator2.Successor = comparator2; comparator2.Successor = conditionalBranch3; conditionalBranch3.FalseBranch = analyzer2; conditionalBranch3.TrueBranch = null; analyzer2.Successor = comparator3; comparator3.Successor = conditionalBranch4; conditionalBranch4.FalseBranch = comparator4; conditionalBranch4.TrueBranch = null; conditionalBranch4.Successor = null; comparator4.Successor = conditionalBranch5; conditionalBranch5.FalseBranch = assigner3; conditionalBranch5.TrueBranch = null; conditionalBranch5.Successor = null; assigner3.Successor = assigner4; assigner4.Successor = assigner5; assigner5.Successor = selector; #endregion }
public AlpsGeneticAlgorithmMainOperator() : 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<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 ValueLookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.")); Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)")); Parameters.Add(new ValueLookupParameter<BoolValue>("PlusSelection", "Include the parents in the selection of the invividuals for the next generation.")); 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.")); var numberOfSelectedParentsCalculator = new ExpressionCalculator() { Name = "NumberOfSelectedParents = 2 * (PopulationSize - (PlusSelection ? 0 : Elites))" }; var selector = new Placeholder() { Name = "Selector (Placeholder)" }; var subScopesProcessor1 = new SubScopesProcessor(); var childrenCreator = new ChildrenCreator(); var uniformSubScopesProcessor1 = new UniformSubScopesProcessor(); var crossover = new Placeholder() { Name = "Crossover (Placeholder)" }; var stochasticBranch = 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 replacementBranch = new ConditionalBranch() { Name = "PlusSelection?" }; var replacementMergingReducer = new MergingReducer(); var replacementBestSelector = new BestSelector(); var replacementRightReducer = new RightReducer(); var subScopesProcessor2 = new SubScopesProcessor(); var bestSelector = new BestSelector(); var rightReducer = new RightReducer(); var mergingReducer = new MergingReducer(); var reevaluateElitesBranch = new ConditionalBranch() { Name = "Reevaluate elites ?" }; var incrementAgeProcessor = new UniformSubScopesProcessor(); var ageIncrementor = new DoubleCounter() { Name = "Increment Age" }; OperatorGraph.InitialOperator = numberOfSelectedParentsCalculator; numberOfSelectedParentsCalculator.CollectedValues.Add(new LookupParameter<IntValue>(PopulationSizeParameter.Name)); numberOfSelectedParentsCalculator.CollectedValues.Add(new LookupParameter<IntValue>(ElitesParameter.Name)); numberOfSelectedParentsCalculator.CollectedValues.Add(new LookupParameter<BoolValue>(PlusSelectionParameter.Name)); numberOfSelectedParentsCalculator.ExpressionResultParameter.ActualName = "NumberOfSelectedSubScopes"; numberOfSelectedParentsCalculator.ExpressionParameter.Value = new StringValue("PopulationSize 0 Elites PlusSelection if - 2 * toint"); numberOfSelectedParentsCalculator.Successor = selector; selector.OperatorParameter.ActualName = SelectorParameter.Name; selector.Successor = subScopesProcessor1; subScopesProcessor1.Operators.Add(new EmptyOperator()); subScopesProcessor1.Operators.Add(childrenCreator); subScopesProcessor1.Successor = replacementBranch; childrenCreator.ParentsPerChild = new IntValue(2); childrenCreator.Successor = uniformSubScopesProcessor1; uniformSubScopesProcessor1.Operator = crossover; uniformSubScopesProcessor1.Successor = uniformSubScopesProcessor2; crossover.OperatorParameter.ActualName = CrossoverParameter.Name; crossover.Successor = stochasticBranch; stochasticBranch.ProbabilityParameter.ActualName = MutationProbabilityParameter.Name; stochasticBranch.RandomParameter.ActualName = RandomParameter.Name; stochasticBranch.FirstBranch = mutator; stochasticBranch.SecondBranch = null; stochasticBranch.Successor = ageCalculator; 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; replacementBranch.ConditionParameter.ActualName = PlusSelectionParameter.Name; replacementBranch.TrueBranch = replacementMergingReducer; replacementBranch.FalseBranch = subScopesProcessor2; replacementBranch.Successor = incrementAgeProcessor; replacementMergingReducer.Successor = replacementBestSelector; replacementBestSelector.NumberOfSelectedSubScopesParameter.ActualName = PopulationSizeParameter.Name; replacementBestSelector.CopySelected = new BoolValue(false); replacementBestSelector.Successor = replacementRightReducer; replacementRightReducer.Successor = reevaluateElitesBranch; subScopesProcessor2.Operators.Add(bestSelector); subScopesProcessor2.Operators.Add(new EmptyOperator()); subScopesProcessor2.Successor = mergingReducer; bestSelector.CopySelected = new BoolValue(false); bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name; bestSelector.NumberOfSelectedSubScopesParameter.ActualName = ElitesParameter.Name; bestSelector.QualityParameter.ActualName = QualityParameter.Name; bestSelector.Successor = rightReducer; rightReducer.Successor = reevaluateElitesBranch; mergingReducer.Successor = null; reevaluateElitesBranch.ConditionParameter.ActualName = ReevaluateElitesParameter.Name; reevaluateElitesBranch.TrueBranch = uniformSubScopesProcessor2; reevaluateElitesBranch.FalseBranch = null; reevaluateElitesBranch.Successor = null; incrementAgeProcessor.Operator = ageIncrementor; incrementAgeProcessor.Successor = null; ageIncrementor.ValueParameter.ActualName = AgeParameter.Name; ageIncrementor.IncrementParameter.Value = null; ageIncrementor.IncrementParameter.ActualName = AgeIncrementParameter.Name; ageIncrementor.Successor = null; }