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("IslandAlpsOffspringSelectionAlgorithmMainLoop", "An island ALPS offspring selection main loop operator.")] [StorableClass] public class IslandAlpsOffspringSelectionAlgorithmMainLoop : AlgorithmOperator { private const string LayerResultsParametername = "LayerResults"; private const string GenerationsParametername = "Generations"; private const string IslandResultsParametername = "IslandResults"; private const string LayerParametername = "Layer"; private const string MigrationsParametername = "Migrations"; private const string OpenLayersParametername = "OpenLayers"; private const string GroupResultsParametername = "GroupResults"; private const string MigrationThresholdParametername = "MigrationThreshold"; private const string MigrateParametername = "Migrate"; private const string LayerEvaluatedSolutionsParameterName = "LayerEvaluatedSolutions"; [StorableConstructor] private IslandAlpsOffspringSelectionAlgorithmMainLoop(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[LayerEvaluatedSolutionsParameterName]; } } 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[MigrateParametername]; } } public LookupParameter IslandEvaluatedSolutions { get { return (LookupParameter) Parameters["IslandEvaluatedSolutions"]; } } #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"]; } } #endregion #region OS public ILookupParameter ComparisonFactorParameter { get { return (ILookupParameter) Parameters["ComparisonFactor"]; } } public IValueLookupParameter SuccessRatioParameter { get { return (IValueLookupParameter) Parameters["SuccessRatio"]; } } public IValueLookupParameter MaximumSelectionPressureParameter { get { return (IValueLookupParameter) Parameters["MaximumSelectionPressure"]; } } public IValueLookupParameter OffspringSelectionBeforeMutationParameter { get { return (IValueLookupParameter) Parameters["OffspringSelectionBeforeMutation"]; } } public IValueLookupParameter FillPopulationWithParentsParameter { get { return (IValueLookupParameter) Parameters["FillPopulationWithParents"]; } } public ILookupParameter CurrentSuccessRatioParameter { get { return (ILookupParameter) Parameters["CurrentSuccessRatio"]; } } public ILookupParameter SelectionPressureParameter { get { return (ILookupParameter) Parameters["SelectionPressure"]; } } #endregion #endregion private IslandAlpsOffspringSelectionAlgorithmMainLoop(IslandAlpsOffspringSelectionAlgorithmMainLoop original, Cloner cloner) : base(original, cloner) {} public override IDeepCloneable Clone(Cloner cloner) { return new IslandAlpsOffspringSelectionAlgorithmMainLoop(this, cloner); } public IslandAlpsOffspringSelectionAlgorithmMainLoop() { AddParameters(); #region create Operators 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", Parallel = new BoolValue(true)}; var initIslandEvaluationsAss = new Assigner {Name = "Init Island Evaluations"}; var incrementGenerationDr = new IntCounter {Name = "Increment Generations"}; var incrementEvaluatedSolutionDr = new DataReducer {Name = "Increment Evaluated Solutions"}; 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 groupLayerNumberResultsCollector = new ResultsCollector {Name = "Add Layernumber to Results"}; var matingPoolCreator = new MatingPoolCreator(); var matingPoolUssp = new UniformSubScopesProcessor {Name = "Process Mating Pools"}; var alpsMainOperator = new AlpsOffspringSelectionGeneticAlgorithmMainOperator(); var setIslandEvaluatedSolutions = new DataReducer {Name = "Set IslandEvaluatedSolutions"}; var migrationThresholdCounter = new IntCounter {Name = "Increment Counter for Migrations"}; var migrationThresholdAss = new Assigner {Name = "Reset Counter for Migrations"}; var migrationCounter = new IntCounter {Name = "Increment Migrations"}; var selectforMigrationUssp = new UniformSubScopesProcessor(); var emigrantSelector = new Placeholder {Name = "Emigrant Selector (Placeholder)"}; var migrator = new LayerMigrator(); var replaceforMigrationUssp = new UniformSubScopesProcessor(); var immigrantSelector = new Placeholder {Name = "Immigrant Replacer (Placeholder)"}; var migrateComparator = new Comparator(); var migrateCondBranch = new ConditionalBranch {Name = "Migrate?"}; var terminator = new TerminationOperator(); #endregion globalVariableCreator.CollectedValues.Add(new ValueParameter(GenerationsParametername, new IntValue(1))); globalVariableCreator.CollectedValues.Add(new ValueParameter(MigrationsParametername, new IntValue(0))); islandVariableCreator.CollectedValues.Add(new ValueParameter(OpenLayersParametername, new IntValue(1))); islandVariableCreator.CollectedValues.Add(new ValueParameter(IslandResultsParametername)); layerVariableCreator.CollectedValues.Add(new ValueParameter(LayerParametername, new IntValue(0))); layerVariableCreator.CollectedValues.Add(new ValueParameter(LayerResultsParametername)); groupVariableCreator.CollectedValues.Add(new ValueParameter(GroupResultsParametername)); initLayerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name; initIslandAnalyzerPlaceholder.OperatorParameter.ActualName = IslandAnalyzerParameter.Name; initGlobalAnalyzerPlacerholder.OperatorParameter.ActualName = AnalyzerParameter.Name; resultsCollector.CollectedValues.Add(new LookupParameter(GenerationsParametername)); resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter(IslandResultsParametername, "", IslandResultsParametername)); resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter(GroupResultsParametername, "", GroupResultsParametername)); resultsCollector.CollectedValues.Add(new ValueLookupParameter(MigrationsParametername)); resultsCollector.CopyValue = new BoolValue(false); initIslandEvaluationsAss.LeftSideParameter.ActualName = IslandEvaluatedSolutions.Name; initIslandEvaluationsAss.RightSideParameter.Value = new IntValue(0); incrementGenerationDr.ValueParameter.ActualName = GenerationsParametername; incrementEvaluatedSolutionDr.ParameterToReduce.ActualName = IslandEvaluatedSolutions.Name; incrementEvaluatedSolutionDr.TargetParameter.ActualName = EvaluatedSolutions.Name; incrementEvaluatedSolutionDr.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum); incrementEvaluatedSolutionDr.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign); setIslandEvaluatedSolutions.ParameterToReduce.ActualName = LayerEvaluatedSolutionsParameter.Name; setIslandEvaluatedSolutions.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum); setIslandEvaluatedSolutions.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign); setIslandEvaluatedSolutions.TargetParameter.ActualName = IslandEvaluatedSolutions.Name; migrationThresholdCounter.ValueParameter.ActualName = MigrationThresholdParametername; migrateComparator.Comparison.Value = ComparisonType.GreaterOrEqual; migrateComparator.LeftSideParameter.ActualName = MigrationThresholdParametername; migrateComparator.RightSideParameter.ActualName = MigrationIntervalParameter.Name; migrateComparator.ResultParameter.ActualName = MigrateParametername; migrateCondBranch.ConditionParameter.ActualName = MigrateParametername; migrationCounter.ValueParameter.ActualName = MigrationsParametername; migrationThresholdAss.LeftSideParameter.ActualName = MigrationThresholdParametername; migrationThresholdAss.RightSideParameter.Value = new IntValue(0); selectforMigrationUssp.Depth = new IntValue(2); emigrantSelector.OperatorParameter.ActualName = EmigrantsSelectorParameter.Name; replaceforMigrationUssp.Depth = new IntValue(2); immigrantSelector.OperatorParameter.ActualName = ImmigrationReplacerParameter.Name; groupAnalyzer.OperatorParameter.ActualName = GroupAnalyzerParameter.Name; groupLayerNumberResultsCollector.CollectedValues.Add(new LookupParameter("LayerNumber")); groupLayerNumberResultsCollector.ResultsParameter.ActualName = GroupResultsParametername; layerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name; layerResultsCollector.ResultsParameter.ActualName = LayerResultsParametername; layerResultsCollector.CollectedValues.Add(new LookupParameter(LayerParametername)); islandAnalyzerPlaceholder.OperatorParameter.ActualName = IslandAnalyzerParameter.Name; islandResultsCollector.ResultsParameter.ActualName = IslandResultsParametername; islandResultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter(LayerResultsParametername)); globalAnalyzerPlacerholder.OperatorParameter.ActualName = AnalyzerParameter.Name; groupResultsExtractor.SourceNameParameter.Value = new StringValue("GroupScope"); groupResultsExtractor.TargetNameParameter.Value = new StringValue(GroupResultsParametername); groupResultsCollector.CollectedValues.Add(new LookupParameter>(GroupResultsParametername)); matingPoolCreator.MatingPoolRangeParameter.ActualName = MatingPoolRangeParameter.Name; ParemetrizeMainOperator(alpsMainOperator); //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 = 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 = null; processIslandsUssp.Successor = incrementGenerationDr; incrementGenerationDr.Successor = incrementEvaluatedSolutionDr; incrementEvaluatedSolutionDr.Successor = migrationThresholdCounter; migrationThresholdCounter.Successor = migrateComparator; migrateComparator.Successor = migrateCondBranch; migrateCondBranch.FalseBranch = null; migrateCondBranch.TrueBranch = migrationThresholdAss; migrationThresholdAss.Successor = migrationCounter; migrationCounter.Successor = selectforMigrationUssp; selectforMigrationUssp.Operator = emigrantSelector; emigrantSelector.Successor = null; selectforMigrationUssp.Successor = migrator; migrator.Successor = replaceforMigrationUssp; replaceforMigrationUssp.Operator = immigrantSelector; immigrantSelector.Successor = null; replaceforMigrationUssp.Successor = null; migrateCondBranch.Successor = globalAnalyzerPlacerholder; globalAnalyzerPlacerholder.Successor = groupingOperator; groupingOperator.Operator = groupAnalyzer; groupAnalyzer.Successor = groupLayerNumberResultsCollector; groupLayerNumberResultsCollector.Successor = null; groupingOperator.Successor = groupResultsExtractor; groupResultsExtractor.Successor = groupResultsCollector; groupResultsCollector.Successor = terminator; terminator.ContinueBranch = processIslandsUssp; } private void ParemetrizeMainOperator(AlpsOffspringSelectionGeneticAlgorithmMainOperator alpsMainOperator) { 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.AgeParameter.ActualName = AgeParameter.Name; alpsMainOperator.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name; alpsMainOperator.AgeIncrementParameter.Value = new DoubleValue(1.0); alpsMainOperator.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name; alpsMainOperator.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name; alpsMainOperator.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name; alpsMainOperator.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name; alpsMainOperator.FillPopulationWithParentsParameter.ActualName = FillPopulationWithParentsParameter.Name; alpsMainOperator.CurrentSuccessRatioParameter.ActualName = "CurrentSuccessRatio"; alpsMainOperator.SelectionPressureParameter.ActualName = "SelectionPressure"; } private void AddParameters() { 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("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(LayerEvaluatedSolutionsParameterName, "The number of times a solution has been evaluated.")); 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(MigrateParametername, "Migrate the island?")); Parameters.Add(new LookupParameter("ComparisonFactor", "The comparison factor is used to determine whether the offspring should be compared to the better parent, the worse parent or a quality value linearly interpolated between them. It is in the range [0;1].")); Parameters.Add(new ValueLookupParameter("SuccessRatio", "The ratio of successful to total children that should be achieved.")); Parameters.Add(new ValueLookupParameter("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.")); Parameters.Add(new ValueLookupParameter("OffspringSelectionBeforeMutation", "True if the offspring selection step should be applied before mutation, false if it should be applied after mutation.")); Parameters.Add(new ValueLookupParameter("FillPopulationWithParents", "True if the population should be filled with parent individual or false if worse children should be used when the maximum selection pressure is exceeded.")); Parameters.Add(new LookupParameter("CurrentSuccessRatio", "The current success ratio.")); Parameters.Add(new LookupParameter("SelectionPressure", "The actual selection pressure.")); } 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 evaluatedSolutionsWiper = new Assigner() { Name = "Clear evaluated Solutions" }; 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(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 = evaluatedSolutionsWiper; evaluatedSolutionsWiper.LeftSideParameter.ActualName = LayerEvaluatedSolutionsParameterName; evaluatedSolutionsWiper.RightSideParameter.Value = new IntValue(0); evaluatedSolutionsWiper.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.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 = LayerEvaluatedSolutionsParameter.Name; incrEvaluatedSolutionsForNewLayer.AccumulateParameter.Value = new BoolValue(true); incrOpenLayers.ValueParameter.ActualName = "OpenLayers"; incrOpenLayers.Increment = new IntValue(1); incrOpenLayers.Successor = newLayerResultsCollector; newLayerResultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter("LayerResults", "Result set for each layer", "LayerResults")); newLayerResultsCollector.CopyValue = new BoolValue(false); newLayerResultsCollector.Successor = null; 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; } } }