[5994] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 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 |
|
---|
| 22 | using System.Linq;
|
---|
| 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Data;
|
---|
| 26 | using HeuristicLab.Operators;
|
---|
| 27 | using HeuristicLab.Optimization;
|
---|
| 28 | using HeuristicLab.Parameters;
|
---|
| 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 30 |
|
---|
| 31 | namespace HeuristicLab.Analysis.QualityAnalysis {
|
---|
| 32 | [Item("Quality Distribution Analyzer", "Analyzes the distribution of the quality values in that it adds a Histogram of them into the result collection.")]
|
---|
| 33 | [StorableClass]
|
---|
| 34 | public class QualityDistributionAnalyzer : SingleSuccessorOperator, IAnalyzer {
|
---|
| 35 |
|
---|
| 36 | #region Parameter properties
|
---|
| 37 | public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
|
---|
| 38 | get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
|
---|
| 39 | }
|
---|
| 40 | public IValueLookupParameter<ResultCollection> ResultsParameter {
|
---|
| 41 | get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; }
|
---|
| 42 | }
|
---|
| 43 | public IValueParameter<StringValue> HistogramNameParameter {
|
---|
| 44 | get { return (IValueParameter<StringValue>)Parameters["HistogramName"]; }
|
---|
| 45 | }
|
---|
| 46 | #endregion
|
---|
| 47 |
|
---|
| 48 | [StorableConstructor]
|
---|
| 49 | protected QualityDistributionAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
| 50 | protected QualityDistributionAnalyzer(QualityDistributionAnalyzer original, Cloner cloner)
|
---|
| 51 | : base(original, cloner) {
|
---|
| 52 | }
|
---|
| 53 | public QualityDistributionAnalyzer()
|
---|
| 54 | : base() {
|
---|
| 55 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
|
---|
| 56 | Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The results collection where the analysis values should be stored."));
|
---|
| 57 | Parameters.Add(new ValueParameter<StringValue>("HistogramName", "The name of the histogram that gets injected in to the results collection.", new StringValue("QualityDistribution")));
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 61 | return new QualityDistributionAnalyzer(this, cloner);
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | public override IOperation Apply() {
|
---|
| 65 | HistogramHistory qualityDistribution = null;
|
---|
| 66 | ResultCollection results = ResultsParameter.ActualValue;
|
---|
| 67 | string description = "Shows the quality distributions in the current population.";
|
---|
| 68 | string resultName = HistogramNameParameter.Value.Value;
|
---|
| 69 | if (results.ContainsKey(resultName)) {
|
---|
| 70 | qualityDistribution = results[resultName].Value as HistogramHistory;
|
---|
| 71 | } else {
|
---|
| 72 | qualityDistribution = new HistogramHistory();
|
---|
| 73 | results.Add(new Result(resultName, description, qualityDistribution));
|
---|
| 74 | }
|
---|
| 75 | Histogram histogram = new Histogram("History " + qualityDistribution.Count, description);
|
---|
| 76 | var qualities = QualityParameter.ActualValue;
|
---|
| 77 | histogram.Values.Clear();
|
---|
| 78 | histogram.Values.AddRange(qualities.Select(x => x.Value));
|
---|
| 79 | qualityDistribution.Add(histogram);
|
---|
| 80 |
|
---|
| 81 | return base.Apply();
|
---|
| 82 | }
|
---|
| 83 | }
|
---|
| 84 | }
|
---|