#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("QualityPerEvaluationsAnalyzer", @"Creates a plot of the solution quality with respect to the number of evaluated solutions.")] [StorableClass] public class QualityPerEvaluationsAnalyzer : SingleSuccessorOperator, IAnalyzer, ISingleObjectiveOperator { public virtual bool EnabledByDefault { get { return false; } } public ILookupParameter BestQualityParameter { get { return (ILookupParameter)Parameters["BestQuality"]; } } public ILookupParameter EvaluatedSolutionsParameter { get { return (ILookupParameter)Parameters["EvaluatedSolutions"]; } } public IResultParameter> QualityPerEvaluationsParameter { get { return (IResultParameter>)Parameters["QualityPerEvaluations"]; } } [StorableConstructor] protected QualityPerEvaluationsAnalyzer(bool deserializing) : base(deserializing) { } protected QualityPerEvaluationsAnalyzer(QualityPerEvaluationsAnalyzer original, Cloner cloner) : base(original, cloner) { } public QualityPerEvaluationsAnalyzer() : base() { Parameters.Add(new LookupParameter("BestQuality", "The quality value that should be compared.")); Parameters.Add(new LookupParameter("EvaluatedSolutions", "The quality value that should be compared.")); Parameters.Add(new ResultParameter>("QualityPerEvaluations", "Data table containing the first hitting graph with evaluations as the x-axis.")); QualityPerEvaluationsParameter.DefaultValue = new IndexedDataTable("Quality per Evaluations") { VisualProperties = { XAxisTitle = "Evaluations", YAxisTitle = "Quality" }, Rows = { new IndexedDataRow("First-hit Graph") { VisualProperties = { ChartType = DataRowVisualProperties.DataRowChartType.StepLine, LineWidth = 3 } } } }; } public override IDeepCloneable Clone(Cloner cloner) { return new QualityPerEvaluationsAnalyzer(this, cloner); } public override IOperation Apply() { var bestQuality = BestQualityParameter.ActualValue.Value; var evaluations = Math.Max(EvaluatedSolutionsParameter.ActualValue.Value, 1); var dataTable = QualityPerEvaluationsParameter.ResultValue; var values = dataTable.Rows["First-hit Graph"].Values; if (values.Count == 0 || values.Last().Item2 != bestQuality) values.Add(Tuple.Create((double)evaluations, bestQuality)); return base.Apply(); } } }