[6615] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15584] | 3 | * Copyright (C) 2002-2018 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 |
|
---|
[12764] | 22 | using System;
|
---|
[12774] | 23 | using System.Linq;
|
---|
[6615] | 24 | using HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Data;
|
---|
| 27 | using HeuristicLab.Operators;
|
---|
| 28 | using HeuristicLab.Optimization;
|
---|
| 29 | using HeuristicLab.Parameters;
|
---|
| 30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 31 |
|
---|
[12764] | 32 | namespace HeuristicLab.Analysis {
|
---|
[12771] | 33 | [Item("QualityPerEvaluationsAnalyzer", @"Creates a plot of the solution quality with respect to the number of evaluated solutions.")]
|
---|
[6615] | 34 | [StorableClass]
|
---|
[12771] | 35 | public class QualityPerEvaluationsAnalyzer : SingleSuccessorOperator, IAnalyzer, ISingleObjectiveOperator {
|
---|
[7172] | 36 | public virtual bool EnabledByDefault {
|
---|
[12764] | 37 | get { return false; }
|
---|
[7172] | 38 | }
|
---|
| 39 |
|
---|
[12764] | 40 | public ILookupParameter<DoubleValue> BestQualityParameter {
|
---|
| 41 | get { return (ILookupParameter<DoubleValue>)Parameters["BestQuality"]; }
|
---|
[6615] | 42 | }
|
---|
[12764] | 43 | public ILookupParameter<IntValue> EvaluatedSolutionsParameter {
|
---|
| 44 | get { return (ILookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
|
---|
[6615] | 45 | }
|
---|
[12804] | 46 | public ILookupParameter<IntValue> EvaluatedMovesParameter {
|
---|
| 47 | get { return (ILookupParameter<IntValue>)Parameters["EvaluatedMoves"]; }
|
---|
| 48 | }
|
---|
| 49 | public IValueLookupParameter<DoubleValue> MoveCostPerSolutionParameter {
|
---|
| 50 | get { return (IValueLookupParameter<DoubleValue>)Parameters["MoveCostPerSolution"]; }
|
---|
| 51 | }
|
---|
[12771] | 52 | public IResultParameter<IndexedDataTable<double>> QualityPerEvaluationsParameter {
|
---|
| 53 | get { return (IResultParameter<IndexedDataTable<double>>)Parameters["QualityPerEvaluations"]; }
|
---|
[6615] | 54 | }
|
---|
| 55 |
|
---|
| 56 | [StorableConstructor]
|
---|
[12771] | 57 | protected QualityPerEvaluationsAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
| 58 | protected QualityPerEvaluationsAnalyzer(QualityPerEvaluationsAnalyzer original, Cloner cloner) : base(original, cloner) { }
|
---|
| 59 | public QualityPerEvaluationsAnalyzer()
|
---|
[6615] | 60 | : base() {
|
---|
[12764] | 61 | Parameters.Add(new LookupParameter<DoubleValue>("BestQuality", "The quality value that should be compared."));
|
---|
[12804] | 62 | Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of evaluated solutions."));
|
---|
| 63 | Parameters.Add(new LookupParameter<IntValue>("EvaluatedMoves", "The number of evaluated moves."));
|
---|
| 64 | Parameters.Add(new ValueLookupParameter<DoubleValue>("MoveCostPerSolution", "The cost to evaluate a move as a ratio to the cost of evaluating a solution.", new DoubleValue(1)));
|
---|
[12771] | 65 | Parameters.Add(new ResultParameter<IndexedDataTable<double>>("QualityPerEvaluations", "Data table containing the first hitting graph with evaluations as the x-axis."));
|
---|
| 66 | QualityPerEvaluationsParameter.DefaultValue = new IndexedDataTable<double>("Quality per Evaluations") {
|
---|
| 67 | VisualProperties = {
|
---|
| 68 | XAxisTitle = "Evaluations",
|
---|
| 69 | YAxisTitle = "Quality"
|
---|
| 70 | },
|
---|
| 71 | Rows = { new IndexedDataRow<double>("First-hit Graph") { VisualProperties = {
|
---|
| 72 | ChartType = DataRowVisualProperties.DataRowChartType.StepLine,
|
---|
[12808] | 73 | LineWidth = 2
|
---|
[12771] | 74 | } } }
|
---|
[12764] | 75 | };
|
---|
[6615] | 76 | }
|
---|
| 77 |
|
---|
| 78 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[12771] | 79 | return new QualityPerEvaluationsAnalyzer(this, cloner);
|
---|
[6615] | 80 | }
|
---|
| 81 |
|
---|
| 82 | public override IOperation Apply() {
|
---|
[12764] | 83 | var bestQuality = BestQualityParameter.ActualValue.Value;
|
---|
[12804] | 84 | var evalSols = EvaluatedSolutionsParameter.ActualValue;
|
---|
| 85 | var evalMoves = EvaluatedMovesParameter.ActualValue;
|
---|
| 86 | var evaluations = 0.0;
|
---|
| 87 | if (evalSols != null) evaluations += evalSols.Value;
|
---|
| 88 | if (evalMoves != null) evaluations += evalMoves.Value * MoveCostPerSolutionParameter.ActualValue.Value;
|
---|
[6615] | 89 |
|
---|
[15220] | 90 | if (evaluations > 0) {
|
---|
| 91 | var dataTable = QualityPerEvaluationsParameter.ActualValue;
|
---|
| 92 | var values = dataTable.Rows["First-hit Graph"].Values;
|
---|
[6615] | 93 |
|
---|
[15220] | 94 | var newEntry = Tuple.Create(evaluations, bestQuality);
|
---|
[12834] | 95 |
|
---|
[15220] | 96 | if (values.Count == 0) {
|
---|
| 97 | values.Add(newEntry); // record the first data
|
---|
| 98 | values.Add(Tuple.Create(evaluations, bestQuality)); // last entry records max number of evaluations
|
---|
| 99 | return base.Apply();
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | var improvement = values.Last().Item2 != bestQuality;
|
---|
| 103 | if (improvement) {
|
---|
| 104 | values[values.Count - 1] = newEntry; // record the improvement
|
---|
| 105 | values.Add(Tuple.Create(evaluations, bestQuality)); // last entry records max number of evaluations
|
---|
| 106 | } else {
|
---|
| 107 | values[values.Count - 1] = Tuple.Create(evaluations, bestQuality); // the last entry is updated
|
---|
| 108 | }
|
---|
[12834] | 109 | }
|
---|
[6615] | 110 | return base.Apply();
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 | }
|
---|