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 System;
|
---|
23 | using HeuristicLab.Analysis;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Data;
|
---|
27 | using HeuristicLab.Operators;
|
---|
28 | using HeuristicLab.Optimization;
|
---|
29 | using HeuristicLab.Optimization.Operators;
|
---|
30 | using HeuristicLab.Parameters;
|
---|
31 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
32 |
|
---|
33 | namespace HeuristicLab.Algorithms.ALPS {
|
---|
34 | [Item("OldestAverageYoungestAgeAnalyzer", "An operator which calculates the current oldest, average and youngest age in the scope tree.")]
|
---|
35 | [StorableClass]
|
---|
36 | public sealed class OldestAverageYoungestAgeAnalyzer : AlgorithmOperator, IAnalyzer {
|
---|
37 | #region Parameter properties
|
---|
38 | public IScopeTreeLookupParameter<IntValue> AgeParameter {
|
---|
39 | get { return (IScopeTreeLookupParameter<IntValue>)Parameters["Age"]; }
|
---|
40 | }
|
---|
41 | public IValueLookupParameter<IntValue> CurrentOldestAgeParameter {
|
---|
42 | get { return (IValueLookupParameter<IntValue>)Parameters["CurrentOldestAge"]; }
|
---|
43 | }
|
---|
44 | public IValueLookupParameter<IntValue> CurrentAverageAgeParameter {
|
---|
45 | get { return (IValueLookupParameter<IntValue>)Parameters["CurrentAverageAge"]; }
|
---|
46 | }
|
---|
47 | public IValueLookupParameter<IntValue> CurrentYoungestAgeParameter {
|
---|
48 | get { return (IValueLookupParameter<IntValue>)Parameters["CurrentYoungestAge"]; }
|
---|
49 | }
|
---|
50 | public IValueLookupParameter<DataTable> AgesParameter {
|
---|
51 | get { return (IValueLookupParameter<DataTable>)Parameters["Ages"]; }
|
---|
52 | }
|
---|
53 | public ValueLookupParameter<ResultCollection> ResultsParameter {
|
---|
54 | get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
|
---|
55 | }
|
---|
56 | #endregion
|
---|
57 |
|
---|
58 | #region Properties
|
---|
59 | public bool EnabledByDefault {
|
---|
60 | get { return true; }
|
---|
61 | }
|
---|
62 | private OldestAverageYoungestAgeCalculator OldestAverageYoungestAgeCalculator {
|
---|
63 | get { return (OldestAverageYoungestAgeCalculator)OperatorGraph.InitialOperator; }
|
---|
64 | }
|
---|
65 | #endregion
|
---|
66 |
|
---|
67 | #region Storing & Cloning
|
---|
68 | [StorableConstructor]
|
---|
69 | private OldestAverageYoungestAgeAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
70 | private OldestAverageYoungestAgeAnalyzer(OldestAverageYoungestAgeAnalyzer original, Cloner cloner)
|
---|
71 | : base(original, cloner) {
|
---|
72 | Initialize();
|
---|
73 | }
|
---|
74 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
75 | return new OldestAverageYoungestAgeAnalyzer(this, cloner);
|
---|
76 | }
|
---|
77 | #endregion
|
---|
78 | public OldestAverageYoungestAgeAnalyzer()
|
---|
79 | : base() {
|
---|
80 | #region Create parameters
|
---|
81 | Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Age", "The value which represents the age of a solution."));
|
---|
82 | Parameters.Add(new ValueLookupParameter<IntValue>("CurrentOldestAge", "The oldest age value found in the current population."));
|
---|
83 | Parameters.Add(new ValueLookupParameter<IntValue>("CurrentAverageAge", "The average age value of all solutions in the current population."));
|
---|
84 | Parameters.Add(new ValueLookupParameter<IntValue>("CurrentYoungestAge", "The youngest age value found in the current population."));
|
---|
85 | Parameters.Add(new ValueLookupParameter<DataTable>("Ages", "The data table to store the current oldest, current average, current youngest age value."));
|
---|
86 | Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The results collection where the analysis values should be stored."));
|
---|
87 |
|
---|
88 | CurrentOldestAgeParameter.Hidden = true;
|
---|
89 | CurrentAverageAgeParameter.Hidden = true;
|
---|
90 | CurrentYoungestAgeParameter.Hidden = true;
|
---|
91 | AgesParameter.Hidden = true;
|
---|
92 | #endregion
|
---|
93 |
|
---|
94 | #region Create operators
|
---|
95 | var oldestAverageYoungestAgeCalculator = new OldestAverageYoungestAgeCalculator();
|
---|
96 | var dataTableValuesCollector = new DataTableValuesCollector();
|
---|
97 | var resultsCollector = new ResultsCollector();
|
---|
98 |
|
---|
99 | oldestAverageYoungestAgeCalculator.AverageAgeParameter.ActualName = CurrentAverageAgeParameter.Name;
|
---|
100 | oldestAverageYoungestAgeCalculator.OldestAgeParameter.ActualName = CurrentOldestAgeParameter.Name;
|
---|
101 | oldestAverageYoungestAgeCalculator.AgeParameter.ActualName = AgeParameter.Name;
|
---|
102 | oldestAverageYoungestAgeCalculator.AgeParameter.Depth = AgeParameter.Depth;
|
---|
103 | oldestAverageYoungestAgeCalculator.YoungestAgeParameter.ActualName = CurrentYoungestAgeParameter.Name;
|
---|
104 |
|
---|
105 | dataTableValuesCollector.CollectedValues.Add(new LookupParameter<IntValue>("CurrentOldestAge", null, CurrentOldestAgeParameter.Name));
|
---|
106 | dataTableValuesCollector.CollectedValues.Add(new LookupParameter<IntValue>("CurrentAverageAge", null, CurrentAverageAgeParameter.Name));
|
---|
107 | dataTableValuesCollector.CollectedValues.Add(new LookupParameter<IntValue>("CurrentYoungestAge", null, CurrentYoungestAgeParameter.Name));
|
---|
108 | dataTableValuesCollector.DataTableParameter.ActualName = AgesParameter.Name;
|
---|
109 |
|
---|
110 | //resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("CurrentOldestAge", null, CurrentOldestAgeParameter.Name));
|
---|
111 | //resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("CurrentAverageAge", null, CurrentAverageAgeParameter.Name));
|
---|
112 | //resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("CurrentYoungestAge", null, CurrentYoungestAgeParameter.Name));
|
---|
113 | resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(AgesParameter.Name));
|
---|
114 | resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name;
|
---|
115 | #endregion
|
---|
116 |
|
---|
117 | #region Create operator graph
|
---|
118 | OperatorGraph.InitialOperator = oldestAverageYoungestAgeCalculator;
|
---|
119 | oldestAverageYoungestAgeCalculator.Successor = dataTableValuesCollector;
|
---|
120 | dataTableValuesCollector.Successor = resultsCollector;
|
---|
121 | resultsCollector.Successor = null;
|
---|
122 | #endregion
|
---|
123 |
|
---|
124 | Initialize();
|
---|
125 | }
|
---|
126 |
|
---|
127 | [StorableHook(HookType.AfterDeserialization)]
|
---|
128 | private void AfterDeserialization() {
|
---|
129 | Initialize();
|
---|
130 | }
|
---|
131 |
|
---|
132 | private void Initialize() {
|
---|
133 | AgeParameter.DepthChanged += new EventHandler(AgeParameter_DepthChanged);
|
---|
134 | }
|
---|
135 |
|
---|
136 | private void AgeParameter_DepthChanged(object sender, EventArgs e) {
|
---|
137 | OldestAverageYoungestAgeCalculator.AgeParameter.Depth = AgeParameter.Depth;
|
---|
138 | }
|
---|
139 | }
|
---|
140 | } |
---|