Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Analysis/3.3/PopulationMinAverageMaxValueAnalyzer.cs @ 3623

Last change on this file since 3623 was 3623, checked in by swagner, 14 years ago

Worked on refactoring of algorithm analysis and tracing (#999)

  • added analyzers
File size: 5.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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 HeuristicLab.Core;
23using HeuristicLab.Data;
24using HeuristicLab.Operators;
25using HeuristicLab.Optimization;
26using HeuristicLab.Optimization.Operators;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Analysis {
31  /// <summary>
32  /// An operator which analyzes the minimum, average and maximum of a value in the current population.
33  /// </summary>
34  [Item("PopulationMinAverageMaxValueAnalyzer", "An operator which analyzes the minimum, average and maximum of a value in the current population.")]
35  [StorableClass]
36  public sealed class PopulationMinAverageMaxValueAnalyzer : AlgorithmOperator, IPopulationAnalyzer {
37    #region Parameter properties
38    public SubScopesLookupParameter<DoubleValue> ValueParameter {
39      get { return (SubScopesLookupParameter<DoubleValue>)Parameters["Value"]; }
40    }
41    public ValueLookupParameter<DoubleValue> MinValueParameter {
42      get { return (ValueLookupParameter<DoubleValue>)Parameters["MinValue"]; }
43    }
44    public ValueLookupParameter<DoubleValue> AverageValueParameter {
45      get { return (ValueLookupParameter<DoubleValue>)Parameters["AverageValue"]; }
46    }
47    public ValueLookupParameter<DoubleValue> MaxValueParameter {
48      get { return (ValueLookupParameter<DoubleValue>)Parameters["MaxValue"]; }
49    }
50    public ValueLookupParameter<DataTable> ValuesParameter {
51      get { return (ValueLookupParameter<DataTable>)Parameters["Values"]; }
52    }
53    public ValueLookupParameter<VariableCollection> ResultsParameter {
54      get { return (ValueLookupParameter<VariableCollection>)Parameters["Results"]; }
55    }
56    #endregion
57
58    [StorableConstructor]
59    private PopulationMinAverageMaxValueAnalyzer(bool deserializing) : base() { }
60    public PopulationMinAverageMaxValueAnalyzer()
61      : base() {
62      Initialize();
63    }
64
65    private void Initialize() {
66      #region Create parameters
67      Parameters.Add(new SubScopesLookupParameter<DoubleValue>("Value", "The value contained in each solution which should be analyzed."));
68      Parameters.Add(new ValueLookupParameter<DoubleValue>("MinValue", "The minimum of the value."));
69      Parameters.Add(new ValueLookupParameter<DoubleValue>("AverageValue", "The average of the value."));
70      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaxValue", "The maximum of the value."));
71      Parameters.Add(new ValueLookupParameter<DataTable>("Values", "The data table to store the minimum, average and maximum of the value."));
72      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The results collection where the analysis values should be stored."));
73      #endregion
74
75      #region Create operators
76      MinAverageMaxValueCalculator minAverageMaxValueCalculator = new MinAverageMaxValueCalculator();
77      DataTableValuesCollector dataTableValuesCollector = new DataTableValuesCollector();
78      ResultsCollector resultsCollector = new ResultsCollector();
79
80      minAverageMaxValueCalculator.AverageValueParameter.ActualName = "AverageValue";
81      minAverageMaxValueCalculator.MaxValueParameter.ActualName = "MaxValue";
82      minAverageMaxValueCalculator.MinValueParameter.ActualName = "MinValue";
83      minAverageMaxValueCalculator.ValueParameter.ActualName = "Value";
84
85      dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Minimum Value", null, "MinValue"));
86      dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Average Value", null, "AverageValue"));
87      dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Maximum Value", null, "MaxValue"));
88      dataTableValuesCollector.DataTableParameter.ActualName = "Values";
89
90      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Minimum Value", null, "MinValue"));
91      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Average Value", null, "AverageValue"));
92      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Maximum Value", null, "MaxValue"));
93      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Values"));
94      resultsCollector.ResultsParameter.ActualName = "Results";
95      #endregion
96
97      #region Create operator graph
98      OperatorGraph.InitialOperator = minAverageMaxValueCalculator;
99      minAverageMaxValueCalculator.Successor = dataTableValuesCollector;
100      dataTableValuesCollector.Successor = resultsCollector;
101      resultsCollector.Successor = null;
102      #endregion
103    }
104  }
105}
Note: See TracBrowser for help on using the repository browser.