source: branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/LayerUpdator.cs @ 13046

Last change on this file since 13046 was 13046, checked in by pfleck, 7 years ago

#2269

  • Changed the age type from int to double.
  • Changed EldersSelector to make use of a ScopeTreeLookupParameter.
  • Removed unused operators in LayerUpdator.
File size: 9.0 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.Linq;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization;
28using HeuristicLab.Optimization.Operators;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31using HeuristicLab.Selection;
32
33namespace HeuristicLab.Algorithms.ALPS {
34  [Item("LayerUpdator", "Operator which manages the reseeding and creation of layers.")]
35  [StorableClass]
36  public sealed class LayerUpdator : AlgorithmOperator {
37
38    public SolutionsCreator SolutionsCreator {
39      get { return OperatorGraph.Iterate().OfType<SolutionsCreator>().First(); }
40    }
41
42    [StorableConstructor]
43    private LayerUpdator(bool deserializing)
44      : base(deserializing) { }
45    private LayerUpdator(LayerUpdator original, Cloner cloner)
46      : base(original, cloner) { }
47    public override IDeepCloneable Clone(Cloner cloner) {
48      return new LayerUpdator(this, cloner);
49    }
50    public LayerUpdator(IOperator mainOperator)
51      : base() {
52      var incGenSlr = new IntCounter() { Name = "Incr. GenerationsSinceLastRefresh" };
53      var genSlrEqAgeGap = new Comparator() { Name = "GenerationsSinceLastRefresh >= AgeGap" };
54      var updateLayersBranch = new ConditionalBranch() { Name = "UpdateLayers?" };
55      var maxLayerReached = new Comparator() { Name = "MaxLayersReached = OpenLayers >= NumberOfLayers" };
56      var maxLayerReachedBranch = new ConditionalBranch() { Name = "MaxLayersReached?" };
57      var openNewLayerCalculator = new ExpressionCalculator() { Name = "OpenNewLayer = Generations >= AgeLimits[OpenLayers - 1]" };
58      var openNewLayerBranch = new ConditionalBranch() { Name = "OpenNewLayer?" };
59      var layerCreator = new LayerCreator() { Name = "Create new Layer" };
60      var incrOpenLayers = new IntCounter() { Name = "Incr. OpenLayers" };
61      var newLayerResultsCollector = new ResultsCollector() { Name = "Collect new Layer Results" };
62      var newLayerSelector = new RightSelector();
63      var newLayerProsessor = new SubScopesProcessor() { Name = "NewLayerProcessor" };
64      var newLayerLayerProcessor = new UniformSubScopesProcessor();
65      var newLayerReducer = new MergingReducer();
66      var incrEvaluatedSolutionsForNewLayer = new SubScopesCounter() { Name = "Update EvaluatedSolutions" };
67      var newResultCollectionAssigner = new Assigner() { Name = "Empty Results" };
68      var regenerateLayerZeroSelector = new LeftSelector();
69      var regenerateLayerZeroProsessor = new SubScopesProcessor() { Name = "LayerZeroProcessor" };
70      var regenerateLayerZeroLayerProsessor = new UniformSubScopesProcessor();
71      var regenerateLayerZeroReducer = new MergingReducer();
72      var layerSorter = new LayerSorter();
73      var subScopesRemover = new SubScopesRemover();
74      var solutionsCreator = new SolutionsCreator();
75      var initializeAgeProsessor = new UniformSubScopesProcessor();
76      var initializeAge = new VariableCreator() { Name = "Initialize Age" };
77      var incrEvaluatedSolutionsAfterReseeding = new SubScopesCounter() { Name = "Update EvaluatedSolutions" };
78      var resetGenSlr = new Assigner() { Name = "Reset GenerationsSinceLastRefresh" };
79
80      OperatorGraph.InitialOperator = incGenSlr;
81
82      incGenSlr.ValueParameter.ActualName = "GenerationsSinceLastRefresh";
83      incGenSlr.Increment = new IntValue(1);
84      incGenSlr.Successor = genSlrEqAgeGap;
85
86      genSlrEqAgeGap.LeftSideParameter.ActualName = "GenerationsSinceLastRefresh";
87      genSlrEqAgeGap.RightSideParameter.ActualName = "AgeGap";
88      genSlrEqAgeGap.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
89      genSlrEqAgeGap.ResultParameter.ActualName = "UpdateLayers";
90      genSlrEqAgeGap.Successor = updateLayersBranch;
91
92      updateLayersBranch.ConditionParameter.ActualName = "UpdateLayers";
93      updateLayersBranch.TrueBranch = maxLayerReached;
94
95      maxLayerReached.LeftSideParameter.ActualName = "OpenLayers";
96      maxLayerReached.RightSideParameter.ActualName = "NumberOfLayers";
97      maxLayerReached.ResultParameter.ActualName = "MaxLayerReached";
98      maxLayerReached.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
99      maxLayerReached.Successor = maxLayerReachedBranch;
100
101      maxLayerReachedBranch.ConditionParameter.ActualName = "MaxLayerReached";
102      maxLayerReachedBranch.FalseBranch = openNewLayerCalculator;
103      maxLayerReachedBranch.Successor = regenerateLayerZeroSelector;
104
105      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntArray>("AgeLimits"));
106      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
107      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("NumberOfLayers"));
108      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("OpenLayers"));
109      openNewLayerCalculator.ExpressionResultParameter.ActualName = "OpenNewLayer";
110      openNewLayerCalculator.ExpressionParameter.Value = new StringValue("Generations 1 + AgeLimits OpenLayers 1 - [] >");
111      openNewLayerCalculator.Successor = openNewLayerBranch;
112
113      openNewLayerBranch.ConditionParameter.ActualName = "OpenNewLayer";
114      openNewLayerBranch.TrueBranch = layerCreator;
115
116      layerCreator.Successor = newLayerSelector;
117
118      newLayerSelector.NumberOfSelectedSubScopesParameter.Value = new IntValue(1);
119      newLayerSelector.CopySelected = new BoolValue(false);
120      newLayerSelector.Successor = newLayerProsessor;
121
122      newLayerProsessor.Operators.Add(new EmptyOperator());
123      newLayerProsessor.Operators.Add(newLayerLayerProcessor);
124      newLayerProsessor.Successor = newLayerReducer;
125
126      newLayerLayerProcessor.Operator = incrEvaluatedSolutionsForNewLayer;
127
128      newLayerReducer.Successor = incrOpenLayers;
129
130      incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = "EvaluatedSolutions";
131      incrEvaluatedSolutionsForNewLayer.AccumulateParameter.Value = new BoolValue(true);
132      incrEvaluatedSolutionsForNewLayer.Successor = mainOperator;
133
134      newResultCollectionAssigner.LeftSideParameter.ActualName = "LayerResults";
135      newResultCollectionAssigner.RightSideParameter.Value = new ResultCollection();
136      newResultCollectionAssigner.Successor = mainOperator;
137      // TODO mainOperator increment age
138
139      incrOpenLayers.ValueParameter.ActualName = "OpenLayers";
140      incrOpenLayers.Increment = new IntValue(1);
141      incrOpenLayers.Successor = newLayerResultsCollector;
142
143      newLayerResultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("LayerResults", "Result set for each layer", "LayerResults"));
144      newLayerResultsCollector.CopyValue = new BoolValue(false);
145      newLayerResultsCollector.Successor = null;
146
147      regenerateLayerZeroSelector.NumberOfSelectedSubScopesParameter.Value = new IntValue(1);
148      regenerateLayerZeroSelector.CopySelected = new BoolValue(false);
149      regenerateLayerZeroSelector.Successor = regenerateLayerZeroProsessor;
150
151      regenerateLayerZeroProsessor.Operators.Add(new EmptyOperator());
152      regenerateLayerZeroProsessor.Operators.Add(regenerateLayerZeroLayerProsessor);
153      regenerateLayerZeroProsessor.Successor = regenerateLayerZeroReducer;
154
155      regenerateLayerZeroLayerProsessor.Operator = subScopesRemover;
156
157      regenerateLayerZeroReducer.Successor = layerSorter;
158
159      layerSorter.Successor = resetGenSlr;
160
161      subScopesRemover.Successor = solutionsCreator;
162
163      solutionsCreator.Successor = initializeAgeProsessor;
164
165      initializeAgeProsessor.Operator = initializeAge;
166      initializeAgeProsessor.Successor = incrEvaluatedSolutionsAfterReseeding;
167
168      initializeAge.CollectedValues.Add(new ValueParameter<DoubleValue>("Age", new DoubleValue(0)));
169      initializeAge.Successor = null;
170
171      incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = "EvaluatedSolutions";
172      incrEvaluatedSolutionsAfterReseeding.AccumulateParameter.Value = new BoolValue(true);
173      incrEvaluatedSolutionsAfterReseeding.Successor = null;
174
175      resetGenSlr.LeftSideParameter.ActualName = "GenerationsSinceLastRefresh";
176      resetGenSlr.RightSideParameter.Value = new IntValue(0);
177      resetGenSlr.Successor = null;
178    }
179  }
180}
Note: See TracBrowser for help on using the repository browser.