Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/LayerReseeder.cs @ 13110

Last change on this file since 13110 was 13110, checked in by pfleck, 8 years ago

#2269

  • Removed ContinuousReseeding because it does not bring any improvements and makes reseeding more complicated.
  • Adapted changes from UnidirectionalRingMigrator.
File size: 4.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Drawing;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization.Operators;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Algorithms.ALPS {
32  [Item("LayerReseeder", "An operator that encapsulates the reseeding of the lowest layer in ALPS.")]
33  [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
45    private ILookupParameter<IntValue> GenerationsParameter {
46      get { return (ILookupParameter<IntValue>)Parameters["Generations"]; }
47    }
48    private ILookupParameter<IntValue> AgeGapParameter {
49      get { return (ILookupParameter<IntValue>)Parameters["AgeGap"]; }
50    }
51
52    [Storable]
53    private OperatorGraph operatorGraph;
54    public OperatorGraph OperatorGraph {
55      get { return operatorGraph; }
56    }
57
58    [StorableConstructor]
59    private LayerReseeder(bool deserializing)
60      : base(deserializing) { }
61
62    private LayerReseeder(LayerReseeder original, Cloner cloner)
63      : base(original, cloner) {
64      operatorGraph = cloner.Clone(original.operatorGraph);
65    }
66    public override IDeepCloneable Clone(Cloner cloner) {
67      return new LayerReseeder(this, cloner);
68    }
69
70    public LayerReseeder()
71      : base() {
72      Parameters.Add(new LookupParameter<IntValue>("Generations"));
73      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;
99    }
100
101    public override IOperation Apply() {
102      int generations = GenerationsParameter.ActualValue.Value;
103      int ageGap = AgeGapParameter.ActualValue.Value;
104
105      var next = new OperationCollection(base.Apply());
106      if (generations % ageGap == 0) {
107        var layerZeroScope = ExecutionContext.Scope.SubScopes[0];
108        if (operatorGraph.InitialOperator != null)
109          next.Insert(0, ExecutionContext.CreateChildOperation(operatorGraph.InitialOperator, layerZeroScope));
110      }
111      return next;
112    }
113  }
114}
Note: See TracBrowser for help on using the repository browser.