[6615] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[14185] | 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6615] | 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.Common;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
| 25 | using HeuristicLab.Operators;
|
---|
| 26 | using HeuristicLab.Optimization;
|
---|
| 27 | using HeuristicLab.Parameters;
|
---|
| 28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Analysis.QualityAnalysis {
|
---|
| 31 | [Item("ScaledQualityDifferenceAnalyzer", @"Calculates the quality value relative to a certain range given with a minimum and a maximum value.
|
---|
| 32 | The 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.
|
---|
| 33 | A 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 | [StorableClass]
|
---|
[11970] | 35 | public class ScaledQualityDifferenceAnalyzer : SingleSuccessorOperator, IAnalyzer, ISingleObjectiveOperator {
|
---|
[7172] | 36 | public virtual bool EnabledByDefault {
|
---|
| 37 | get { return true; }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
[6615] | 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(bool deserializing) : base(deserializing) { }
|
---|
| 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;
|
---|
[6616] | 85 | if (differenceValue == null) {
|
---|
| 86 | differenceValue = new DoubleValue(difference);
|
---|
| 87 | ScaledDifferenceParameter.ActualValue = differenceValue;
|
---|
| 88 | } else differenceValue.Value = difference;
|
---|
[6615] | 89 |
|
---|
| 90 | ResultCollection results = ResultsParameter.ActualValue;
|
---|
| 91 | if (results != null) {
|
---|
| 92 | IResult r;
|
---|
[7245] | 93 | if (!results.TryGetValue(ScaledDifferenceParameter.TranslatedName, out r)) {
|
---|
| 94 | r = new Result(ScaledDifferenceParameter.TranslatedName, differenceValue);
|
---|
[6615] | 95 | results.Add(r);
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | return base.Apply();
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 | }
|
---|