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 |
|
---|
22 | using HeuristicLab.Common;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Data;
|
---|
25 | using HeuristicLab.Operators;
|
---|
26 | using HeuristicLab.Optimization;
|
---|
27 | using HeuristicLab.Optimization.Operators;
|
---|
28 | using HeuristicLab.Parameters;
|
---|
29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.Algorithms.ALPS {
|
---|
32 | [Item("LayerOpener", "")]
|
---|
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 | } |
---|