source: branches/PerformanceComparison/HeuristicLab.Analysis/3.3/QualityAnalysis/QualityPerEvaluationsAnalyzer.cs @ 12774

Last change on this file since 12774 was 12774, checked in by abeham, 6 years ago

#2431: minor improvements

File size: 3.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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 System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Operators;
28using HeuristicLab.Optimization;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31
32namespace HeuristicLab.Analysis {
33  [Item("QualityPerEvaluationsAnalyzer", @"Creates a plot of the solution quality with respect to the number of evaluated solutions.")]
34  [StorableClass]
35  public class QualityPerEvaluationsAnalyzer : SingleSuccessorOperator, IAnalyzer, ISingleObjectiveOperator {
36    public virtual bool EnabledByDefault {
37      get { return false; }
38    }
39
40    public ILookupParameter<DoubleValue> BestQualityParameter {
41      get { return (ILookupParameter<DoubleValue>)Parameters["BestQuality"]; }
42    }
43    public ILookupParameter<IntValue> EvaluatedSolutionsParameter {
44      get { return (ILookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
45    }
46    public IResultParameter<IndexedDataTable<double>> QualityPerEvaluationsParameter {
47      get { return (IResultParameter<IndexedDataTable<double>>)Parameters["QualityPerEvaluations"]; }
48    }
49
50    [StorableConstructor]
51    protected QualityPerEvaluationsAnalyzer(bool deserializing) : base(deserializing) { }
52    protected QualityPerEvaluationsAnalyzer(QualityPerEvaluationsAnalyzer original, Cloner cloner) : base(original, cloner) { }
53    public QualityPerEvaluationsAnalyzer()
54      : base() {
55      Parameters.Add(new LookupParameter<DoubleValue>("BestQuality", "The quality value that should be compared."));
56      Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The quality value that should be compared."));
57      Parameters.Add(new ResultParameter<IndexedDataTable<double>>("QualityPerEvaluations", "Data table containing the first hitting graph with evaluations as the x-axis."));
58      QualityPerEvaluationsParameter.DefaultValue = new IndexedDataTable<double>("Quality per Evaluations") {
59        VisualProperties = {
60          XAxisTitle = "Evaluations",
61          YAxisTitle = "Quality"
62        },
63        Rows = { new IndexedDataRow<double>("First-hit Graph") { VisualProperties = {
64          ChartType = DataRowVisualProperties.DataRowChartType.StepLine,
65          LineWidth = 3
66        } } }
67      };
68    }
69
70    public override IDeepCloneable Clone(Cloner cloner) {
71      return new QualityPerEvaluationsAnalyzer(this, cloner);
72    }
73
74    public override IOperation Apply() {
75      var bestQuality = BestQualityParameter.ActualValue.Value;
76      var evaluations = Math.Max(EvaluatedSolutionsParameter.ActualValue.Value, 1);
77
78      var dataTable = QualityPerEvaluationsParameter.ResultValue;
79      var values = dataTable.Rows["First-hit Graph"].Values;
80      if (values.Count == 0 || values.Last().Item2 != bestQuality)
81        values.Add(Tuple.Create((double)evaluations, bestQuality));
82
83      return base.Apply();
84    }
85  }
86}
Note: See TracBrowser for help on using the repository browser.