[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 {
|
---|
[6013] | 32 | [Item("QualityDistributionAnalyzer", "Analyzes the distribution of the quality values in that it adds a Histogram of them into the result collection.")]
|
---|
[5994] | 33 | [StorableClass]
|
---|
[6013] | 34 | public class QualityDistributionAnalyzer : SingleSuccessorOperator, IAnalyzer, IIterationBasedOperator {
|
---|
[5994] | 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 | }
|
---|
[6013] | 43 | private ValueParameter<StringValue> HistogramNameParameter {
|
---|
| 44 | get { return (ValueParameter<StringValue>)Parameters["HistogramName"]; }
|
---|
[5994] | 45 | }
|
---|
[6013] | 46 | private ValueParameter<BoolValue> StoreHistoryParameter {
|
---|
| 47 | get { return (ValueParameter<BoolValue>)Parameters["StoreHistory"]; }
|
---|
| 48 | }
|
---|
| 49 | public ILookupParameter<IntValue> IterationsParameter {
|
---|
| 50 | get { return (ILookupParameter<IntValue>)Parameters["Iterations"]; }
|
---|
| 51 | }
|
---|
| 52 | public IValueLookupParameter<IntValue> MaximumIterationsParameter {
|
---|
| 53 | get { return (IValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; }
|
---|
| 54 | }
|
---|
[5994] | 55 | #endregion
|
---|
| 56 |
|
---|
[6013] | 57 | public string HistogramName {
|
---|
| 58 | get { return HistogramNameParameter.Value.Value; }
|
---|
| 59 | set { HistogramNameParameter.Value.Value = value; }
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | public bool StoreHistory {
|
---|
| 63 | get { return StoreHistoryParameter.Value.Value; }
|
---|
| 64 | set { StoreHistoryParameter.Value.Value = value; }
|
---|
| 65 | }
|
---|
| 66 |
|
---|
[5994] | 67 | [StorableConstructor]
|
---|
| 68 | protected QualityDistributionAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
| 69 | protected QualityDistributionAnalyzer(QualityDistributionAnalyzer original, Cloner cloner)
|
---|
| 70 | : base(original, cloner) {
|
---|
| 71 | }
|
---|
| 72 | public QualityDistributionAnalyzer()
|
---|
| 73 | : base() {
|
---|
| 74 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
|
---|
| 75 | Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The results collection where the analysis values should be stored."));
|
---|
[6013] | 76 | Parameters.Add(new FixedValueParameter<StringValue>("HistogramName", "The name of the histogram that gets injected in to the results collection.", new StringValue("Quality Distribution")));
|
---|
| 77 | Parameters.Add(new FixedValueParameter<BoolValue>("StoreHistory", "True if the history should be stored in addition to the current distribution", new BoolValue(false)));
|
---|
| 78 | Parameters.Add(new LookupParameter<IntValue>("Iterations", "Optional: A value indicating the current iteration."));
|
---|
| 79 | Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "Unused", new IntValue(-1)));
|
---|
| 80 |
|
---|
| 81 | QualityParameter.Hidden = true;
|
---|
| 82 | ResultsParameter.Hidden = true;
|
---|
| 83 | IterationsParameter.Hidden = true;
|
---|
| 84 | MaximumIterationsParameter.Hidden = true;
|
---|
[5994] | 85 | }
|
---|
| 86 |
|
---|
| 87 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 88 | return new QualityDistributionAnalyzer(this, cloner);
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | public override IOperation Apply() {
|
---|
[6013] | 92 | DataTable qualityDistribution = null;
|
---|
[5994] | 93 | ResultCollection results = ResultsParameter.ActualValue;
|
---|
| 94 | string description = "Shows the quality distributions in the current population.";
|
---|
[6013] | 95 | if (results.ContainsKey(HistogramName)) {
|
---|
| 96 | qualityDistribution = results[HistogramName].Value as DataTable;
|
---|
[5994] | 97 | } else {
|
---|
[6013] | 98 | qualityDistribution = new DataTable("Population Quality Distribution", description);
|
---|
[6115] | 99 | qualityDistribution.VisualProperties.XAxisTitle = QualityParameter.ActualName;
|
---|
| 100 | qualityDistribution.VisualProperties.YAxisTitle = "Frequency";
|
---|
[6013] | 101 | results.Add(new Result(HistogramName, description, qualityDistribution));
|
---|
[5994] | 102 | }
|
---|
[6013] | 103 | DataRow row;
|
---|
| 104 | if (!qualityDistribution.Rows.TryGetValue("QualityDistribution", out row)) {
|
---|
| 105 | row = new DataRow("QualityDistribution");
|
---|
| 106 | row.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram;
|
---|
| 107 | qualityDistribution.Rows.Add(row);
|
---|
| 108 | }
|
---|
[5994] | 109 | var qualities = QualityParameter.ActualValue;
|
---|
[6115] | 110 | row.Values.Replace(qualities.Select(x => x.Value));
|
---|
[5994] | 111 |
|
---|
[6013] | 112 | if (StoreHistory) {
|
---|
| 113 | string historyResultName = HistogramName + " History";
|
---|
| 114 | DataTableHistory qdHistory = null;
|
---|
| 115 | if (results.ContainsKey(historyResultName)) {
|
---|
| 116 | qdHistory = results[historyResultName].Value as DataTableHistory;
|
---|
| 117 | } else {
|
---|
| 118 | qdHistory = new DataTableHistory();
|
---|
| 119 | results.Add(new Result(historyResultName, qdHistory));
|
---|
| 120 | }
|
---|
| 121 | DataTable table = (DataTable)qualityDistribution.Clone();
|
---|
| 122 | IntValue iteration = IterationsParameter.ActualValue;
|
---|
| 123 | if (iteration != null) {
|
---|
| 124 | string iterationName = IterationsParameter.ActualName;
|
---|
| 125 | if (iterationName.EndsWith("s")) iterationName = iterationName.Remove(iterationName.Length - 1);
|
---|
| 126 | string appendix = " at " + iterationName + " " + iteration.Value.ToString();
|
---|
| 127 | table.Name += appendix;
|
---|
| 128 | table.Rows["QualityDistribution"].Name += appendix;
|
---|
| 129 | }
|
---|
| 130 | qdHistory.Add(table);
|
---|
| 131 | }
|
---|
[5994] | 132 | return base.Apply();
|
---|
| 133 | }
|
---|
| 134 | }
|
---|
| 135 | }
|
---|