Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2520_PersistenceReintegration/HeuristicLab.Algorithms.ALPS/3.3/Analyzers/OldestAverageYoungestAgeAnalyzer.cs @ 16559

Last change on this file since 16559 was 16559, checked in by jkarder, 5 years ago

#2520: renamed Fossil to Attic and set version to 1.0.0-pre01

File size: 6.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2019 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
22using System;
23using HeuristicLab.Analysis;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Operators;
28using HeuristicLab.Optimization;
29using HeuristicLab.Optimization.Operators;
30using HeuristicLab.Parameters;
31using HEAL.Attic;
32
33namespace HeuristicLab.Algorithms.ALPS {
34  [Item("OldestAverageYoungestAgeAnalyzer", "An operator which calculates the current oldest, average and youngest age in the scope tree.")]
35  [StorableType("1AE2C4EF-BFCB-439C-AD5E-00E7740FD3D0")]
36  public sealed class OldestAverageYoungestAgeAnalyzer : AlgorithmOperator, IAnalyzer {
37    #region Parameter properties
38    public IScopeTreeLookupParameter<DoubleValue> AgeParameter {
39      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Age"]; }
40    }
41    public IValueLookupParameter<DoubleValue> CurrentOldestAgeParameter {
42      get { return (IValueLookupParameter<DoubleValue>)Parameters["CurrentOldestAge"]; }
43    }
44    public IValueLookupParameter<DoubleValue> CurrentAverageAgeParameter {
45      get { return (IValueLookupParameter<DoubleValue>)Parameters["CurrentAverageAge"]; }
46    }
47    public IValueLookupParameter<DoubleValue> CurrentYoungestAgeParameter {
48      get { return (IValueLookupParameter<DoubleValue>)Parameters["CurrentYoungestAge"]; }
49    }
50    public IValueLookupParameter<DataTable> AgesParameter {
51      get { return (IValueLookupParameter<DataTable>)Parameters["Ages"]; }
52    }
53    public IValueLookupParameter<ResultCollection> ResultsParameter {
54      get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; }
55    }
56    #endregion
57
58    #region Properties
59    public bool EnabledByDefault {
60      get { return false; }
61    }
62    private OldestAverageYoungestAgeCalculator OldestAverageYoungestAgeCalculator {
63      get { return (OldestAverageYoungestAgeCalculator)OperatorGraph.InitialOperator; }
64    }
65    #endregion
66
67    #region Storing & Cloning
68    [StorableConstructor]
69    private OldestAverageYoungestAgeAnalyzer(StorableConstructorFlag _) : base(_) { }
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<DoubleValue>("Age", "The value which represents the age of a solution."));
82      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentOldestAge", "The oldest age value found in the current population."));
83      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentAverageAge", "The average age value of all solutions in the current population."));
84      Parameters.Add(new ValueLookupParameter<DoubleValue>("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<DoubleValue>("CurrentOldestAge", null, CurrentOldestAgeParameter.Name));
106      dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentAverageAge", null, CurrentAverageAgeParameter.Name));
107      dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentYoungestAge", null, CurrentYoungestAgeParameter.Name));
108      dataTableValuesCollector.DataTableParameter.ActualName = AgesParameter.Name;
109
110      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(AgesParameter.Name));
111      resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name;
112      #endregion
113
114      #region Create operator graph
115      OperatorGraph.InitialOperator = oldestAverageYoungestAgeCalculator;
116      oldestAverageYoungestAgeCalculator.Successor = dataTableValuesCollector;
117      dataTableValuesCollector.Successor = resultsCollector;
118      resultsCollector.Successor = null;
119      #endregion
120
121      Initialize();
122    }
123
124    [StorableHook(HookType.AfterDeserialization)]
125    private void AfterDeserialization() {
126      Initialize();
127    }
128
129    private void Initialize() {
130      AgeParameter.DepthChanged += new EventHandler(AgeParameter_DepthChanged);
131    }
132
133    private void AgeParameter_DepthChanged(object sender, EventArgs e) {
134      OldestAverageYoungestAgeCalculator.AgeParameter.Depth = AgeParameter.Depth;
135    }
136  }
137}
Note: See TracBrowser for help on using the repository browser.