Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/03/15 17:09:44 (8 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.
File:
1 moved

Legend:

Unmodified
Added
Removed
  • 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.