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 |
|
---|
22 | using System.Linq;
|
---|
23 | using HeuristicLab.Common;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 | using HeuristicLab.Operators;
|
---|
27 | using HeuristicLab.Optimization;
|
---|
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 |
|
---|
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 incrOpenLayers = new IntCounter() { Name = "Incr. OpenLayers" };
|
---|
60 | var newLayerProsessor = new LastSubScopeProcessor();
|
---|
61 | var layerInitializer = new Assigner() { Name = "Init Layer" };
|
---|
62 | var incrEvaluatedSolutionsForNewLayer = new SubScopesCounter() { Name = "Update EvaluatedSolutions" };
|
---|
63 | var newResultCollectionAssigner = new Assigner() { Name = "Empty Results" };
|
---|
64 | var regenerateLayerZeroProsessor = new FirstSubScopeProcessor();
|
---|
65 | var subScopesRemover = new SubScopesRemover();
|
---|
66 | var solutionsCreator = new SolutionsCreator();
|
---|
67 | var initializeAgeProsessor = new UniformSubScopesProcessor();
|
---|
68 | var initializeAge = new VariableCreator() { Name = "Initialize Age" };
|
---|
69 | var incrEvaluatedSolutionsAfterReseeding = new SubScopesCounter() { Name = "Update EvaluatedSolutions" };
|
---|
70 | var resetGenSlr = new Assigner() { Name = "Reset GenerationsSinceLastRefresh" };
|
---|
71 |
|
---|
72 | OperatorGraph.InitialOperator = incGenSlr;
|
---|
73 |
|
---|
74 | incGenSlr.ValueParameter.ActualName = "GenerationsSinceLastRefresh";
|
---|
75 | incGenSlr.Increment = new IntValue(1);
|
---|
76 | incGenSlr.Successor = genSlrEqAgeGap;
|
---|
77 |
|
---|
78 | genSlrEqAgeGap.LeftSideParameter.ActualName = "GenerationsSinceLastRefresh";
|
---|
79 | genSlrEqAgeGap.RightSideParameter.ActualName = "AgeGap";
|
---|
80 | genSlrEqAgeGap.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
|
---|
81 | genSlrEqAgeGap.ResultParameter.ActualName = "UpdateLayers";
|
---|
82 | genSlrEqAgeGap.Successor = updateLayersBranch;
|
---|
83 |
|
---|
84 | updateLayersBranch.ConditionParameter.ActualName = "UpdateLayers";
|
---|
85 | updateLayersBranch.TrueBranch = openNewLayerCalculator;
|
---|
86 |
|
---|
87 | //openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
|
---|
88 | //openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("AgeGap"));
|
---|
89 | //openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("OpenLayers"));
|
---|
90 | //openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("NumberOfLayers"));
|
---|
91 | //openNewLayerCalculator.ExpressionParameter.Value = new StringValue("Generations AgeLimits [] OpenedLayers 1 - 1 + = false OpenLayers NumberOfLayers < if");
|
---|
92 | //openNewLayerCalculator.ExpressionResultParameter.ActualName = "OpenNewLayer";
|
---|
93 | openNewLayerCalculator.Successor = openNewLayerBranch;
|
---|
94 |
|
---|
95 | openNewLayerBranch.ConditionParameter.ActualName = "OpenNewLayer";
|
---|
96 | openNewLayerBranch.TrueBranch = layerCloner;
|
---|
97 | openNewLayerBranch.Successor = regenerateLayerZeroProsessor;
|
---|
98 |
|
---|
99 | layerCloner.Successor = newLayerProsessor;
|
---|
100 |
|
---|
101 | newLayerProsessor.Operator = layerInitializer;
|
---|
102 | newLayerProsessor.Successor = incrOpenLayers;
|
---|
103 |
|
---|
104 | layerInitializer.LeftSideParameter.ActualName = "Layer";
|
---|
105 | layerInitializer.RightSideParameter.ActualName = "OpenLayers";
|
---|
106 | layerInitializer.Successor = incrEvaluatedSolutionsForNewLayer;
|
---|
107 |
|
---|
108 | incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = "EvaluatedSolutions";
|
---|
109 | incrEvaluatedSolutionsForNewLayer.AccumulateParameter.Value = new BoolValue(true);
|
---|
110 | incrEvaluatedSolutionsForNewLayer.Successor = newResultCollectionAssigner;
|
---|
111 |
|
---|
112 | newResultCollectionAssigner.LeftSideParameter.ActualName = "Results";
|
---|
113 | newResultCollectionAssigner.RightSideParameter.Value = new ResultCollection();
|
---|
114 | newResultCollectionAssigner.Successor = mainOperator;
|
---|
115 | // TODO mainOperator increment age
|
---|
116 |
|
---|
117 | incrOpenLayers.ValueParameter.ActualName = "OpenLayers";
|
---|
118 | incrOpenLayers.Increment = new IntValue(1);
|
---|
119 | incrOpenLayers.Successor = null;
|
---|
120 |
|
---|
121 | regenerateLayerZeroProsessor.Operator = subScopesRemover;
|
---|
122 | regenerateLayerZeroProsessor.Successor = resetGenSlr;
|
---|
123 |
|
---|
124 | subScopesRemover.Successor = solutionsCreator;
|
---|
125 |
|
---|
126 | solutionsCreator.Successor = initializeAgeProsessor;
|
---|
127 |
|
---|
128 | initializeAgeProsessor.Operator = initializeAge;
|
---|
129 | initializeAgeProsessor.Successor = incrEvaluatedSolutionsAfterReseeding;
|
---|
130 |
|
---|
131 | initializeAge.CollectedValues.Add(new ValueParameter<IntValue>("Age", new IntValue(0)));
|
---|
132 | initializeAge.Successor = null;
|
---|
133 |
|
---|
134 | incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = "EvaluatedSolutions";
|
---|
135 | incrEvaluatedSolutionsAfterReseeding.AccumulateParameter.Value = new BoolValue(true);
|
---|
136 | incrEvaluatedSolutionsAfterReseeding.Successor = null;
|
---|
137 |
|
---|
138 | resetGenSlr.LeftSideParameter.ActualName = "GenerationsSinceLastRefresh";
|
---|
139 | resetGenSlr.RightSideParameter.Value = new IntValue(1);
|
---|
140 | resetGenSlr.Successor = null;
|
---|
141 | }
|
---|
142 | }
|
---|
143 | } |
---|