[12046] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16453] | 3 | * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[12046] | 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
|
---|
[13046] | 38 | public IScopeTreeLookupParameter<DoubleValue> AgeParameter {
|
---|
| 39 | get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Age"]; }
|
---|
[12046] | 40 | }
|
---|
[13046] | 41 | public IValueLookupParameter<DoubleValue> CurrentOldestAgeParameter {
|
---|
| 42 | get { return (IValueLookupParameter<DoubleValue>)Parameters["CurrentOldestAge"]; }
|
---|
[12046] | 43 | }
|
---|
[13046] | 44 | public IValueLookupParameter<DoubleValue> CurrentAverageAgeParameter {
|
---|
| 45 | get { return (IValueLookupParameter<DoubleValue>)Parameters["CurrentAverageAge"]; }
|
---|
[12046] | 46 | }
|
---|
[13046] | 47 | public IValueLookupParameter<DoubleValue> CurrentYoungestAgeParameter {
|
---|
| 48 | get { return (IValueLookupParameter<DoubleValue>)Parameters["CurrentYoungestAge"]; }
|
---|
[12046] | 49 | }
|
---|
| 50 | public IValueLookupParameter<DataTable> AgesParameter {
|
---|
| 51 | get { return (IValueLookupParameter<DataTable>)Parameters["Ages"]; }
|
---|
| 52 | }
|
---|
[13127] | 53 | public IValueLookupParameter<ResultCollection> ResultsParameter {
|
---|
| 54 | get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; }
|
---|
[12046] | 55 | }
|
---|
| 56 | #endregion
|
---|
| 57 |
|
---|
| 58 | #region Properties
|
---|
| 59 | public bool EnabledByDefault {
|
---|
[12996] | 60 | get { return false; }
|
---|
[12046] | 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
|
---|
[13046] | 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."));
|
---|
[12046] | 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 |
|
---|
[13046] | 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));
|
---|
[12046] | 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 | } |
---|