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 solution qualities in the current population.
|
---|
33 | /// </summary>
|
---|
34 | [Item("PopulationQualityAnalyzer", "An operator which analyzes the solution qualities in the current population.")]
|
---|
35 | [StorableClass]
|
---|
36 | public sealed class PopulationQualityAnalyzer : AlgorithmOperator, IPopulationAnalyzer {
|
---|
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<DataTable> QualitiesParameter {
|
---|
51 | get { return (ValueLookupParameter<DataTable>)Parameters["Qualities"]; }
|
---|
52 | }
|
---|
53 | public ValueLookupParameter<DoubleValue> AbsoluteDifferenceBestKnownToBestParameter {
|
---|
54 | get { return (ValueLookupParameter<DoubleValue>)Parameters["AbsoluteDifferenceBestKnownToBest"]; }
|
---|
55 | }
|
---|
56 | public ValueLookupParameter<PercentValue> RelativeDifferenceBestKnownToBestParameter {
|
---|
57 | get { return (ValueLookupParameter<PercentValue>)Parameters["RelativeDifferenceBestKnownToBest"]; }
|
---|
58 | }
|
---|
59 | public ValueLookupParameter<VariableCollection> ResultsParameter {
|
---|
60 | get { return (ValueLookupParameter<VariableCollection>)Parameters["Results"]; }
|
---|
61 | }
|
---|
62 | #endregion
|
---|
63 |
|
---|
64 | [StorableConstructor]
|
---|
65 | private PopulationQualityAnalyzer(bool deserializing) : base() { }
|
---|
66 | public PopulationQualityAnalyzer()
|
---|
67 | : base() {
|
---|
68 | Initialize();
|
---|
69 | }
|
---|
70 |
|
---|
71 | private void Initialize() {
|
---|
72 | #region Create parameters
|
---|
73 | Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
|
---|
74 | Parameters.Add(new SubScopesLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
|
---|
75 | Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
|
---|
76 | Parameters.Add(new ValueLookupParameter<DoubleValue>("BestQuality", "The best quality value found in the current run."));
|
---|
77 | Parameters.Add(new ValueLookupParameter<DataTable>("Qualities", "The data table to store the best, best known and all other quality values."));
|
---|
78 | Parameters.Add(new ValueLookupParameter<DoubleValue>("AbsoluteDifferenceBestKnownToBest", "The absolute difference of the best known quality value to the best quality value."));
|
---|
79 | Parameters.Add(new ValueLookupParameter<PercentValue>("RelativeDifferenceBestKnownToBest", "The relative difference of the best known quality value to the best quality value."));
|
---|
80 | Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The results collection where the analysis values should be stored."));
|
---|
81 | #endregion
|
---|
82 |
|
---|
83 | #region Create operators
|
---|
84 | BestQualityMemorizer bestQualityMemorizer1 = new BestQualityMemorizer();
|
---|
85 | BestQualityMemorizer bestQualityMemorizer2 = new BestQualityMemorizer();
|
---|
86 | DataTableValuesCollector dataTableValuesCollector = new DataTableValuesCollector();
|
---|
87 | QualityDifferenceCalculator qualityDifferenceCalculator = new QualityDifferenceCalculator();
|
---|
88 | ResultsCollector resultsCollector = new ResultsCollector();
|
---|
89 |
|
---|
90 | bestQualityMemorizer1.BestQualityParameter.ActualName = "BestQuality";
|
---|
91 | bestQualityMemorizer1.MaximizationParameter.ActualName = "Maximization";
|
---|
92 | bestQualityMemorizer1.QualityParameter.ActualName = "Quality";
|
---|
93 |
|
---|
94 | bestQualityMemorizer2.BestQualityParameter.ActualName = "BestKnownQuality";
|
---|
95 | bestQualityMemorizer2.MaximizationParameter.ActualName = "Maximization";
|
---|
96 | bestQualityMemorizer2.QualityParameter.ActualName = "Quality";
|
---|
97 |
|
---|
98 | dataTableValuesCollector.CollectedValues.Add(new SubScopesLookupParameter<DoubleValue>("Quality", null, "Quality"));
|
---|
99 | dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality"));
|
---|
100 | dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, "BestKnownQuality"));
|
---|
101 | dataTableValuesCollector.DataTableParameter.ActualName = "Qualities";
|
---|
102 |
|
---|
103 | qualityDifferenceCalculator.AbsoluteDifferenceParameter.ActualName = "AbsoluteDifferenceBestKnownToBest";
|
---|
104 | qualityDifferenceCalculator.FirstQualityParameter.ActualName = "BestKnownQuality";
|
---|
105 | qualityDifferenceCalculator.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest";
|
---|
106 | qualityDifferenceCalculator.SecondQualityParameter.ActualName = "BestQuality";
|
---|
107 |
|
---|
108 | resultsCollector.CollectedValues.Add(new SubScopesLookupParameter<DoubleValue>("Quality", null, "Quality"));
|
---|
109 | resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality"));
|
---|
110 | resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, "BestKnownQuality"));
|
---|
111 | resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Absolute Difference of Best Known Quality to Best Quality", null, "AbsoluteDifferenceBestKnownToBest"));
|
---|
112 | resultsCollector.CollectedValues.Add(new LookupParameter<PercentValue>("Relative Difference of Best Known Quality to Best Quality", null, "RelativeDifferenceBestKnownToBest"));
|
---|
113 | resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Qualities"));
|
---|
114 | resultsCollector.ResultsParameter.ActualName = "Results";
|
---|
115 | #endregion
|
---|
116 |
|
---|
117 | #region Create operator graph
|
---|
118 | OperatorGraph.InitialOperator = bestQualityMemorizer1;
|
---|
119 | bestQualityMemorizer1.Successor = bestQualityMemorizer2;
|
---|
120 | bestQualityMemorizer2.Successor = dataTableValuesCollector;
|
---|
121 | dataTableValuesCollector.Successor = qualityDifferenceCalculator;
|
---|
122 | qualityDifferenceCalculator.Successor = resultsCollector;
|
---|
123 | resultsCollector.Successor = null;
|
---|
124 | #endregion
|
---|
125 | }
|
---|
126 | }
|
---|
127 | }
|
---|