#region License Information /* HeuristicLab * Copyright (C) 2002-2011 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.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.QualityAnalysis { [Item("Quality Distribution Analyzer", "Analyzes the distribution of the quality values in that it adds a Histogram of them into the result collection.")] [StorableClass] public class QualityDistributionAnalyzer : SingleSuccessorOperator, IAnalyzer { #region Parameter properties public IScopeTreeLookupParameter QualityParameter { get { return (IScopeTreeLookupParameter)Parameters["Quality"]; } } public IValueLookupParameter ResultsParameter { get { return (IValueLookupParameter)Parameters["Results"]; } } public IValueParameter HistogramNameParameter { get { return (IValueParameter)Parameters["HistogramName"]; } } #endregion [StorableConstructor] protected QualityDistributionAnalyzer(bool deserializing) : base(deserializing) { } protected QualityDistributionAnalyzer(QualityDistributionAnalyzer original, Cloner cloner) : base(original, cloner) { } public QualityDistributionAnalyzer() : base() { Parameters.Add(new ScopeTreeLookupParameter("Quality", "The value which represents the quality of a solution.")); Parameters.Add(new ValueLookupParameter("Results", "The results collection where the analysis values should be stored.")); Parameters.Add(new ValueParameter("HistogramName", "The name of the histogram that gets injected in to the results collection.", new StringValue("QualityDistribution"))); } public override IDeepCloneable Clone(Cloner cloner) { return new QualityDistributionAnalyzer(this, cloner); } public override IOperation Apply() { HistogramHistory qualityDistribution = null; ResultCollection results = ResultsParameter.ActualValue; string description = "Shows the quality distributions in the current population."; string resultName = HistogramNameParameter.Value.Value; if (results.ContainsKey(resultName)) { qualityDistribution = results[resultName].Value as HistogramHistory; } else { qualityDistribution = new HistogramHistory(); results.Add(new Result(resultName, description, qualityDistribution)); } Histogram histogram = new Histogram("History " + qualityDistribution.Count, description); var qualities = QualityParameter.ActualValue; histogram.Values.Clear(); histogram.Values.AddRange(qualities.Select(x => x.Value)); qualityDistribution.Add(histogram); return base.Apply(); } } }