Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 11679 was 11609, checked in by pfleck, 10 years ago

#2269

  • Fixed Bugs with Per-Layer-Results.
  • Fixed Bugs in EldersSelector.
  • Added LayerCreator instead of LastSubScopeCloner for avoiding operators for some temporary hacks.
File size: 8.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 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;
31
32namespace HeuristicLab.Algorithms.ALPS {
33  [Item("LayerUpdator", "Operator which manages the reseeding and creation of layers.")]
34  [StorableClass]
35  public class LayerUpdator : AlgorithmOperator {
36
37    public SolutionsCreator SolutionsCreator {
38      get { return OperatorGraph.Iterate().OfType<SolutionsCreator>().First(); }
39    }
40
41    [StorableConstructor]
42    private LayerUpdator(bool deserializing)
43      : base(deserializing) { }
44    private LayerUpdator(LayerUpdator original, Cloner cloner)
45      : base(original, cloner) { }
46    public override IDeepCloneable Clone(Cloner cloner) {
47      return new LayerUpdator(this, cloner);
48    }
49    public LayerUpdator(IOperator mainOperator)
50      : base() {
51      var incGenSlr = new IntCounter() { Name = "Incr. GenerationsSinceLastRefresh" };
52      var genSlrEqAgeGap = new Comparator() { Name = "GenerationsSinceLastRefresh >= AgeGap" };
53      var updateLayersBranch = new ConditionalBranch() { Name = "UpdateLayers?" };
54      // TODO: if expression calculator supports array indexing, use expression calculator
55      //var openNewLayerCalculator = new ExpressionCalculator();
56      var openNewLayerCalculator = new OpenNewLayerCalculator();
57      var openNewLayerBranch = new ConditionalBranch() { Name = "OpenNewLayer?" };
58      //var layerCloner = new LastSubScopeCloner() { Name = "Copy Lower Layer" };
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 newLayerProsessor = new LastSubScopeProcessor();
63      var layerInitializer = new Assigner() { Name = "Init Layer" };
64      var correctAgeProcessor = new UniformSubScopesProcessor() { Name = "Hack: Decrement Age" };
65      var correctAgeDecrementor = new IntCounter() { Name = "Age = Age - 1" };
66      var incrEvaluatedSolutionsForNewLayer = new SubScopesCounter() { Name = "Update EvaluatedSolutions" };
67      var newResultCollectionAssigner = new Assigner() { Name = "Empty Results" };
68      var regenerateLayerZeroProsessor = new FirstSubScopeProcessor();
69      var subScopesRemover = new SubScopesRemover();
70      var solutionsCreator = new SolutionsCreator();
71      var initializeAgeProsessor = new UniformSubScopesProcessor();
72      var initializeAge = new VariableCreator() { Name = "Initialize Age" };
73      var incrEvaluatedSolutionsAfterReseeding = new SubScopesCounter() { Name = "Update EvaluatedSolutions" };
74      var resetGenSlr = new Assigner() { Name = "Reset GenerationsSinceLastRefresh" };
75
76      OperatorGraph.InitialOperator = incGenSlr;
77
78      incGenSlr.ValueParameter.ActualName = "GenerationsSinceLastRefresh";
79      incGenSlr.Increment = new IntValue(1);
80      incGenSlr.Successor = genSlrEqAgeGap;
81
82      genSlrEqAgeGap.LeftSideParameter.ActualName = "GenerationsSinceLastRefresh";
83      genSlrEqAgeGap.RightSideParameter.ActualName = "AgeGap";
84      genSlrEqAgeGap.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
85      genSlrEqAgeGap.ResultParameter.ActualName = "UpdateLayers";
86      genSlrEqAgeGap.Successor = updateLayersBranch;
87
88      updateLayersBranch.ConditionParameter.ActualName = "UpdateLayers";
89      updateLayersBranch.TrueBranch = openNewLayerCalculator;
90
91      //openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
92      //openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("AgeGap"));
93      //openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("OpenLayers"));
94      //openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("NumberOfLayers"));
95      //openNewLayerCalculator.ExpressionParameter.Value = new StringValue("Generations AgeLimits [] OpenedLayers 1 - 1 + = false OpenLayers NumberOfLayers < if");
96      //openNewLayerCalculator.ExpressionResultParameter.ActualName = "OpenNewLayer";
97      openNewLayerCalculator.Successor = openNewLayerBranch;
98
99      openNewLayerBranch.ConditionParameter.ActualName = "OpenNewLayer";
100      openNewLayerBranch.TrueBranch = layerCreator;
101      openNewLayerBranch.Successor = regenerateLayerZeroProsessor;
102
103      //layerCloner.Successor = newLayerProsessor;
104      layerCreator.Successor = newLayerProsessor;
105
106      //newLayerProsessor.Operator = layerInitializer;
107      newLayerProsessor.Operator = incrEvaluatedSolutionsForNewLayer;
108      newLayerProsessor.Successor = incrOpenLayers;
109
110      layerInitializer.LeftSideParameter.ActualName = "Layer";
111      layerInitializer.RightSideParameter.ActualName = "OpenLayers";
112      layerInitializer.Successor = correctAgeProcessor;
113
114      correctAgeProcessor.Operator = correctAgeDecrementor;
115      correctAgeProcessor.Successor = incrEvaluatedSolutionsForNewLayer;
116
117      correctAgeDecrementor.Increment = new IntValue(-1);
118      correctAgeDecrementor.ValueParameter.ActualName = "Age";
119
120      incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = "EvaluatedSolutions";
121      incrEvaluatedSolutionsForNewLayer.AccumulateParameter.Value = new BoolValue(true);
122      //incrEvaluatedSolutionsForNewLayer.Successor = newResultCollectionAssigner;
123      incrEvaluatedSolutionsForNewLayer.Successor = mainOperator;
124
125      newResultCollectionAssigner.LeftSideParameter.ActualName = "Results";
126      newResultCollectionAssigner.RightSideParameter.Value = new ResultCollection();
127      newResultCollectionAssigner.Successor = mainOperator;
128      // TODO mainOperator increment age
129
130      incrOpenLayers.ValueParameter.ActualName = "OpenLayers";
131      incrOpenLayers.Increment = new IntValue(1);
132      incrOpenLayers.Successor = newLayerResultsCollector;
133
134      newLayerResultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("LayerResults", "Result set for each layer", "Results"));
135      newLayerResultsCollector.CopyValue = new BoolValue(false);
136      newLayerResultsCollector.Successor = null;
137
138      regenerateLayerZeroProsessor.Operator = subScopesRemover;
139      regenerateLayerZeroProsessor.Successor = resetGenSlr;
140
141      subScopesRemover.Successor = solutionsCreator;
142
143      solutionsCreator.Successor = initializeAgeProsessor;
144
145      initializeAgeProsessor.Operator = initializeAge;
146      initializeAgeProsessor.Successor = incrEvaluatedSolutionsAfterReseeding;
147
148      initializeAge.CollectedValues.Add(new ValueParameter<IntValue>("Age", new IntValue(0)));
149      initializeAge.Successor = null;
150
151      incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = "EvaluatedSolutions";
152      incrEvaluatedSolutionsAfterReseeding.AccumulateParameter.Value = new BoolValue(true);
153      incrEvaluatedSolutionsAfterReseeding.Successor = null;
154
155      resetGenSlr.LeftSideParameter.ActualName = "GenerationsSinceLastRefresh";
156      resetGenSlr.RightSideParameter.Value = new IntValue(0);
157      resetGenSlr.Successor = null;
158    }
159  }
160}
Note: See TracBrowser for help on using the repository browser.