Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/18/12 09:45:42 (10 years ago)
Author:
ascheibe
Message:

#1886 improved crossover analyzer and added duplicate parent counting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/CrossoverPerformanceAnalyzer.cs

    r8382 r8499  
    3232using HeuristicLab.Parameters;
    3333using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     34using HeuristicLab.Problems.TravelingSalesman;
    3435
    3536namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers {
     
    7778    #endregion
    7879
    79     ScatterPlot plot, childDiversityPlot, parentDiversityPlot;
    80     DataRow dtRow, dtRowSuccess;
     80    ScatterPlotHelper plotHelper, childDiversityHelper, parentDiversityHelper;
     81    DataTableHelper performanceHelper, successHelper, equalParentsHelper;
    8182    int cnt = 0;
    8283    int success = 0;
     84    int lastGeneration = 0;
     85    int equalParents = 0;
     86    List<double> qualityPoints = new List<double>();
    8387
    8488    [StorableConstructor]
     
    103107
    104108      Parameters.Add(new ValueParameter<SingleObjectiveSolutionSimilarityCalculator>("SimilarityCalculator"));
     109
     110      plotHelper = new ScatterPlotHelper();
     111      childDiversityHelper = new ScatterPlotHelper();
     112      parentDiversityHelper = new ScatterPlotHelper();
     113      performanceHelper = new DataTableHelper();
     114      successHelper = new DataTableHelper();
     115      equalParentsHelper = new DataTableHelper();
    105116    }
    106117
     
    113124      SimilarityCalculatorParameter.Value.SolutionVariableName = "TSPTour";
    114125
     126      plotHelper.InitializePlot(Results, "Crossover Performance", "Solution Index", "Absolut Quality Difference");
     127      childDiversityHelper.InitializePlot(Results, "Child Diversity", "Solution Index", "Diversity");
     128      parentDiversityHelper.InitializePlot(Results, "Parent Diversity", "Solution Index", "Diversity");
     129
     130      performanceHelper.InitializeChart(Results, "Average Crossover Performance", "Average Crossover Performance per Generation");
     131      successHelper.InitializeChart(Results, "Successfull Crossovers", "Successfull Crossovers per Generation");
     132      equalParentsHelper.InitializeChart(Results, "Number of equal parents", "Absolut number of equal parents");
     133
    115134      Point2D<double> qualityPoint, diversityPointChild, diversityPointParent;
    116135      var qualityParent1 = ParentsQualityParameter.ActualValue.First().Value;
     
    120139      var parent2 = ParentsParameter.ActualValue.Last();
    121140      var parentDiversity = SimilarityCalculatorParameter.Value.CalculateSolutionSimilarity(ExecutionContext.Scope.SubScopes.First(), ExecutionContext.Scope.SubScopes.Last());
     141      string curGenStr = GenerationsParameter.ActualValue.Value.ToString();
     142
    122143
    123144      diversityPointParent = new Point2D<double>(cnt, parentDiversity);
     
    133154        success++;
    134155      }
     156      qualityPoints.Add(qualityPoint.Y);
    135157
    136       string curGenStr = GenerationsParameter.ActualValue.Value.ToString();
    137 
    138       if (!Results.ContainsKey("Scatter Plot")) {
    139         InitializePlot();
    140         InitializeChildDiversityPlot();
    141         InitializeParentDiversityPlot();
    142 
    143         Results.Add(new Result("Scatter Plot", plot));
    144         Results.Add(new Result("Scatter Plot History", new ScatterPlotHistory()));
    145 
    146         Results.Add(new Result("Child Diversity Scatter Plot", childDiversityPlot));
    147         Results.Add(new Result("Child Diversity Scatter Plot History", new ScatterPlotHistory()));
    148 
    149         Results.Add(new Result("Parent Diversity Scatter Plot", parentDiversityPlot));
    150         Results.Add(new Result("Parent Diversity Scatter Plot History", new ScatterPlotHistory()));
    151         cnt = 0;
    152 
    153         DataTable dt = new DataTable("Average Crossover Performance");
    154         dtRow = new DataRow("Average Crossover Performance per Generation");
    155         dt.Rows.Add(dtRow);
    156         Results.Add(new Result("Average Crossover Performance", dt));
    157 
    158         DataTable dtSuccess = new DataTable("Successfull Crossovers");
    159         dtRowSuccess = new DataRow("Successfull Crossovers per Generation");
    160         dtSuccess.Rows.Add(dtRowSuccess);
    161         Results.Add(new Result("Successfull Crossovers", dtSuccess));
    162 
    163         success = 0;
     158      if (TSPSimilarityCalculator.CalculateSimilarity(parent1, parent2) == 1.0) {
     159        equalParents++;
    164160      }
    165161
    166       if (!plot.Rows.ContainsKey(curGenStr)) {
    167         if (GenerationsParameter.ActualValue.Value != 0) {
    168           double avg = plot.Rows[(GenerationsParameter.ActualValue.Value - 1).ToString()].Points.Average(x => x.Y);
    169           dtRow.Values.Add(avg);
    170           dtRowSuccess.Values.Add(success);
     162      if (GenerationsParameter.ActualValue.Value != 0) {
     163        if (GenerationsParameter.ActualValue.Value > lastGeneration) {
     164          double avg = qualityPoints.Average();
    171165
    172           ((ScatterPlotHistory)Results["Scatter Plot History"].Value).Add(plot);
    173           ((ScatterPlotHistory)Results["Child Diversity Scatter Plot History"].Value).Add(childDiversityPlot);
    174           ((ScatterPlotHistory)Results["Parent Diversity Scatter Plot History"].Value).Add(parentDiversityPlot);
    175           InitializePlot();
    176           InitializeChildDiversityPlot();
    177           InitializeParentDiversityPlot();
    178           Results["Scatter Plot"].Value = plot;
    179           Results["Child Diversity Scatter Plot"].Value = childDiversityPlot;
    180           Results["Parent Diversity Scatter Plot"].Value = parentDiversityPlot;
    181           cnt = 0;
    182           success = 0;
     166          performanceHelper.AddPoint(avg);
     167          successHelper.AddPoint(success);
     168          equalParentsHelper.AddPoint(equalParents);
     169
     170          Reset();
    183171        }
    184172
    185         var points = new List<Point2D<double>>();
    186         points.Add(qualityPoint);
    187         ScatterPlotDataRow row;
    188         row = new ScatterPlotDataRow(curGenStr, null, points);
    189         row.VisualProperties.PointStyle = ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Circle;
    190         row.VisualProperties.PointSize = 5;
    191         plot.Rows.Add(row);
    192 
    193         points = new List<Point2D<double>>();
    194         points.Add(diversityPointChild);
    195         row = new ScatterPlotDataRow(curGenStr, null, points);
    196         row.VisualProperties.PointStyle = ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Circle;
    197         row.VisualProperties.PointSize = 5;
    198         childDiversityPlot.Rows.Add(row);
    199 
    200         points = new List<Point2D<double>>();
    201         points.Add(diversityPointParent);
    202         row = new ScatterPlotDataRow(curGenStr, null, points);
    203         row.VisualProperties.PointStyle = ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Circle;
    204         row.VisualProperties.PointSize = 5;
    205         parentDiversityPlot.Rows.Add(row);
     173        plotHelper.AddPoint(curGenStr, qualityPoint);
     174        childDiversityHelper.AddPoint(curGenStr, diversityPointChild);
     175        parentDiversityHelper.AddPoint(curGenStr, diversityPointParent);
    206176      } else {
    207         plot.Rows[curGenStr].Points.Add(qualityPoint);
    208         childDiversityPlot.Rows[curGenStr].Points.Add(diversityPointChild);
    209         parentDiversityPlot.Rows[curGenStr].Points.Add(diversityPointParent);
     177        Reset();
    210178      }
    211179
     
    213181    }
    214182
    215     private void InitializePlot() {
    216       plot = new ScatterPlot("Crossover Performance", null);
    217       plot.VisualProperties.XAxisTitle = "Solution Index";
    218       plot.VisualProperties.YAxisTitle = "Absolut Quality Difference";
    219     }
    220     private void InitializeChildDiversityPlot() {
    221       childDiversityPlot = new ScatterPlot("Child Diversity", null);
    222       childDiversityPlot.VisualProperties.XAxisTitle = "Solution Index";
    223       childDiversityPlot.VisualProperties.YAxisTitle = "Diversity";
    224     }
    225     private void InitializeParentDiversityPlot() {
    226       parentDiversityPlot = new ScatterPlot("Parent Diversity", null);
    227       parentDiversityPlot.VisualProperties.XAxisTitle = "Solution Index";
    228       parentDiversityPlot.VisualProperties.YAxisTitle = "Diversity";
     183    private void Reset() {
     184      cnt = 0;
     185      success = 0;
     186      lastGeneration = GenerationsParameter.ActualValue.Value;
     187      qualityPoints.Clear();
     188      equalParents = 0;
    229189    }
    230190  }
Note: See TracChangeset for help on using the changeset viewer.