Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13111 for branches


Ignore:
Timestamp:
11/03/15 17:09:44 (9 years ago)
Author:
pfleck
Message:

#2269

  • Instead of hidden execution scope change logic in LayerReseeder, the new ReseedingController makes the scope change more obvious by using an OperatorParameter.
  • Instead of the classes for EldersEmigrator, LayerOpener and LayerReseeder the operator graph is created in the AlpsGeneticAlgorithmMainLoop using CombinedOperator.
Location:
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3
Files:
2 deleted
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithmMainLoop.cs

    r13096 r13111  
    3030using HeuristicLab.Parameters;
    3131using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     32using HeuristicLab.Selection;
    3233
    3334namespace HeuristicLab.Algorithms.ALPS {
     
    8384      var generationsIcrementor = new IntCounter() { Name = "Increment Generations" };
    8485      var evaluatedSolutionsReducer = new DataReducer() { Name = "Increment EvaluatedSolutions" };
    85       var eldersEmigrator = new EldersEmigrator() { Name = "Emigrate Elders" };
    86       var layerOpener = new LayerOpener() { Name = "Open new Layer" };
    87       var layerReseeder = new LayerReseeder() { Name = "Reseed Layer Zero" };
     86      var eldersEmigrator = CreateEldersEmigrator();
     87      var layerOpener = CreateLayerOpener();
     88      var layerReseeder = CreateReseeder();
    8889      var layerAnalyzerProcessor = new UniformSubScopesProcessor();
    8990      var layerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" };
     
    153154      termination.ContinueBranch = matingPoolCreator;
    154155    }
     156
     157    private static CombinedOperator CreateEldersEmigrator() {
     158      var eldersEmigrator = new CombinedOperator() { Name = "Emigrate Elders" };
     159      var selectorProsessor = new UniformSubScopesProcessor();
     160      var eldersSelector = new EldersSelector();
     161      var shiftToRightMigrator = new UnidirectionalRingMigrator();
     162      var mergingProsessor = new UniformSubScopesProcessor();
     163      var mergingReducer = new MergingReducer();
     164      var subScopesCounter = new SubScopesCounter();
     165      var countCalculator = new ExpressionCalculator() { Name = "LayerPopulationSize = Min(LayerPopulationSize, PopulationSize)" };
     166      var bestSelector = new BestSelector();
     167      var rightReducer = new RightReducer();
     168
     169      eldersEmigrator.OperatorGraph.InitialOperator = selectorProsessor;
     170
     171      selectorProsessor.Operator = eldersSelector;
     172      selectorProsessor.Successor = shiftToRightMigrator;
     173
     174      shiftToRightMigrator.ClockwiseMigrationParameter.Value = new BoolValue(true);
     175      shiftToRightMigrator.Successor = mergingProsessor;
     176
     177      mergingProsessor.Operator = mergingReducer;
     178
     179      mergingReducer.Successor = subScopesCounter;
     180
     181      subScopesCounter.ValueParameter.ActualName = "LayerPopulationSize";
     182      subScopesCounter.AccumulateParameter.Value = new BoolValue(false);
     183      subScopesCounter.Successor = countCalculator;
     184
     185      countCalculator.CollectedValues.Add(new LookupParameter<IntValue>("PopulationSize"));
     186      countCalculator.CollectedValues.Add(new LookupParameter<IntValue>("LayerPopulationSize"));
     187      countCalculator.ExpressionParameter.Value = new StringValue("LayerPopulationSize PopulationSize LayerPopulationSize PopulationSize < if toint");
     188      countCalculator.ExpressionResultParameter.ActualName = "LayerPopulationSize";
     189      countCalculator.Successor = bestSelector;
     190
     191      bestSelector.NumberOfSelectedSubScopesParameter.ActualName = "LayerPopulationSize";
     192      bestSelector.CopySelected = new BoolValue(false);
     193      bestSelector.Successor = rightReducer;
     194
     195      return eldersEmigrator;
     196    }
     197
     198    private static CombinedOperator CreateLayerOpener() {
     199      var layerOpener = new CombinedOperator() { Name = "Open new Layer if needed" };
     200      var maxLayerReached = new Comparator() { Name = "MaxLayersReached = OpenLayers >= NumberOfLayers" };
     201      var maxLayerReachedBranch = new ConditionalBranch() { Name = "MaxLayersReached?" };
     202      var openNewLayerCalculator = new ExpressionCalculator() { Name = "OpenNewLayer = Generations >= AgeLimits[OpenLayers - 1]" };
     203      var openNewLayerBranch = new ConditionalBranch() { Name = "OpenNewLayer?" };
     204      var layerCreator = new LayerCreator() { Name = "Create Layer" };
     205      var createChildrenViaCrossover = AlpsGeneticAlgorithmMainOperator.Create();
     206      var incrEvaluatedSolutionsForNewLayer = new SubScopesCounter() { Name = "Update EvaluatedSolutions" };
     207      var incrOpenLayers = new IntCounter() { Name = "Incr. OpenLayers" };
     208      var newLayerResultsCollector = new ResultsCollector() { Name = "Collect new Layer Results" };
     209
     210      layerOpener.OperatorGraph.InitialOperator = maxLayerReached;
     211
     212      maxLayerReached.LeftSideParameter.ActualName = "OpenLayers";
     213      maxLayerReached.RightSideParameter.ActualName = "NumberOfLayers";
     214      maxLayerReached.ResultParameter.ActualName = "MaxLayerReached";
     215      maxLayerReached.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
     216      maxLayerReached.Successor = maxLayerReachedBranch;
     217
     218      maxLayerReachedBranch.ConditionParameter.ActualName = "MaxLayerReached";
     219      maxLayerReachedBranch.FalseBranch = openNewLayerCalculator;
     220
     221      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntArray>("AgeLimits"));
     222      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
     223      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("NumberOfLayers"));
     224      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("OpenLayers"));
     225      openNewLayerCalculator.ExpressionResultParameter.ActualName = "OpenNewLayer";
     226      openNewLayerCalculator.ExpressionParameter.Value = new StringValue("Generations 1 + AgeLimits OpenLayers 1 - [] >");
     227      openNewLayerCalculator.Successor = openNewLayerBranch;
     228
     229      openNewLayerBranch.ConditionParameter.ActualName = "OpenNewLayer";
     230      openNewLayerBranch.TrueBranch = layerCreator;
     231
     232      layerCreator.NewLayerOperator = createChildrenViaCrossover;
     233      layerCreator.Successor = incrOpenLayers;
     234
     235      createChildrenViaCrossover.Successor = incrEvaluatedSolutionsForNewLayer;
     236
     237      incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = "EvaluatedSolutions";
     238      incrEvaluatedSolutionsForNewLayer.AccumulateParameter.Value = new BoolValue(true);
     239
     240      incrOpenLayers.ValueParameter.ActualName = "OpenLayers";
     241      incrOpenLayers.Increment = new IntValue(1);
     242      incrOpenLayers.Successor = newLayerResultsCollector;
     243
     244      newLayerResultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("LayerResults", "Result set for each layer", "LayerResults"));
     245      newLayerResultsCollector.CopyValue = new BoolValue(false);
     246      newLayerResultsCollector.Successor = null;
     247
     248      return layerOpener;
     249    }
     250
     251    private static CombinedOperator CreateReseeder() {
     252      var reseeder = new CombinedOperator() { Name = "Reseed Layer Zero if needed" };
     253      var reseedingController = new ReseedingController() { Name = "Reseeding needed (Generation % AgeGap == 0)?" };
     254      var removeIndividuals = new SubScopesRemover();
     255      var createIndividuals = new SolutionsCreator();
     256      var initializeAgeProsessor = new UniformSubScopesProcessor();
     257      var initializeAge = new VariableCreator() { Name = "Initialize Age" };
     258      var incrEvaluatedSolutionsAfterReseeding = new SubScopesCounter() { Name = "Update EvaluatedSolutions" };
     259
     260      reseeder.OperatorGraph.InitialOperator = reseedingController;
     261
     262      reseedingController.FirstLayerOperator = removeIndividuals;
     263
     264      removeIndividuals.Successor = createIndividuals;
     265
     266      createIndividuals.NumberOfSolutionsParameter.ActualName = "PopulationSize";
     267      createIndividuals.Successor = initializeAgeProsessor;
     268
     269      initializeAgeProsessor.Operator = initializeAge;
     270      initializeAgeProsessor.Successor = incrEvaluatedSolutionsAfterReseeding;
     271
     272      initializeAge.CollectedValues.Add(new ValueParameter<DoubleValue>("Age", new DoubleValue(0)));
     273
     274      incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = "EvaluatedSolutions";
     275      incrEvaluatedSolutionsAfterReseeding.AccumulateParameter.Value = new BoolValue(true);
     276
     277      return reseeder;
     278    }
    155279  }
    156280}
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/HeuristicLab.Algorithms.ALPS-3.3.csproj

    r13095 r13111  
    133133  <ItemGroup>
    134134    <Compile Include="AlpsGeneticAlgorithmMainOperator.cs" />
    135     <Compile Include="LayerOpener.cs" />
    136     <Compile Include="LayerReseeder.cs" />
     135    <Compile Include="ReseedingController.cs" />
    137136    <Compile Include="WeightingReducer.cs" />
    138137    <Compile Include="Analyzers\OldestAverageYoungestAgeAnalyzer.cs" />
     
    142141    <Compile Include="AlpsGeneticAlgorithmMainLoop.cs" />
    143142    <Compile Include="Analyzers\OldestAverageYoungestAgeCalculator.cs" />
    144     <Compile Include="EldersEmigrator.cs" />
    145143    <Compile Include="EldersSelector.cs" />
    146144    <Compile Include="LayerCreator.cs" />
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/ReseedingController.cs

    r13110 r13111  
    2020#endregion
    2121
    22 using System.Drawing;
    2322using HeuristicLab.Common;
    2423using HeuristicLab.Core;
    2524using HeuristicLab.Data;
    2625using HeuristicLab.Operators;
    27 using HeuristicLab.Optimization.Operators;
    2826using HeuristicLab.Parameters;
    2927using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3028
    3129namespace HeuristicLab.Algorithms.ALPS {
    32   [Item("LayerReseeder", "An operator that encapsulates the reseeding of the lowest layer in ALPS.")]
     30  [Item("ReseedingController", "An operator that controls if reseeding is needed.")]
    3331  [StorableClass]
    34   public sealed class LayerReseeder : SingleSuccessorOperator, IOperatorGraphOperator {
    35     public static new Image StaticItemImage {
    36       get { return HeuristicLab.Common.Resources.VSImageLibrary.Module; }
    37     }
    38     public override Image ItemImage {
    39       get {
    40         if (Breakpoint) return HeuristicLab.Common.Resources.VSImageLibrary.BreakpointActive;
    41         else return base.ItemImage;
    42       }
    43     }
    44 
     32  public sealed class ReseedingController : SingleSuccessorOperator {
    4533    private ILookupParameter<IntValue> GenerationsParameter {
    4634      get { return (ILookupParameter<IntValue>)Parameters["Generations"]; }
     
    4937      get { return (ILookupParameter<IntValue>)Parameters["AgeGap"]; }
    5038    }
     39    public OperatorParameter FirstLayerOperatorParameter {
     40      get { return (OperatorParameter)Parameters["FirstLayerOperator"]; }
     41    }
    5142
    52     [Storable]
    53     private OperatorGraph operatorGraph;
    54     public OperatorGraph OperatorGraph {
    55       get { return operatorGraph; }
     43    public IOperator FirstLayerOperator {
     44      get { return FirstLayerOperatorParameter.Value; }
     45      set { FirstLayerOperatorParameter.Value = value; }
    5646    }
    5747
    5848    [StorableConstructor]
    59     private LayerReseeder(bool deserializing)
     49    private ReseedingController(bool deserializing)
    6050      : base(deserializing) { }
    6151
    62     private LayerReseeder(LayerReseeder original, Cloner cloner)
     52    private ReseedingController(ReseedingController original, Cloner cloner)
    6353      : base(original, cloner) {
    64       operatorGraph = cloner.Clone(original.operatorGraph);
    6554    }
    6655    public override IDeepCloneable Clone(Cloner cloner) {
    67       return new LayerReseeder(this, cloner);
     56      return new ReseedingController(this, cloner);
    6857    }
    6958
    70     public LayerReseeder()
     59    public ReseedingController()
    7160      : base() {
    7261      Parameters.Add(new LookupParameter<IntValue>("Generations"));
    7362      Parameters.Add(new LookupParameter<IntValue>("AgeGap"));
    74 
    75       operatorGraph = new OperatorGraph();
    76 
    77       var removeIndividuals = new SubScopesRemover();
    78       var createIndividuals = new SolutionsCreator();
    79       var initializeAgeProsessor = new UniformSubScopesProcessor();
    80       var initializeAge = new VariableCreator() { Name = "Initialize Age" };
    81       var incrEvaluatedSolutionsAfterReseeding = new SubScopesCounter() { Name = "Update EvaluatedSolutions" };
    82 
    83       OperatorGraph.InitialOperator = removeIndividuals;
    84 
    85       removeIndividuals.Successor = createIndividuals;
    86 
    87       createIndividuals.NumberOfSolutionsParameter.ActualName = "PopulationSize";
    88       createIndividuals.Successor = initializeAgeProsessor;
    89 
    90       initializeAgeProsessor.Operator = initializeAge;
    91       initializeAgeProsessor.Successor = incrEvaluatedSolutionsAfterReseeding;
    92 
    93       initializeAge.CollectedValues.Add(new ValueParameter<DoubleValue>("Age", new DoubleValue(0)));
    94       initializeAge.Successor = null;
    95 
    96       incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = "EvaluatedSolutions";
    97       incrEvaluatedSolutionsAfterReseeding.AccumulateParameter.Value = new BoolValue(true);
    98       incrEvaluatedSolutionsAfterReseeding.Successor = null;
     63      Parameters.Add(new OperatorParameter("FirstLayerOperator"));
    9964    }
    10065
     
    10671      if (generations % ageGap == 0) {
    10772        var layerZeroScope = ExecutionContext.Scope.SubScopes[0];
    108         if (operatorGraph.InitialOperator != null)
    109           next.Insert(0, ExecutionContext.CreateChildOperation(operatorGraph.InitialOperator, layerZeroScope));
     73        if (FirstLayerOperator != null)
     74          next.Insert(0, ExecutionContext.CreateChildOperation(FirstLayerOperator, layerZeroScope));
    11075      }
    11176      return next;
Note: See TracChangeset for help on using the changeset viewer.