#region License Information /* HeuristicLab * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Linq; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Operators; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Analysis { [Item("QualityPerClockAnalyzer", @"Creates a plot of the solution quality with respect to the elapsed wall-clock time.")] [StorableClass] public class QualityPerClockAnalyzer : SingleSuccessorOperator, IAnalyzer, ISingleObjectiveOperator { public virtual bool EnabledByDefault { get { return false; } } public ILookupParameter BestQualityParameter { get { return (ILookupParameter)Parameters["BestQuality"]; } } public IResultParameter ExecutionTimeParameter { get { return (IResultParameter)Parameters["Execution Time"]; } } public IResultParameter> QualityPerClockParameter { get { return (IResultParameter>)Parameters["QualityPerClock"]; } } [StorableConstructor] protected QualityPerClockAnalyzer(bool deserializing) : base(deserializing) { } protected QualityPerClockAnalyzer(QualityPerClockAnalyzer original, Cloner cloner) : base(original, cloner) { } public QualityPerClockAnalyzer() : base() { Parameters.Add(new LookupParameter("BestQuality", "The quality value that should be compared.")); Parameters.Add(new ResultParameter("Execution Time", "The execution time.")); Parameters.Add(new ResultParameter>("QualityPerClock", "Data table containing the first hitting graph with elapsed wall clock time (in seconds) as the x-axis.")); QualityPerClockParameter.DefaultValue = new IndexedDataTable("Quality per Clock") { VisualProperties = { XAxisTitle = "Elapsed time [s]", YAxisTitle = "Quality" }, Rows = { new IndexedDataRow("First-hit Graph") { VisualProperties = { ChartType = DataRowVisualProperties.DataRowChartType.StepLine, LineWidth = 3 } } } }; } public override IDeepCloneable Clone(Cloner cloner) { return new QualityPerClockAnalyzer(this, cloner); } public override IOperation Apply() { var executionTime = Math.Max(ExecutionTimeParameter.ResultValue.Value.TotalSeconds, 0.2); var bestQuality = BestQualityParameter.ActualValue.Value; var dataTable = QualityPerClockParameter.ResultValue; var values = dataTable.Rows["First-hit Graph"].Values; if (values.Count == 0 || values.Last().Item2 != bestQuality) dataTable.Rows["First-hit Graph"].Values.Add(Tuple.Create(executionTime, bestQuality)); return base.Apply(); } } }