Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Analysis/3.3/BestAverageWorstQualityAnalyzer.cs @ 4525

Last change on this file since 4525 was 3787, checked in by abeham, 14 years ago

#893

  • Removed best known quality tracking from BestAverageWorstQualityAnalyzer
  • Added best known quality / solution tracking to problem specific analyzers
File size: 10.7 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 System;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization;
28using HeuristicLab.Optimization.Operators;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31
32namespace HeuristicLab.Analysis {
33  /// <summary>
34  /// An operator which analyzes the best, average and worst quality of solutions in the scope tree.
35  /// </summary>
36  [Item("BestAverageWorstQualityAnalyzer", "An operator which analyzes the best, average and worst quality of solutions in the scope tree.")]
37  [StorableClass]
38  public sealed class BestAverageWorstQualityAnalyzer : AlgorithmOperator, IAnalyzer {
39    #region Parameter properties
40    public ValueLookupParameter<BoolValue> MaximizationParameter {
41      get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
42    }
43    public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
44      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
45    }
46    public ValueLookupParameter<DoubleValue> BestKnownQualityParameter {
47      get { return (ValueLookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
48    }
49    public ValueLookupParameter<DoubleValue> BestQualityParameter {
50      get { return (ValueLookupParameter<DoubleValue>)Parameters["BestQuality"]; }
51    }
52    public ValueLookupParameter<DoubleValue> CurrentBestQualityParameter {
53      get { return (ValueLookupParameter<DoubleValue>)Parameters["CurrentBestQuality"]; }
54    }
55    public ValueLookupParameter<DoubleValue> CurrentAverageQualityParameter {
56      get { return (ValueLookupParameter<DoubleValue>)Parameters["CurrentAverageQuality"]; }
57    }
58    public ValueLookupParameter<DoubleValue> CurrentWorstQualityParameter {
59      get { return (ValueLookupParameter<DoubleValue>)Parameters["CurrentWorstQuality"]; }
60    }
61    public ValueLookupParameter<DataTable> QualitiesParameter {
62      get { return (ValueLookupParameter<DataTable>)Parameters["Qualities"]; }
63    }
64    public ValueLookupParameter<DoubleValue> AbsoluteDifferenceBestKnownToBestParameter {
65      get { return (ValueLookupParameter<DoubleValue>)Parameters["AbsoluteDifferenceBestKnownToBest"]; }
66    }
67    public ValueLookupParameter<PercentValue> RelativeDifferenceBestKnownToBestParameter {
68      get { return (ValueLookupParameter<PercentValue>)Parameters["RelativeDifferenceBestKnownToBest"]; }
69    }
70    public ValueLookupParameter<VariableCollection> ResultsParameter {
71      get { return (ValueLookupParameter<VariableCollection>)Parameters["Results"]; }
72    }
73    #endregion
74
75    #region Properties
76    private BestQualityMemorizer BestQualityMemorizer {
77      get { return (BestQualityMemorizer)OperatorGraph.InitialOperator; }
78    }
79    private BestAverageWorstQualityCalculator BestAverageWorstQualityCalculator {
80      get { return (BestAverageWorstQualityCalculator)BestQualityMemorizer.Successor; }
81    }
82    #endregion
83
84    public BestAverageWorstQualityAnalyzer()
85      : base() {
86      #region Create parameters
87      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
88      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
89      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
90      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestQuality", "The best quality value found in the current run."));
91      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentBestQuality", "The best quality value found in the current population."));
92      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentAverageQuality", "The average quality value of all solutions in the current population."));
93      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentWorstQuality", "The worst quality value found in the current population."));
94      Parameters.Add(new ValueLookupParameter<DataTable>("Qualities", "The data table to store the current best, current average, current worst, best and best known quality value."));
95      Parameters.Add(new ValueLookupParameter<DoubleValue>("AbsoluteDifferenceBestKnownToBest", "The absolute difference of the best known quality value to the best quality value."));
96      Parameters.Add(new ValueLookupParameter<PercentValue>("RelativeDifferenceBestKnownToBest", "The relative difference of the best known quality value to the best quality value."));
97      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The results collection where the analysis values should be stored."));
98      #endregion
99
100      #region Create operators
101      BestQualityMemorizer bestQualityMemorizer = new BestQualityMemorizer();
102      BestAverageWorstQualityCalculator bestAverageWorstQualityCalculator = new BestAverageWorstQualityCalculator();
103      DataTableValuesCollector dataTableValuesCollector = new DataTableValuesCollector();
104      QualityDifferenceCalculator qualityDifferenceCalculator = new QualityDifferenceCalculator();
105      ResultsCollector resultsCollector = new ResultsCollector();
106
107      bestQualityMemorizer.BestQualityParameter.ActualName = BestQualityParameter.Name;
108      bestQualityMemorizer.MaximizationParameter.ActualName = MaximizationParameter.Name;
109      bestQualityMemorizer.QualityParameter.ActualName = QualityParameter.Name;
110      bestQualityMemorizer.QualityParameter.Depth = QualityParameter.Depth;
111
112      bestAverageWorstQualityCalculator.AverageQualityParameter.ActualName = CurrentAverageQualityParameter.Name;
113      bestAverageWorstQualityCalculator.BestQualityParameter.ActualName = CurrentBestQualityParameter.Name;
114      bestAverageWorstQualityCalculator.MaximizationParameter.ActualName = MaximizationParameter.Name;
115      bestAverageWorstQualityCalculator.QualityParameter.ActualName = QualityParameter.Name;
116      bestAverageWorstQualityCalculator.QualityParameter.Depth = QualityParameter.Depth;
117      bestAverageWorstQualityCalculator.WorstQualityParameter.ActualName = CurrentWorstQualityParameter.Name;
118
119      dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentBestQuality", null, CurrentBestQualityParameter.Name));
120      dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentAverageQuality", null, CurrentAverageQualityParameter.Name));
121      dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentWorstQuality", null, CurrentWorstQualityParameter.Name));
122      dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("BestQuality", null, BestQualityParameter.Name));
123      dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("BestKnownQuality", null, BestKnownQualityParameter.Name));
124      dataTableValuesCollector.DataTableParameter.ActualName = QualitiesParameter.Name;
125
126      qualityDifferenceCalculator.AbsoluteDifferenceParameter.ActualName = AbsoluteDifferenceBestKnownToBestParameter.Name;
127      qualityDifferenceCalculator.FirstQualityParameter.ActualName = BestKnownQualityParameter.Name;
128      qualityDifferenceCalculator.RelativeDifferenceParameter.ActualName = RelativeDifferenceBestKnownToBestParameter.Name;
129      qualityDifferenceCalculator.SecondQualityParameter.ActualName = BestQualityParameter.Name;
130
131      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentBestQuality", null, CurrentBestQualityParameter.Name));
132      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentAverageQuality", null, CurrentAverageQualityParameter.Name));
133      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentWorstQuality", null, CurrentWorstQualityParameter.Name));
134      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("BestQuality", null, BestQualityParameter.Name));
135      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("BestKnownQuality", null, BestKnownQualityParameter.Name));
136      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("AbsoluteDifferenceBestKnownToBest", null, AbsoluteDifferenceBestKnownToBestParameter.Name));
137      resultsCollector.CollectedValues.Add(new LookupParameter<PercentValue>("RelativeDifferenceBestKnownToBest", null, RelativeDifferenceBestKnownToBestParameter.Name));
138      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(QualitiesParameter.Name));
139      resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name;
140      #endregion
141
142      #region Create operator graph
143      OperatorGraph.InitialOperator = bestQualityMemorizer;
144      bestQualityMemorizer.Successor = bestAverageWorstQualityCalculator;
145      bestAverageWorstQualityCalculator.Successor = dataTableValuesCollector;
146      dataTableValuesCollector.Successor = qualityDifferenceCalculator;
147      qualityDifferenceCalculator.Successor = resultsCollector;
148      resultsCollector.Successor = null;
149      #endregion
150
151      Initialize();
152    }
153    [StorableConstructor]
154    private BestAverageWorstQualityAnalyzer(bool deserializing) : base() { }
155
156    [StorableHook(HookType.AfterDeserialization)]
157    private void Initialize() {
158      QualityParameter.DepthChanged += new EventHandler(QualityParameter_DepthChanged);
159    }
160
161    public override IDeepCloneable Clone(Cloner cloner) {
162      BestAverageWorstQualityAnalyzer clone = (BestAverageWorstQualityAnalyzer)base.Clone(cloner);
163      clone.Initialize();
164      return clone;
165    }
166
167    private void QualityParameter_DepthChanged(object sender, System.EventArgs e) {
168      BestQualityMemorizer.QualityParameter.Depth = QualityParameter.Depth;
169      BestAverageWorstQualityCalculator.QualityParameter.Depth = QualityParameter.Depth;
170    }
171  }
172}
Note: See TracBrowser for help on using the repository browser.