Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Analysis/3.3/QualityAnalysis/ScaledQualityDifferenceAnalyzer.cs @ 18199

Last change on this file since 18199 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 5.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Operators;
26using HeuristicLab.Optimization;
27using HeuristicLab.Parameters;
28using HEAL.Attic;
29
30namespace HeuristicLab.Analysis.QualityAnalysis {
31  [Item("ScaledQualityDifferenceAnalyzer", @"Calculates the quality value relative to a certain range given with a minimum and a maximum value.
32The difference lies in the interval [0;1] if the range [min;max] is as large as the observed quality values, otherwise the difference will become < 0 or > 1.
33A value towards 0 always means that it's closer to the better fitness value, while a value towards 1 means that it's closer to the worse fitness value.")]
34  [StorableType("C0E9AE9C-06F8-4A5F-A726-6532F0E038CF")]
35  public class ScaledQualityDifferenceAnalyzer : SingleSuccessorOperator, IAnalyzer, ISingleObjectiveOperator {
36    public virtual bool EnabledByDefault {
37      get { return true; }
38    }
39
40    public ILookupParameter<DoubleValue> QualityParameter {
41      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
42    }
43    public ILookupParameter<BoolValue> MaximizationParameter {
44      get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }
45    }
46    public ILookupParameter<DoubleValue> ScaledDifferenceParameter {
47      get { return (ILookupParameter<DoubleValue>)Parameters["ScaledDifference"]; }
48    }
49    public ILookupParameter<ResultCollection> ResultsParameter {
50      get { return (ILookupParameter<ResultCollection>)Parameters["Results"]; }
51    }
52    public IValueLookupParameter<DoubleValue> MinimumQualityParameter {
53      get { return (IValueLookupParameter<DoubleValue>)Parameters["MinimumQuality"]; }
54    }
55    public IValueLookupParameter<DoubleValue> MaximumQualityParameter {
56      get { return (IValueLookupParameter<DoubleValue>)Parameters["MaximumQuality"]; }
57    }
58
59    [StorableConstructor]
60    protected ScaledQualityDifferenceAnalyzer(StorableConstructorFlag _) : base(_) { }
61    protected ScaledQualityDifferenceAnalyzer(ScaledQualityDifferenceAnalyzer original, Cloner cloner) : base(original, cloner) { }
62    public ScaledQualityDifferenceAnalyzer()
63      : base() {
64      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality value that should be compared."));
65      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, false otherwise."));
66      Parameters.Add(new LookupParameter<DoubleValue>("ScaledDifference", "The value that describes whether the quality value lies towards the better quality in the range (<=0.5) or more towards the worse quality (> 0.5)."));
67      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The result collection where the difference will be stored (in addition to the scope)."));
68      Parameters.Add(new ValueLookupParameter<DoubleValue>("MinimumQuality", "The lower bound of the quality range to which the quality is compared."));
69      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumQuality", "The upper bound of the quality range to which the quality is compared."));
70    }
71
72    public override IDeepCloneable Clone(Cloner cloner) {
73      return new ScaledQualityDifferenceAnalyzer(this, cloner);
74    }
75
76    public override IOperation Apply() {
77      bool maximization = MaximizationParameter.ActualValue.Value;
78      double quality = QualityParameter.ActualValue.Value, max = MaximumQualityParameter.ActualValue.Value, min = MinimumQualityParameter.ActualValue.Value;
79      double difference;
80
81      difference = ((quality - min) / (max - min));
82      if (maximization) difference = 1.0 - difference;
83
84      DoubleValue differenceValue = ScaledDifferenceParameter.ActualValue;
85      if (differenceValue == null) {
86        differenceValue = new DoubleValue(difference);
87        ScaledDifferenceParameter.ActualValue = differenceValue;
88      } else differenceValue.Value = difference;
89
90      ResultCollection results = ResultsParameter.ActualValue;
91      if (results != null) {
92        IResult r;
93        if (!results.TryGetValue(ScaledDifferenceParameter.TranslatedName, out r)) {
94          r = new Result(ScaledDifferenceParameter.TranslatedName, differenceValue);
95          results.Add(r);
96        }
97      }
98
99      return base.Apply();
100    }
101  }
102}
Note: See TracBrowser for help on using the repository browser.