Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/07/16 21:29:00 (9 years ago)
Author:
abeham
Message:

#2457: worked on expert system

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PerformanceComparison/HeuristicLab.Analysis/3.3/QualityAnalysis/QualityDistributionAnalyzer.cs

    r12012 r13663  
    2020#endregion
    2121
    22 using System.Linq;
    2322using HeuristicLab.Common;
    2423using HeuristicLab.Core;
     
    2827using HeuristicLab.Parameters;
    2928using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using System.Collections.Generic;
     30using System.Linq;
    3031
    3132namespace HeuristicLab.Analysis.QualityAnalysis {
     
    3334  [StorableClass]
    3435  public class QualityDistributionAnalyzer : SingleSuccessorOperator, IAnalyzer, IIterationBasedOperator, ISingleObjectiveOperator {
     36    private const string TableDescription = "Shows the quality distributions in the current population.";
    3537
    3638    #region Parameter properties
     
    9395    }
    9496
     97    public static DataTable PrepareTable(string qualityName = "Quality") {
     98      var result = new DataTable("Population Quality Distribution", TableDescription);
     99      result.VisualProperties.XAxisTitle = qualityName;
     100      result.VisualProperties.YAxisTitle = "Frequency";
     101
     102      var row = new DataRow("QualityDistribution");
     103      row.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram;
     104      result.Rows.Add(row);
     105
     106      return result;
     107    }
     108
     109    public static void UpdateTable(DataTable table, IEnumerable<double> qualities) {
     110      var row = table.Rows["QualityDistribution"];
     111      row.Values.Replace(qualities);
     112    }
     113
    95114    public override IOperation Apply() {
    96115      DataTable qualityDistribution = null;
    97       ResultCollection results = ResultsParameter.ActualValue;
    98       string description = "Shows the quality distributions in the current population.";
     116      var results = ResultsParameter.ActualValue;
    99117      if (results.ContainsKey(HistogramName)) {
    100         qualityDistribution = results[HistogramName].Value as DataTable;
     118        qualityDistribution = (DataTable)results[HistogramName].Value;
    101119      } else {
    102         qualityDistribution = new DataTable("Population Quality Distribution", description);
    103         qualityDistribution.VisualProperties.XAxisTitle = QualityParameter.ActualName;
    104         qualityDistribution.VisualProperties.YAxisTitle = "Frequency";
    105         results.Add(new Result(HistogramName, description, qualityDistribution));
     120        qualityDistribution = PrepareTable(QualityParameter.ActualName);
     121        results.Add(new Result(HistogramName, TableDescription, qualityDistribution));
    106122      }
    107       DataRow row;
    108       if (!qualityDistribution.Rows.TryGetValue("QualityDistribution", out row)) {
    109         row = new DataRow("QualityDistribution");
    110         row.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram;
    111         qualityDistribution.Rows.Add(row);
    112       }
    113       var qualities = QualityParameter.ActualValue;
    114       row.Values.Replace(qualities.Select(x => x.Value));
     123
     124      UpdateTable(qualityDistribution, QualityParameter.ActualValue.Select(x => x.Value));
    115125
    116126      if (StoreHistory) {
    117         string historyResultName = HistogramName + " History";
     127        var historyResultName = HistogramName + " History";
    118128        DataTableHistory qdHistory = null;
    119129        if (results.ContainsKey(historyResultName)) {
    120           qdHistory = results[historyResultName].Value as DataTableHistory;
     130          qdHistory = (DataTableHistory)results[historyResultName].Value;
    121131        } else {
    122132          qdHistory = new DataTableHistory();
    123133          results.Add(new Result(historyResultName, qdHistory));
    124134        }
    125         DataTable table = (DataTable)qualityDistribution.Clone();
    126         IntValue iteration = IterationsParameter.ActualValue;
     135        var table = (DataTable)qualityDistribution.Clone();
     136        var iteration = IterationsParameter.ActualValue;
    127137        if (iteration != null) {
    128           string iterationName = IterationsParameter.ActualName;
     138          var iterationName = IterationsParameter.ActualName;
    129139          if (iterationName.EndsWith("s")) iterationName = iterationName.Remove(iterationName.Length - 1);
    130           string appendix = " at " + iterationName + " " + iteration.Value.ToString();
     140          var appendix = " at " + iterationName + " " + iteration.Value.ToString();
    131141          table.Name += appendix;
    132142          table.Rows["QualityDistribution"].VisualProperties.DisplayName += appendix;
Note: See TracChangeset for help on using the changeset viewer.