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 |
|
---|
22 | using HeuristicLab.Core;
|
---|
23 | using HeuristicLab.Data;
|
---|
24 | using HeuristicLab.Operators;
|
---|
25 | using HeuristicLab.Optimization;
|
---|
26 | using HeuristicLab.Optimization.Operators;
|
---|
27 | using HeuristicLab.Parameters;
|
---|
28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Analysis {
|
---|
31 | /// <summary>
|
---|
32 | /// An operator which analyzes the best, average and worst solution quality in the current population.
|
---|
33 | /// </summary>
|
---|
34 | [Item("PopulationBestAverageWorstQualityAnalyzer", "An operator which analyzes the best, average and worst solution quality in the current population.")]
|
---|
35 | [StorableClass]
|
---|
36 | public sealed class PopulationBestAverageWorstQualityAnalyzer : AlgorithmOperator, IAnalyzer {
|
---|
37 | #region Parameter properties
|
---|
38 | public ValueLookupParameter<BoolValue> MaximizationParameter {
|
---|
39 | get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
|
---|
40 | }
|
---|
41 | public SubScopesLookupParameter<DoubleValue> QualityParameter {
|
---|
42 | get { return (SubScopesLookupParameter<DoubleValue>)Parameters["Quality"]; }
|
---|
43 | }
|
---|
44 | public ValueLookupParameter<DoubleValue> BestKnownQualityParameter {
|
---|
45 | get { return (ValueLookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
|
---|
46 | }
|
---|
47 | public ValueLookupParameter<DoubleValue> BestQualityParameter {
|
---|
48 | get { return (ValueLookupParameter<DoubleValue>)Parameters["BestQuality"]; }
|
---|
49 | }
|
---|
50 | public ValueLookupParameter<DoubleValue> CurrentBestQualityParameter {
|
---|
51 | get { return (ValueLookupParameter<DoubleValue>)Parameters["CurrentBestQuality"]; }
|
---|
52 | }
|
---|
53 | public ValueLookupParameter<DoubleValue> CurrentAverageQualityParameter {
|
---|
54 | get { return (ValueLookupParameter<DoubleValue>)Parameters["CurrentAverageQuality"]; }
|
---|
55 | }
|
---|
56 | public ValueLookupParameter<DoubleValue> CurrentWorstQualityParameter {
|
---|
57 | get { return (ValueLookupParameter<DoubleValue>)Parameters["CurrentWorstQuality"]; }
|
---|
58 | }
|
---|
59 | public ValueLookupParameter<DataTable> QualitiesParameter {
|
---|
60 | get { return (ValueLookupParameter<DataTable>)Parameters["Qualities"]; }
|
---|
61 | }
|
---|
62 | public ValueLookupParameter<DoubleValue> AbsoluteDifferenceBestKnownToBestParameter {
|
---|
63 | get { return (ValueLookupParameter<DoubleValue>)Parameters["AbsoluteDifferenceBestKnownToBest"]; }
|
---|
64 | }
|
---|
65 | public ValueLookupParameter<PercentValue> RelativeDifferenceBestKnownToBestParameter {
|
---|
66 | get { return (ValueLookupParameter<PercentValue>)Parameters["RelativeDifferenceBestKnownToBest"]; }
|
---|
67 | }
|
---|
68 | public ValueLookupParameter<VariableCollection> ResultsParameter {
|
---|
69 | get { return (ValueLookupParameter<VariableCollection>)Parameters["Results"]; }
|
---|
70 | }
|
---|
71 | #endregion
|
---|
72 |
|
---|
73 | [StorableConstructor]
|
---|
74 | private PopulationBestAverageWorstQualityAnalyzer(bool deserializing) : base() { }
|
---|
75 | public PopulationBestAverageWorstQualityAnalyzer()
|
---|
76 | : base() {
|
---|
77 | Initialize();
|
---|
78 | }
|
---|
79 |
|
---|
80 | private void Initialize() {
|
---|
81 | #region Create parameters
|
---|
82 | Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
|
---|
83 | Parameters.Add(new SubScopesLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
|
---|
84 | Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
|
---|
85 | Parameters.Add(new ValueLookupParameter<DoubleValue>("BestQuality", "The best quality value found in the current run."));
|
---|
86 | Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentBestQuality", "The best quality value found in the current population."));
|
---|
87 | Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentAverageQuality", "The average quality value of all solutions in the current population."));
|
---|
88 | Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentWorstQuality", "The worst quality value found in the current population."));
|
---|
89 | Parameters.Add(new ValueLookupParameter<DataTable>("Qualities", "The data table to store the current best, current average, current worst, best and best known quality value."));
|
---|
90 | Parameters.Add(new ValueLookupParameter<DoubleValue>("AbsoluteDifferenceBestKnownToBest", "The absolute difference of the best known quality value to the best quality value."));
|
---|
91 | Parameters.Add(new ValueLookupParameter<PercentValue>("RelativeDifferenceBestKnownToBest", "The relative difference of the best known quality value to the best quality value."));
|
---|
92 | Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The results collection where the analysis values should be stored."));
|
---|
93 | #endregion
|
---|
94 |
|
---|
95 | #region Create operators
|
---|
96 | BestQualityMemorizer bestQualityMemorizer1 = new BestQualityMemorizer();
|
---|
97 | BestQualityMemorizer bestQualityMemorizer2 = new BestQualityMemorizer();
|
---|
98 | BestAverageWorstQualityCalculator bestAverageWorstQualityCalculator = new BestAverageWorstQualityCalculator();
|
---|
99 | DataTableValuesCollector dataTableValuesCollector = new DataTableValuesCollector();
|
---|
100 | QualityDifferenceCalculator qualityDifferenceCalculator = new QualityDifferenceCalculator();
|
---|
101 | ResultsCollector resultsCollector = new ResultsCollector();
|
---|
102 |
|
---|
103 | bestQualityMemorizer1.BestQualityParameter.ActualName = "BestQuality";
|
---|
104 | bestQualityMemorizer1.MaximizationParameter.ActualName = "Maximization";
|
---|
105 | bestQualityMemorizer1.QualityParameter.ActualName = "Quality";
|
---|
106 |
|
---|
107 | bestQualityMemorizer2.BestQualityParameter.ActualName = "BestKnownQuality";
|
---|
108 | bestQualityMemorizer2.MaximizationParameter.ActualName = "Maximization";
|
---|
109 | bestQualityMemorizer2.QualityParameter.ActualName = "Quality";
|
---|
110 |
|
---|
111 | bestAverageWorstQualityCalculator.AverageQualityParameter.ActualName = "CurrentAverageQuality";
|
---|
112 | bestAverageWorstQualityCalculator.BestQualityParameter.ActualName = "CurrentBestQuality";
|
---|
113 | bestAverageWorstQualityCalculator.MaximizationParameter.ActualName = "Maximization";
|
---|
114 | bestAverageWorstQualityCalculator.QualityParameter.ActualName = "Quality";
|
---|
115 | bestAverageWorstQualityCalculator.WorstQualityParameter.ActualName = "CurrentWorstQuality";
|
---|
116 |
|
---|
117 | dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Best Quality", null, "CurrentBestQuality"));
|
---|
118 | dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Average Quality", null, "CurrentAverageQuality"));
|
---|
119 | dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Worst Quality", null, "CurrentWorstQuality"));
|
---|
120 | dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality"));
|
---|
121 | dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, "BestKnownQuality"));
|
---|
122 | dataTableValuesCollector.DataTableParameter.ActualName = "Qualities";
|
---|
123 |
|
---|
124 | qualityDifferenceCalculator.AbsoluteDifferenceParameter.ActualName = "AbsoluteDifferenceBestKnownToBest";
|
---|
125 | qualityDifferenceCalculator.FirstQualityParameter.ActualName = "BestKnownQuality";
|
---|
126 | qualityDifferenceCalculator.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest";
|
---|
127 | qualityDifferenceCalculator.SecondQualityParameter.ActualName = "BestQuality";
|
---|
128 |
|
---|
129 | resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Best Quality", null, "CurrentBestQuality"));
|
---|
130 | resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Average Quality", null, "CurrentAverageQuality"));
|
---|
131 | resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Worst Quality", null, "CurrentWorstQuality"));
|
---|
132 | resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality"));
|
---|
133 | resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, "BestKnownQuality"));
|
---|
134 | resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Absolute Difference of Best Known Quality to Best Quality", null, "AbsoluteDifferenceBestKnownToBest"));
|
---|
135 | resultsCollector.CollectedValues.Add(new LookupParameter<PercentValue>("Relative Difference of Best Known Quality to Best Quality", null, "RelativeDifferenceBestKnownToBest"));
|
---|
136 | resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Qualities"));
|
---|
137 | resultsCollector.ResultsParameter.ActualName = "Results";
|
---|
138 | #endregion
|
---|
139 |
|
---|
140 | #region Create operator graph
|
---|
141 | OperatorGraph.InitialOperator = bestQualityMemorizer1;
|
---|
142 | bestQualityMemorizer1.Successor = bestQualityMemorizer2;
|
---|
143 | bestQualityMemorizer2.Successor = bestAverageWorstQualityCalculator;
|
---|
144 | bestAverageWorstQualityCalculator.Successor = dataTableValuesCollector;
|
---|
145 | dataTableValuesCollector.Successor = qualityDifferenceCalculator;
|
---|
146 | qualityDifferenceCalculator.Successor = resultsCollector;
|
---|
147 | resultsCollector.Successor = null;
|
---|
148 | #endregion
|
---|
149 | }
|
---|
150 | }
|
---|
151 | }
|
---|