Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/LayerOpener.cs @ 13096

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

#2269

  • Simplified operator graph in MainOperator.
  • Added item descriptions.
  • Removed unnecessary code.
File size: 4.7 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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Operators;
26using HeuristicLab.Optimization;
27using HeuristicLab.Optimization.Operators;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Algorithms.ALPS {
32  [Item("LayerOpener", "An operator that encapsules opening new layer for ALPS when required.")]
33  [StorableClass]
34  public sealed class LayerOpener : AlgorithmOperator {
35    [StorableConstructor]
36    private LayerOpener(bool deserializing)
37      : base(deserializing) { }
38    private LayerOpener(LayerOpener original, Cloner cloner)
39      : base(original, cloner) { }
40    public override IDeepCloneable Clone(Cloner cloner) {
41      return new LayerOpener(this, cloner);
42    }
43
44    public LayerOpener()
45      : base() {
46      var maxLayerReached = new Comparator() { Name = "MaxLayersReached = OpenLayers >= NumberOfLayers" };
47      var maxLayerReachedBranch = new ConditionalBranch() { Name = "MaxLayersReached?" };
48      var openNewLayerCalculator = new ExpressionCalculator() { Name = "OpenNewLayer = Generations >= AgeLimits[OpenLayers - 1]" };
49      var openNewLayerBranch = new ConditionalBranch() { Name = "OpenNewLayer?" };
50      var layerCreator = new LayerCreator() { Name = "Create Layer" };
51      var createChildrenViaCrossover = AlpsGeneticAlgorithmMainOperator.Create();
52      var incrEvaluatedSolutionsForNewLayer = new SubScopesCounter() { Name = "Update EvaluatedSolutions" };
53      var incrOpenLayers = new IntCounter() { Name = "Incr. OpenLayers" };
54      var newLayerResultsCollector = new ResultsCollector() { Name = "Collect new Layer Results" };
55
56      OperatorGraph.InitialOperator = maxLayerReached;
57
58      maxLayerReached.LeftSideParameter.ActualName = "OpenLayers";
59      maxLayerReached.RightSideParameter.ActualName = "NumberOfLayers";
60      maxLayerReached.ResultParameter.ActualName = "MaxLayerReached";
61      maxLayerReached.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
62      maxLayerReached.Successor = maxLayerReachedBranch;
63
64      maxLayerReachedBranch.ConditionParameter.ActualName = "MaxLayerReached";
65      maxLayerReachedBranch.FalseBranch = openNewLayerCalculator;
66
67      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntArray>("AgeLimits"));
68      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
69      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("NumberOfLayers"));
70      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("OpenLayers"));
71      openNewLayerCalculator.ExpressionResultParameter.ActualName = "OpenNewLayer";
72      openNewLayerCalculator.ExpressionParameter.Value = new StringValue("Generations 1 + AgeLimits OpenLayers 1 - [] >");
73      openNewLayerCalculator.Successor = openNewLayerBranch;
74
75      openNewLayerBranch.ConditionParameter.ActualName = "OpenNewLayer";
76      openNewLayerBranch.TrueBranch = layerCreator;
77
78      layerCreator.NewLayerOperator = createChildrenViaCrossover;
79      layerCreator.Successor = incrOpenLayers;
80
81      createChildrenViaCrossover.Successor = incrEvaluatedSolutionsForNewLayer;
82
83      incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = "EvaluatedSolutions";
84      incrEvaluatedSolutionsForNewLayer.AccumulateParameter.Value = new BoolValue(true);
85
86      incrOpenLayers.ValueParameter.ActualName = "OpenLayers";
87      incrOpenLayers.Increment = new IntValue(1);
88      incrOpenLayers.Successor = newLayerResultsCollector;
89
90      newLayerResultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("LayerResults", "Result set for each layer", "LayerResults"));
91      newLayerResultsCollector.CopyValue = new BoolValue(false);
92      newLayerResultsCollector.Successor = null;
93    }
94  }
95}
Note: See TracBrowser for help on using the repository browser.