[6615] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[14058] | 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 |
|
---|
[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;
|
---|
[14927] | 30 | using HeuristicLab.Persistence;
|
---|
[6615] | 31 |
|
---|
[12764] | 32 | namespace HeuristicLab.Analysis {
|
---|
[12771] | 33 | [Item("QualityPerClockAnalyzer", @"Creates a plot of the solution quality with respect to the elapsed wall-clock time.")]
|
---|
[14927] | 34 | [StorableType("b6f186b2-ca40-431a-985b-55f1773737f7")]
|
---|
[12771] | 35 | public class QualityPerClockAnalyzer : 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 | }
|
---|
[12771] | 43 |
|
---|
[12803] | 44 | public ILookupParameter<DateTimeValue> LastUpdateTimeParameter {
|
---|
| 45 | get { return (ILookupParameter<DateTimeValue>)Parameters["LastUpdateTime"]; }
|
---|
[6615] | 46 | }
|
---|
[12771] | 47 |
|
---|
| 48 | public IResultParameter<IndexedDataTable<double>> QualityPerClockParameter {
|
---|
| 49 | get { return (IResultParameter<IndexedDataTable<double>>)Parameters["QualityPerClock"]; }
|
---|
[6615] | 50 | }
|
---|
| 51 |
|
---|
| 52 | [StorableConstructor]
|
---|
[15018] | 53 | protected QualityPerClockAnalyzer(StorableConstructorFlag deserializing) : base(deserializing) { }
|
---|
[12771] | 54 | protected QualityPerClockAnalyzer(QualityPerClockAnalyzer original, Cloner cloner) : base(original, cloner) { }
|
---|
| 55 | public QualityPerClockAnalyzer()
|
---|
[6615] | 56 | : base() {
|
---|
[12764] | 57 | Parameters.Add(new LookupParameter<DoubleValue>("BestQuality", "The quality value that should be compared."));
|
---|
[12803] | 58 | Parameters.Add(new LookupParameter<DateTimeValue>("LastUpdateTime", "The time the analyzer was last run."));
|
---|
[12771] | 59 | Parameters.Add(new ResultParameter<IndexedDataTable<double>>("QualityPerClock", "Data table containing the first hitting graph with elapsed wall clock time (in seconds) as the x-axis."));
|
---|
| 60 | QualityPerClockParameter.DefaultValue = new IndexedDataTable<double>("Quality per Clock") {
|
---|
| 61 | VisualProperties = {
|
---|
| 62 | XAxisTitle = "Elapsed time [s]",
|
---|
| 63 | YAxisTitle = "Quality"
|
---|
| 64 | },
|
---|
| 65 | Rows = { new IndexedDataRow<double>("First-hit Graph") { VisualProperties = {
|
---|
| 66 | ChartType = DataRowVisualProperties.DataRowChartType.StepLine,
|
---|
[12808] | 67 | LineWidth = 2
|
---|
[12771] | 68 | } } }
|
---|
[12764] | 69 | };
|
---|
[6615] | 70 | }
|
---|
| 71 |
|
---|
| 72 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[12771] | 73 | return new QualityPerClockAnalyzer(this, cloner);
|
---|
[6615] | 74 | }
|
---|
| 75 |
|
---|
| 76 | public override IOperation Apply() {
|
---|
[12764] | 77 | var bestQuality = BestQualityParameter.ActualValue.Value;
|
---|
[14058] | 78 | var dataTable = QualityPerClockParameter.ActualValue;
|
---|
[12774] | 79 | var values = dataTable.Rows["First-hit Graph"].Values;
|
---|
[6615] | 80 |
|
---|
[12834] | 81 | var lastUpdateTime = LastUpdateTimeParameter.ActualValue;
|
---|
| 82 | if (lastUpdateTime == null) {
|
---|
| 83 | lastUpdateTime = new DateTimeValue(DateTime.UtcNow.AddMilliseconds(-1));
|
---|
| 84 | LastUpdateTimeParameter.ActualValue = lastUpdateTime;
|
---|
| 85 | }
|
---|
[12804] | 86 |
|
---|
[12834] | 87 | var now = DateTime.UtcNow;
|
---|
| 88 | var runtimeSoFar = (now - lastUpdateTime.Value).TotalSeconds + (values.Count > 0 ? values.Last().Item1 : 0);
|
---|
| 89 | lastUpdateTime.Value = now;
|
---|
| 90 | var newEntry = Tuple.Create(runtimeSoFar, bestQuality);
|
---|
| 91 |
|
---|
| 92 | if (values.Count == 0) {
|
---|
| 93 | values.Add(newEntry);
|
---|
| 94 | values.Add(Tuple.Create(runtimeSoFar, bestQuality)); // duplicate entry that will be replaced
|
---|
| 95 | return base.Apply();
|
---|
[12804] | 96 | }
|
---|
[12834] | 97 |
|
---|
| 98 | var improvement = values.Last().Item2 != bestQuality;
|
---|
| 99 | if (improvement) {
|
---|
| 100 | values[values.Count - 1] = newEntry;
|
---|
| 101 | values.Add(Tuple.Create(runtimeSoFar, bestQuality)); // duplicate entry that will be replaced
|
---|
| 102 | } else {
|
---|
| 103 | values[values.Count - 1] = Tuple.Create(runtimeSoFar, bestQuality);
|
---|
| 104 | }
|
---|
[6615] | 105 | return base.Apply();
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 | }
|
---|