[11586] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12018] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[11586] | 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 |
|
---|
[11590] | 22 | using System.Linq;
|
---|
[11586] | 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Data;
|
---|
| 26 | using HeuristicLab.Operators;
|
---|
[11590] | 27 | using HeuristicLab.Optimization;
|
---|
[11586] | 28 | using HeuristicLab.Optimization.Operators;
|
---|
| 29 | using HeuristicLab.Parameters;
|
---|
| 30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[12036] | 31 | using HeuristicLab.Selection;
|
---|
[11586] | 32 |
|
---|
| 33 | namespace HeuristicLab.Algorithms.ALPS {
|
---|
| 34 | [Item("LayerUpdator", "Operator which manages the reseeding and creation of layers.")]
|
---|
| 35 | [StorableClass]
|
---|
[12570] | 36 | public sealed class LayerUpdator : AlgorithmOperator {
|
---|
[11586] | 37 |
|
---|
[11590] | 38 | public SolutionsCreator SolutionsCreator {
|
---|
| 39 | get { return OperatorGraph.Iterate().OfType<SolutionsCreator>().First(); }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
[11586] | 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?" };
|
---|
[12097] | 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]" };
|
---|
[11586] | 58 | var openNewLayerBranch = new ConditionalBranch() { Name = "OpenNewLayer?" };
|
---|
[11609] | 59 | var layerCreator = new LayerCreator() { Name = "Create new Layer" };
|
---|
[11586] | 60 | var incrOpenLayers = new IntCounter() { Name = "Incr. OpenLayers" };
|
---|
[11609] | 61 | var newLayerResultsCollector = new ResultsCollector() { Name = "Collect new Layer Results" };
|
---|
[12036] | 62 | var newLayerSelector = new RightSelector();
|
---|
[12097] | 63 | var newLayerProsessor = new SubScopesProcessor() { Name = "NewLayerProcessor" };
|
---|
[12992] | 64 | var newLayerLayerProcessor = new UniformSubScopesProcessor();
|
---|
[12036] | 65 | var newLayerReducer = new MergingReducer();
|
---|
[11590] | 66 | var layerInitializer = new Assigner() { Name = "Init Layer" };
|
---|
[11609] | 67 | var correctAgeProcessor = new UniformSubScopesProcessor() { Name = "Hack: Decrement Age" };
|
---|
| 68 | var correctAgeDecrementor = new IntCounter() { Name = "Age = Age - 1" };
|
---|
[11590] | 69 | var incrEvaluatedSolutionsForNewLayer = new SubScopesCounter() { Name = "Update EvaluatedSolutions" };
|
---|
| 70 | var newResultCollectionAssigner = new Assigner() { Name = "Empty Results" };
|
---|
[12036] | 71 | var regenerateLayerZeroSelector = new LeftSelector();
|
---|
[12097] | 72 | var regenerateLayerZeroProsessor = new SubScopesProcessor() { Name = "LayerZeroProcessor" };
|
---|
[12992] | 73 | var regenerateLayerZeroLayerProsessor = new UniformSubScopesProcessor();
|
---|
[12036] | 74 | var regenerateLayerZeroReducer = new MergingReducer();
|
---|
| 75 | var layerSorter = new LayerSorter();
|
---|
[11586] | 76 | var subScopesRemover = new SubScopesRemover();
|
---|
| 77 | var solutionsCreator = new SolutionsCreator();
|
---|
| 78 | var initializeAgeProsessor = new UniformSubScopesProcessor();
|
---|
| 79 | var initializeAge = new VariableCreator() { Name = "Initialize Age" };
|
---|
[11590] | 80 | var incrEvaluatedSolutionsAfterReseeding = new SubScopesCounter() { Name = "Update EvaluatedSolutions" };
|
---|
[11586] | 81 | var resetGenSlr = new Assigner() { Name = "Reset GenerationsSinceLastRefresh" };
|
---|
| 82 |
|
---|
| 83 | OperatorGraph.InitialOperator = incGenSlr;
|
---|
| 84 |
|
---|
| 85 | incGenSlr.ValueParameter.ActualName = "GenerationsSinceLastRefresh";
|
---|
| 86 | incGenSlr.Increment = new IntValue(1);
|
---|
| 87 | incGenSlr.Successor = genSlrEqAgeGap;
|
---|
| 88 |
|
---|
| 89 | genSlrEqAgeGap.LeftSideParameter.ActualName = "GenerationsSinceLastRefresh";
|
---|
| 90 | genSlrEqAgeGap.RightSideParameter.ActualName = "AgeGap";
|
---|
| 91 | genSlrEqAgeGap.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
|
---|
| 92 | genSlrEqAgeGap.ResultParameter.ActualName = "UpdateLayers";
|
---|
| 93 | genSlrEqAgeGap.Successor = updateLayersBranch;
|
---|
| 94 |
|
---|
[11590] | 95 | updateLayersBranch.ConditionParameter.ActualName = "UpdateLayers";
|
---|
[12097] | 96 | updateLayersBranch.TrueBranch = maxLayerReached;
|
---|
[11586] | 97 |
|
---|
[12097] | 98 | maxLayerReached.LeftSideParameter.ActualName = "OpenLayers";
|
---|
| 99 | maxLayerReached.RightSideParameter.ActualName = "NumberOfLayers";
|
---|
| 100 | maxLayerReached.ResultParameter.ActualName = "MaxLayerReached";
|
---|
| 101 | maxLayerReached.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
|
---|
| 102 | maxLayerReached.Successor = maxLayerReachedBranch;
|
---|
| 103 |
|
---|
| 104 | maxLayerReachedBranch.ConditionParameter.ActualName = "MaxLayerReached";
|
---|
| 105 | maxLayerReachedBranch.FalseBranch = openNewLayerCalculator;
|
---|
| 106 | maxLayerReachedBranch.Successor = regenerateLayerZeroSelector;
|
---|
| 107 |
|
---|
| 108 | openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntArray>("AgeLimits"));
|
---|
| 109 | openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
|
---|
| 110 | openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("NumberOfLayers"));
|
---|
| 111 | openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("OpenLayers"));
|
---|
| 112 | openNewLayerCalculator.ExpressionResultParameter.ActualName = "OpenNewLayer";
|
---|
| 113 | openNewLayerCalculator.ExpressionParameter.Value = new StringValue("Generations 1 + AgeLimits OpenLayers 1 - [] >");
|
---|
[11586] | 114 | openNewLayerCalculator.Successor = openNewLayerBranch;
|
---|
| 115 |
|
---|
| 116 | openNewLayerBranch.ConditionParameter.ActualName = "OpenNewLayer";
|
---|
[11609] | 117 | openNewLayerBranch.TrueBranch = layerCreator;
|
---|
[11586] | 118 |
|
---|
[12036] | 119 | layerCreator.Successor = newLayerSelector;
|
---|
[11586] | 120 |
|
---|
[12036] | 121 | newLayerSelector.NumberOfSelectedSubScopesParameter.Value = new IntValue(1);
|
---|
| 122 | newLayerSelector.CopySelected = new BoolValue(false);
|
---|
| 123 | newLayerSelector.Successor = newLayerProsessor;
|
---|
[11586] | 124 |
|
---|
[12036] | 125 | newLayerProsessor.Operators.Add(new EmptyOperator());
|
---|
| 126 | newLayerProsessor.Operators.Add(newLayerLayerProcessor);
|
---|
| 127 | newLayerProsessor.Successor = newLayerReducer;
|
---|
| 128 |
|
---|
| 129 | newLayerLayerProcessor.Operator = incrEvaluatedSolutionsForNewLayer;
|
---|
| 130 |
|
---|
| 131 | newLayerReducer.Successor = incrOpenLayers;
|
---|
| 132 |
|
---|
[11590] | 133 | layerInitializer.LeftSideParameter.ActualName = "Layer";
|
---|
| 134 | layerInitializer.RightSideParameter.ActualName = "OpenLayers";
|
---|
[11609] | 135 | layerInitializer.Successor = correctAgeProcessor;
|
---|
[11586] | 136 |
|
---|
[11609] | 137 | correctAgeProcessor.Operator = correctAgeDecrementor;
|
---|
| 138 | correctAgeProcessor.Successor = incrEvaluatedSolutionsForNewLayer;
|
---|
| 139 |
|
---|
| 140 | correctAgeDecrementor.Increment = new IntValue(-1);
|
---|
| 141 | correctAgeDecrementor.ValueParameter.ActualName = "Age";
|
---|
| 142 |
|
---|
[11590] | 143 | incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = "EvaluatedSolutions";
|
---|
| 144 | incrEvaluatedSolutionsForNewLayer.AccumulateParameter.Value = new BoolValue(true);
|
---|
[11609] | 145 | incrEvaluatedSolutionsForNewLayer.Successor = mainOperator;
|
---|
[11586] | 146 |
|
---|
[12071] | 147 | newResultCollectionAssigner.LeftSideParameter.ActualName = "LayerResults";
|
---|
[11590] | 148 | newResultCollectionAssigner.RightSideParameter.Value = new ResultCollection();
|
---|
| 149 | newResultCollectionAssigner.Successor = mainOperator;
|
---|
| 150 | // TODO mainOperator increment age
|
---|
[11586] | 151 |
|
---|
[11590] | 152 | incrOpenLayers.ValueParameter.ActualName = "OpenLayers";
|
---|
| 153 | incrOpenLayers.Increment = new IntValue(1);
|
---|
[11609] | 154 | incrOpenLayers.Successor = newLayerResultsCollector;
|
---|
[11586] | 155 |
|
---|
[12071] | 156 | newLayerResultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("LayerResults", "Result set for each layer", "LayerResults"));
|
---|
[11609] | 157 | newLayerResultsCollector.CopyValue = new BoolValue(false);
|
---|
| 158 | newLayerResultsCollector.Successor = null;
|
---|
| 159 |
|
---|
[12036] | 160 | regenerateLayerZeroSelector.NumberOfSelectedSubScopesParameter.Value = new IntValue(1);
|
---|
| 161 | regenerateLayerZeroSelector.CopySelected = new BoolValue(false);
|
---|
| 162 | regenerateLayerZeroSelector.Successor = regenerateLayerZeroProsessor;
|
---|
[11586] | 163 |
|
---|
[12036] | 164 | regenerateLayerZeroProsessor.Operators.Add(new EmptyOperator());
|
---|
| 165 | regenerateLayerZeroProsessor.Operators.Add(regenerateLayerZeroLayerProsessor);
|
---|
| 166 | regenerateLayerZeroProsessor.Successor = regenerateLayerZeroReducer;
|
---|
| 167 |
|
---|
| 168 | regenerateLayerZeroLayerProsessor.Operator = subScopesRemover;
|
---|
| 169 |
|
---|
| 170 | regenerateLayerZeroReducer.Successor = layerSorter;
|
---|
| 171 |
|
---|
| 172 | layerSorter.Successor = resetGenSlr;
|
---|
| 173 |
|
---|
[11586] | 174 | subScopesRemover.Successor = solutionsCreator;
|
---|
| 175 |
|
---|
| 176 | solutionsCreator.Successor = initializeAgeProsessor;
|
---|
| 177 |
|
---|
| 178 | initializeAgeProsessor.Operator = initializeAge;
|
---|
[11590] | 179 | initializeAgeProsessor.Successor = incrEvaluatedSolutionsAfterReseeding;
|
---|
[11586] | 180 |
|
---|
| 181 | initializeAge.CollectedValues.Add(new ValueParameter<IntValue>("Age", new IntValue(0)));
|
---|
| 182 | initializeAge.Successor = null;
|
---|
| 183 |
|
---|
[11590] | 184 | incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = "EvaluatedSolutions";
|
---|
| 185 | incrEvaluatedSolutionsAfterReseeding.AccumulateParameter.Value = new BoolValue(true);
|
---|
| 186 | incrEvaluatedSolutionsAfterReseeding.Successor = null;
|
---|
[11586] | 187 |
|
---|
| 188 | resetGenSlr.LeftSideParameter.ActualName = "GenerationsSinceLastRefresh";
|
---|
[11609] | 189 | resetGenSlr.RightSideParameter.Value = new IntValue(0);
|
---|
[11586] | 190 | resetGenSlr.Successor = null;
|
---|
| 191 | }
|
---|
| 192 | }
|
---|
| 193 | } |
---|