[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;
|
---|
| 31 |
|
---|
| 32 | namespace HeuristicLab.Algorithms.ALPS {
|
---|
| 33 | [Item("LayerUpdator", "Operator which manages the reseeding and creation of layers.")]
|
---|
| 34 | [StorableClass]
|
---|
| 35 | public class LayerUpdator : AlgorithmOperator {
|
---|
| 36 |
|
---|
[11590] | 37 | public SolutionsCreator SolutionsCreator {
|
---|
| 38 | get { return OperatorGraph.Iterate().OfType<SolutionsCreator>().First(); }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
[11586] | 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?" };
|
---|
[11609] | 58 | //var layerCloner = new LastSubScopeCloner() { Name = "Copy Lower Layer" };
|
---|
| 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" };
|
---|
[11586] | 62 | var newLayerProsessor = new LastSubScopeProcessor();
|
---|
[11590] | 63 | var layerInitializer = new Assigner() { Name = "Init Layer" };
|
---|
[11609] | 64 | var correctAgeProcessor = new UniformSubScopesProcessor() { Name = "Hack: Decrement Age" };
|
---|
| 65 | var correctAgeDecrementor = new IntCounter() { Name = "Age = Age - 1" };
|
---|
[11590] | 66 | var incrEvaluatedSolutionsForNewLayer = new SubScopesCounter() { Name = "Update EvaluatedSolutions" };
|
---|
| 67 | var newResultCollectionAssigner = new Assigner() { Name = "Empty Results" };
|
---|
[11586] | 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" };
|
---|
[11590] | 73 | var incrEvaluatedSolutionsAfterReseeding = new SubScopesCounter() { Name = "Update EvaluatedSolutions" };
|
---|
[11586] | 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 |
|
---|
[11590] | 88 | updateLayersBranch.ConditionParameter.ActualName = "UpdateLayers";
|
---|
[11586] | 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";
|
---|
[11609] | 100 | openNewLayerBranch.TrueBranch = layerCreator;
|
---|
[11586] | 101 | openNewLayerBranch.Successor = regenerateLayerZeroProsessor;
|
---|
| 102 |
|
---|
[11609] | 103 | //layerCloner.Successor = newLayerProsessor;
|
---|
| 104 | layerCreator.Successor = newLayerProsessor;
|
---|
[11586] | 105 |
|
---|
[11609] | 106 | //newLayerProsessor.Operator = layerInitializer;
|
---|
| 107 | newLayerProsessor.Operator = incrEvaluatedSolutionsForNewLayer;
|
---|
[11590] | 108 | newLayerProsessor.Successor = incrOpenLayers;
|
---|
[11586] | 109 |
|
---|
[11590] | 110 | layerInitializer.LeftSideParameter.ActualName = "Layer";
|
---|
| 111 | layerInitializer.RightSideParameter.ActualName = "OpenLayers";
|
---|
[11609] | 112 | layerInitializer.Successor = correctAgeProcessor;
|
---|
[11586] | 113 |
|
---|
[11609] | 114 | correctAgeProcessor.Operator = correctAgeDecrementor;
|
---|
| 115 | correctAgeProcessor.Successor = incrEvaluatedSolutionsForNewLayer;
|
---|
| 116 |
|
---|
| 117 | correctAgeDecrementor.Increment = new IntValue(-1);
|
---|
| 118 | correctAgeDecrementor.ValueParameter.ActualName = "Age";
|
---|
| 119 |
|
---|
[11590] | 120 | incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = "EvaluatedSolutions";
|
---|
| 121 | incrEvaluatedSolutionsForNewLayer.AccumulateParameter.Value = new BoolValue(true);
|
---|
[11609] | 122 | //incrEvaluatedSolutionsForNewLayer.Successor = newResultCollectionAssigner;
|
---|
| 123 | incrEvaluatedSolutionsForNewLayer.Successor = mainOperator;
|
---|
[11586] | 124 |
|
---|
[11590] | 125 | newResultCollectionAssigner.LeftSideParameter.ActualName = "Results";
|
---|
| 126 | newResultCollectionAssigner.RightSideParameter.Value = new ResultCollection();
|
---|
| 127 | newResultCollectionAssigner.Successor = mainOperator;
|
---|
| 128 | // TODO mainOperator increment age
|
---|
[11586] | 129 |
|
---|
[11590] | 130 | incrOpenLayers.ValueParameter.ActualName = "OpenLayers";
|
---|
| 131 | incrOpenLayers.Increment = new IntValue(1);
|
---|
[11609] | 132 | incrOpenLayers.Successor = newLayerResultsCollector;
|
---|
[11586] | 133 |
|
---|
[11609] | 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 |
|
---|
[11586] | 138 | regenerateLayerZeroProsessor.Operator = subScopesRemover;
|
---|
| 139 | regenerateLayerZeroProsessor.Successor = resetGenSlr;
|
---|
| 140 |
|
---|
| 141 | subScopesRemover.Successor = solutionsCreator;
|
---|
| 142 |
|
---|
| 143 | solutionsCreator.Successor = initializeAgeProsessor;
|
---|
| 144 |
|
---|
| 145 | initializeAgeProsessor.Operator = initializeAge;
|
---|
[11590] | 146 | initializeAgeProsessor.Successor = incrEvaluatedSolutionsAfterReseeding;
|
---|
[11586] | 147 |
|
---|
| 148 | initializeAge.CollectedValues.Add(new ValueParameter<IntValue>("Age", new IntValue(0)));
|
---|
| 149 | initializeAge.Successor = null;
|
---|
| 150 |
|
---|
[11590] | 151 | incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = "EvaluatedSolutions";
|
---|
| 152 | incrEvaluatedSolutionsAfterReseeding.AccumulateParameter.Value = new BoolValue(true);
|
---|
| 153 | incrEvaluatedSolutionsAfterReseeding.Successor = null;
|
---|
[11586] | 154 |
|
---|
| 155 | resetGenSlr.LeftSideParameter.ActualName = "GenerationsSinceLastRefresh";
|
---|
[11609] | 156 | resetGenSlr.RightSideParameter.Value = new IntValue(0);
|
---|
[11586] | 157 | resetGenSlr.Successor = null;
|
---|
| 158 | }
|
---|
| 159 | }
|
---|
| 160 | } |
---|