using HeuristicLab.Algorithms.ALPS; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Operators; using HeuristicLab.Optimization; using HeuristicLab.Optimization.Operators; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Selection; namespace HeuristicLab.Algorithms.IslandALPS { [Item("IslandALPSAlgorithmMainLoop", "An island ALPS main loop operator.")] [StorableClass] public class IslandAlpsAlgorthmsMainLoop : AlgorithmOperator{ [StorableConstructor] private IslandAlpsAlgorthmsMainLoop(bool deserializing) : base(deserializing) { } #region Parameter Properties public ValueLookupParameter GlobalRandomParameter { get { return (ValueLookupParameter)Parameters["GlobalRandom"]; } } public ValueLookupParameter IslandRandomParameter { get { return (ValueLookupParameter)Parameters["IslandRandom"]; } } public ValueLookupParameter LayerRandomParameter { get { return (ValueLookupParameter)Parameters["LayerRandom"]; } } public ValueLookupParameter MaximizationParameter { get { return (ValueLookupParameter)Parameters["Maximization"]; } } public ScopeTreeLookupParameter QualityParameter { get { return (ScopeTreeLookupParameter)Parameters["Quality"]; } } public ValueLookupParameter BestKnownQualityParameter { get { return (ValueLookupParameter)Parameters["BestKnownQuality"]; } } public ValueLookupParameter PopulationSizeParameter { get { return (ValueLookupParameter)Parameters["PopulationSize"]; } } public ValueLookupParameter SelectorParameter { get { return (ValueLookupParameter)Parameters["Selector"]; } } public ValueLookupParameter CrossoverParameter { get { return (ValueLookupParameter)Parameters["Crossover"]; } } public ValueLookupParameter MutationProbabilityParameter { get { return (ValueLookupParameter)Parameters["MutationProbability"]; } } public ValueLookupParameter MutatorParameter { get { return (ValueLookupParameter)Parameters["Mutator"]; } } public ValueLookupParameter EvaluatorParameter { get { return (ValueLookupParameter)Parameters["Evaluator"]; } } public ValueLookupParameter ElitesParameter { get { return (ValueLookupParameter)Parameters["Elites"]; } } public IValueLookupParameter ReevaluateElitesParameter { get { return (IValueLookupParameter)Parameters["ReevaluateElites"]; } } public ValueLookupParameter ResultsParameter { get { return (ValueLookupParameter)Parameters["Results"]; } } public ILookupParameter TerminatorParameter { get { return (ILookupParameter)Parameters["Terminator"]; } } public ValueLookupParameter AnalyzerParameter { get { return (ValueLookupParameter)Parameters["Analyzer"]; } } public ValueLookupParameter IslandAnalyzerParameter { get { return (ValueLookupParameter)Parameters["IslandAnalyzer"]; } } public ValueLookupParameter LayerAnalyzerParameter { get { return (ValueLookupParameter)Parameters["LayerAnalyzer"]; } } public ValueLookupParameter GroupAnalyzerParameter { get { return (ValueLookupParameter)Parameters["GroupAnalyzer"]; } } public LookupParameter LayerEvaluatedSolutionsParameter { get { return (LookupParameter)Parameters["LayerEvaluatedSolutions"]; } } public LookupParameter EvaluatedSolutions { get { return (LookupParameter)Parameters["EvaluatedSolutions"]; } } #region island public ValueLookupParameter NumberOfIslandsParameter { get { return (ValueLookupParameter)Parameters["NumberOfIslands"]; } } public ValueLookupParameter MigrationIntervalParameter { get { return (ValueLookupParameter)Parameters["MigrationInterval"]; } } public ValueLookupParameter MigrationRateParameter { get { return (ValueLookupParameter)Parameters["MigrationRate"]; } } public ValueLookupParameter MigratorParameter { get { return (ValueLookupParameter)Parameters["Migrator"]; } } public ValueLookupParameter EmigrantsSelectorParameter { get { return (ValueLookupParameter)Parameters["EmigrantsSelector"]; } } public ValueLookupParameter ImmigrationReplacerParameter { get { return (ValueLookupParameter)Parameters["ImmigrationReplacer"]; } } public ValueLookupParameter Migrate { get { return (ValueLookupParameter)Parameters["Migrate"]; } } public LookupParameter IslandEvaluatedSolutions { get { return (LookupParameter)Parameters["IslandEvaluatedSolutions"]; } } public LookupParameter IslandGenerations { get { return (LookupParameter)Parameters["IslandGenerations"]; } } #endregion #region alps public ILookupParameter CurrentPopulationSizeParameter { get { return (ILookupParameter)Parameters["CurrentPopulationSize"]; } } public IValueLookupParameter NumberOfLayersParameter { get { return (IValueLookupParameter)Parameters["NumberOfLayers"]; } } public IScopeTreeLookupParameter AgeParameter { get { return (IScopeTreeLookupParameter)Parameters["Age"]; } } public IValueLookupParameter AgeGapParameter { get { return (IValueLookupParameter)Parameters["AgeGap"]; } } public IValueLookupParameter AgeInheritanceParameter { get { return (IValueLookupParameter)Parameters["AgeInheritance"]; } } public IValueLookupParameter AgeLimitsParameter { get { return (IValueLookupParameter)Parameters["AgeLimits"]; } } public IValueLookupParameter MatingPoolRangeParameter { get { return (IValueLookupParameter)Parameters["MatingPoolRange"]; } } public IValueLookupParameter ReduceToPopulationSizeParameter { get { return (IValueLookupParameter)Parameters["ReduceToPopulationSize"]; } } public IValueLookupParameter PlusSelectionParameter { get { return (IValueLookupParameter)Parameters["PlusSelection"]; } } #endregion #endregion private IslandAlpsAlgorthmsMainLoop(IslandAlpsAlgorthmsMainLoop original, Cloner cloner) : base(original,cloner){ } public override IDeepCloneable Clone(Cloner cloner) { return new IslandAlpsAlgorthmsMainLoop(this,cloner); } public IslandAlpsAlgorthmsMainLoop() : base() { #region Create parameters Parameters.Add(new ValueLookupParameter("GlobalRandom", "A pseudo random number generator.")); Parameters.Add(new ValueLookupParameter("IslandRandom", "A pseudo random number generator.")); Parameters.Add(new ValueLookupParameter("LayerRandom", "A pseudo random number generator.")); Parameters.Add(new ValueLookupParameter("Maximization", "True if the problem is a maximization problem, otherwise false.")); Parameters.Add(new ScopeTreeLookupParameter("Quality", "The value which represents the quality of a solution.")); Parameters.Add(new ValueLookupParameter("BestKnownQuality", "The best known quality value found so far.")); Parameters.Add(new ValueLookupParameter("NumberOfLayers", "The number of Layers per Island.")); Parameters.Add(new ValueLookupParameter("NumberOfIslands", "The number of islands.")); Parameters.Add(new ValueLookupParameter("MigrationInterval", "The number of generations that should pass between migration phases.")); Parameters.Add(new ValueLookupParameter("MigrationRate", "The proportion of individuals that should migrate between the islands.")); Parameters.Add(new ValueLookupParameter("Migrator", "The migration strategy.")); Parameters.Add(new ValueLookupParameter("EmigrantsSelector", "Selects the individuals that will be migrated.")); Parameters.Add(new ValueLookupParameter("ImmigrationReplacer", "Replaces some of the original population with the immigrants.")); Parameters.Add(new ValueLookupParameter("PopulationSize", "The size of the population of solutions.")); Parameters.Add(new ValueLookupParameter("CurrentPopulationSize", "The current size of the population of solutions.")); Parameters.Add(new ValueLookupParameter("Selector", "The operator used to select solutions for reproduction.")); Parameters.Add(new ValueLookupParameter("Crossover", "The operator used to cross solutions.")); Parameters.Add(new ValueLookupParameter("MutationProbability", "The probability that the mutation operator is applied on a solution.")); Parameters.Add(new ValueLookupParameter("Mutator", "The operator used to mutate solutions.")); Parameters.Add(new ValueLookupParameter("Evaluator", "The operator used to evaluate solutions.")); Parameters.Add(new ValueLookupParameter("Elites", "The numer of elite solutions which are kept in each generation.")); Parameters.Add(new ValueLookupParameter("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)")); Parameters.Add(new ValueLookupParameter("Results", "The results collection to store the results.")); Parameters.Add(new ValueLookupParameter("Terminator", "The termination criteria that defines if the algorithm should continue or stop")); Parameters.Add(new ScopeTreeLookupParameter("Age", "The age of individuals.")); Parameters.Add(new ValueLookupParameter("AgeGap", "The frequency of reseeding the lowest layer and scaling factor for the age-limits for the layers.")); Parameters.Add(new ValueLookupParameter("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("AgeLimits", "The maximum age an individual is allowed to reach in a certain layer.")); Parameters.Add(new ValueLookupParameter("PlusSelection", "Include the parents in the selection of the invividuals for the next generation.")); Parameters.Add(new ValueLookupParameter("MatingPoolRange", "The range of sub - populations used for creating a mating pool. (1 = current + previous sub-population)")); Parameters.Add(new ValueLookupParameter("ReduceToPopulationSize", "Reduce the CurrentPopulationSize after elder migration to PopulationSize")); Parameters.Add(new ValueLookupParameter("Analyzer", "The operator used to the analyze the islands.")); Parameters.Add(new ValueLookupParameter("IslandAnalyzer", "The operator used to analyze each island.")); Parameters.Add(new ValueLookupParameter("LayerAnalyzer", "The operator used to analyze each Layer.")); Parameters.Add(new ValueLookupParameter("GroupAnalyzer", "The operator used to analyze each Layergroup.")); Parameters.Add(new LookupParameter("LayerEvaluatedSolutions", "The number of times a solution has been evaluated.")); Parameters.Add(new LookupParameter("IslandGenerations", "The number of generations calculated on one island.")); //TODO: make long ? Parameters.Add(new LookupParameter("IslandEvaluatedSolutions", "The number of times a solution has been evaluated on one island.")); Parameters.Add(new LookupParameter("EvaluatedSolutions", "The number of times a solution has been evaluated on one island.")); Parameters.Add(new ValueLookupParameter("Migrate", "Migrate the island?")); #endregion var globalVariableCreator = new VariableCreator() { Name = "Create global values" }; var islandVarCreatorUssp = new UniformSubScopesProcessor(); var islandVariableCreator = new VariableCreator() {Name = "Initialize Results"}; var groupVariableCreator = new VariableCreator() {Name = "Initialize Group Results"}; var layerUssp = new UniformSubScopesProcessor(); var layerVariableCreator = new VariableCreator() {}; var initLayerAnalyzerPlaceholder = new Placeholder() {Name = "Layer Analyzer (Placeholder)"}; var initIslandAnalyzerPlaceholder = new Placeholder() {Name = "Island Analyzer (Placeholder)"}; var initGlobalAnalyzerPlacerholder =new Placeholder() {Name = "Global Analyzer (Placeholder)"}; var resultsCollector = new ResultsCollector(); var processIslandsUssp = new UniformSubScopesProcessor() {Name = "Process Islands"}; var initIslandGenerationsAss = new Assigner() {Name = "Init Island Generations"}; var initIslandEvaluationsAss = new Assigner() {Name = "Init Island Evaluations"}; var incrementGenerationDr = new DataReducer() { Name = "Increment Generations" }; var incrementEvaluatedSolutionDr = new DataReducer() { Name = "Increment Evaluated Solutions" }; //TODO: increase migration count + migrate var elderMigrator = CreateEldersEmigrator(); var newLayerOpener = CreateLayerOpener(); var reseeder = CreateReseeder(); var analyzeLayerUssp = new UniformSubScopesProcessor(); var layerAnalyzerPlaceholder = new Placeholder() { Name = "Layer Analyzer (Placeholder)" }; var layerResultsCollector = new ResultsCollector() {Name = "Collect Additional Infos"}; var islandAnalyzerPlaceholder = new Placeholder() { Name = "Island Analyzer (Placeholder)" }; var islandResultsCollector = new ResultsCollector() { Name = "Collect layer results into IslandResults" }; var globalAnalyzerPlacerholder = new Placeholder() { Name = "Global Analyzer (Placeholder)" }; var groupingOperator = new GroupedLayerOperator() {Name = "Grouped Analyzer"}; var groupAnalyzer = new Placeholder() {Name = "Group Analyzer (Placeholder)"}; var groupResultsExtractor = new ResultsExtractor() {Name = "Collect group results into variable"}; var groupResultsCollector = new ResultsCollector() {Name = "Collect group results into into global results"}; var matingPoolCreator = new MatingPoolCreator(); var matingPoolUssp = new UniformSubScopesProcessor() {Name = "Process Mating Pools"}; var alpsMainOperator =new AlpsGeneticAlgorithmMainOperator(); var incrementIslandGeneration = new IntCounter() {Name = "incrementIslandGeneration" }; var setIslandEvaluatedSolutions = new DataReducer() {Name = "Set IslandEvaluatedSolutions" }; var migrateComparator = new Comparator(); var migrateCondBranch = new ConditionalBranch() {Name = "Migrate?"}; var terminator = new TerminationOperator(); globalVariableCreator.CollectedValues.Add(new ValueParameter("Generations",new IntValue(0))); globalVariableCreator.CollectedValues.Add(new ValueParameter("Migrations",new IntValue(0))); islandVariableCreator.CollectedValues.Add(new ValueParameter(IslandGenerations.Name, new IntValue(0))); islandVariableCreator.CollectedValues.Add(new ValueParameter("OpenLayers", new IntValue(1))); islandVariableCreator.CollectedValues.Add(new ValueParameter("IslandResults")); layerVariableCreator.CollectedValues.Add(new ValueParameter("Layer", new IntValue(0))); layerVariableCreator.CollectedValues.Add(new ValueParameter("LayerResults")); groupVariableCreator.CollectedValues.Add((new ValueParameter("GroupResults"))); //TODO: groupAnalyze initLayerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name; initIslandAnalyzerPlaceholder.OperatorParameter.ActualName = IslandAnalyzerParameter.Name; initGlobalAnalyzerPlacerholder.OperatorParameter.ActualName = AnalyzerParameter.Name; resultsCollector.CollectedValues.Add(new LookupParameter("Generations")); resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter("IslandResults","","IslandResults")); resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter("GroupResults","","GroupResults")); resultsCollector.CopyValue = new BoolValue(false); initIslandGenerationsAss.LeftSideParameter.ActualName = IslandGenerations.Name; initIslandGenerationsAss.RightSideParameter.Value = new IntValue(0); initIslandEvaluationsAss.LeftSideParameter.ActualName = IslandEvaluatedSolutions.Name; initIslandEvaluationsAss.RightSideParameter.Value = new IntValue(0); incrementGenerationDr.TargetParameter.ActualName = "Generations"; incrementGenerationDr.ParameterToReduce.ActualName = IslandGenerations.Name; incrementGenerationDr.TargetOperation.Value = new ReductionOperation(ReductionOperations.Sum); incrementGenerationDr.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Min); incrementEvaluatedSolutionDr.ParameterToReduce.ActualName = IslandEvaluatedSolutions.Name; incrementEvaluatedSolutionDr.TargetParameter.ActualName = EvaluatedSolutions.Name; incrementEvaluatedSolutionDr.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum); incrementEvaluatedSolutionDr.TargetOperation.Value = new ReductionOperation(ReductionOperations.Sum); incrementIslandGeneration.ValueParameter.ActualName = IslandGenerations.Name; setIslandEvaluatedSolutions.ParameterToReduce.ActualName = LayerEvaluatedSolutionsParameter.Name; setIslandEvaluatedSolutions.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum); setIslandEvaluatedSolutions.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign); setIslandEvaluatedSolutions.TargetParameter.ActualName = IslandEvaluatedSolutions.Name; migrateComparator.Comparison.Value = ComparisonType.GreaterOrEqual; migrateComparator.LeftSideParameter.ActualName = IslandGenerations.Name; migrateComparator.RightSideParameter.ActualName = MigrationIntervalParameter.Name; migrateComparator.ResultParameter.ActualName = "Migrate"; migrateCondBranch.ConditionParameter.ActualName = "Migrate"; groupAnalyzer.OperatorParameter.ActualName = GroupAnalyzerParameter.Name; layerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name; layerResultsCollector.ResultsParameter.ActualName = "LayerResults"; layerResultsCollector.CollectedValues.Add(new LookupParameter("Layer")); islandAnalyzerPlaceholder.OperatorParameter.ActualName = IslandAnalyzerParameter.Name; islandResultsCollector.ResultsParameter.ActualName = "IslandResults"; islandResultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter("LayerResults")); globalAnalyzerPlacerholder.OperatorParameter.ActualName = AnalyzerParameter.Name; //TODO: implement check for grouped layer analyzer groupResultsExtractor.SourceNameParameter.Value = new StringValue("GroupScope"); groupResultsExtractor.TargetNameParameter.Value = new StringValue("GroupResults"); groupResultsCollector.CollectedValues.Add(new LookupParameter>("GroupResults")); matingPoolCreator.MatingPoolRangeParameter.ActualName = MatingPoolRangeParameter.Name; alpsMainOperator.RandomParameter.ActualName = LayerRandomParameter.Name; alpsMainOperator.EvaluatorParameter.ActualName = EvaluatorParameter.Name; alpsMainOperator.EvaluatedSolutionsParameter.ActualName = LayerEvaluatedSolutionsParameter.Name; alpsMainOperator.QualityParameter.ActualName = QualityParameter.Name; alpsMainOperator.MaximizationParameter.ActualName = MaximizationParameter.Name; alpsMainOperator.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name; alpsMainOperator.SelectorParameter.ActualName = SelectorParameter.Name; alpsMainOperator.CrossoverParameter.ActualName = CrossoverParameter.Name; alpsMainOperator.MutatorParameter.ActualName = MutatorParameter.ActualName; alpsMainOperator.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name; alpsMainOperator.ElitesParameter.ActualName = ElitesParameter.Name; alpsMainOperator.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name; alpsMainOperator.PlusSelectionParameter.ActualName = PlusSelectionParameter.Name; alpsMainOperator.AgeParameter.ActualName = AgeParameter.Name; alpsMainOperator.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name; alpsMainOperator.AgeIncrementParameter.Value = new DoubleValue(1.0); //flow OperatorGraph.InitialOperator = globalVariableCreator; globalVariableCreator.Successor = islandVarCreatorUssp; islandVarCreatorUssp.Operator = islandVariableCreator; islandVariableCreator.Successor = layerUssp; layerUssp.Operator = layerVariableCreator; layerVariableCreator.Successor = initLayerAnalyzerPlaceholder; initLayerAnalyzerPlaceholder.Successor = null; layerUssp.Successor = initIslandAnalyzerPlaceholder; initLayerAnalyzerPlaceholder.Successor = null; islandVarCreatorUssp.Successor = initGlobalAnalyzerPlacerholder; initGlobalAnalyzerPlacerholder.Successor = resultsCollector; resultsCollector.Successor = processIslandsUssp; processIslandsUssp.Operator = initIslandGenerationsAss; initIslandGenerationsAss.Successor = initIslandEvaluationsAss; initIslandEvaluationsAss.Successor = matingPoolCreator; matingPoolCreator.Successor = matingPoolUssp; matingPoolUssp.Operator = alpsMainOperator; alpsMainOperator.Successor = null; matingPoolUssp.Successor = elderMigrator; elderMigrator.Successor = newLayerOpener; newLayerOpener.Successor = reseeder; reseeder.Successor = analyzeLayerUssp; analyzeLayerUssp.Operator = layerAnalyzerPlaceholder; layerAnalyzerPlaceholder.Successor = layerResultsCollector; layerResultsCollector.Successor = null; analyzeLayerUssp.Successor = islandAnalyzerPlaceholder; islandAnalyzerPlaceholder.Successor = islandResultsCollector; islandResultsCollector.Successor = setIslandEvaluatedSolutions; setIslandEvaluatedSolutions.Successor = incrementIslandGeneration; incrementIslandGeneration.Successor = migrateComparator; migrateComparator.Successor = migrateCondBranch; migrateCondBranch.FalseBranch = matingPoolCreator; migrateCondBranch.TrueBranch = null; processIslandsUssp.Successor = incrementGenerationDr; incrementGenerationDr.Successor = incrementEvaluatedSolutionDr; incrementEvaluatedSolutionDr.Successor = globalAnalyzerPlacerholder; globalAnalyzerPlacerholder.Successor = groupingOperator; groupingOperator.Operator = groupAnalyzer; groupAnalyzer.Successor = null; groupingOperator.Successor = groupResultsExtractor; groupResultsExtractor.Successor = groupResultsCollector; groupResultsCollector.Successor = terminator; terminator.ContinueBranch = processIslandsUssp; } 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(PopulationSizeParameter.Name)); countCalculator.CollectedValues.Add(new LookupParameter(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; } 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 AlpsGeneticAlgorithmMainOperator(); 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(AgeLimitsParameter.Name)); openNewLayerCalculator.CollectedValues.Add(new LookupParameter("Generations")); openNewLayerCalculator.CollectedValues.Add(new LookupParameter(NumberOfLayersParameter.Name)); openNewLayerCalculator.CollectedValues.Add(new LookupParameter("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 = LayerRandomParameter.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.Name; createChildrenViaCrossover.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name; createChildrenViaCrossover.ElitesParameter.ActualName = ElitesParameter.Name; createChildrenViaCrossover.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name; createChildrenViaCrossover.PlusSelectionParameter.ActualName = PlusSelectionParameter.Name; createChildrenViaCrossover.AgeParameter.ActualName = AgeParameter.Name; createChildrenViaCrossover.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name; createChildrenViaCrossover.AgeIncrementParameter.Value = new DoubleValue(0.0); createChildrenViaCrossover.Successor = incrEvaluatedSolutionsForNewLayer; incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = LayerEvaluatedSolutionsParameter.Name; incrEvaluatedSolutionsForNewLayer.AccumulateParameter.Value = new BoolValue(true); incrOpenLayers.ValueParameter.ActualName = "OpenLayers"; incrOpenLayers.Increment = new IntValue(1); return layerOpener; } 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 initializeAgeProsessor = new UniformSubScopesProcessor(); var initializeAge = new VariableCreator() { Name = "Initialize Age" }; var incrEvaluatedSolutionsAfterReseeding = new SubScopesCounter() { Name = "Update EvaluatedSolutions" }; 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 = initializeAgeProsessor; initializeAgeProsessor.Operator = initializeAge; initializeAgeProsessor.Successor = incrEvaluatedSolutionsAfterReseeding; initializeAge.CollectedValues.Add(new ValueParameter(AgeParameter.Name, new DoubleValue(0))); incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = LayerEvaluatedSolutionsParameter.Name; incrEvaluatedSolutionsAfterReseeding.AccumulateParameter.Value = new BoolValue(true); return reseeder; } } }