Changeset 10133


Ignore:
Timestamp:
11/13/13 10:56:46 (9 years ago)
Author:
ascheibe
Message:

#1886 updated the PermutationConvexHullModifier to collect the same results as the RealVectorConvexHullModifier

Location:
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/RunCollectionModifiers
Files:
2 edited

Legend:

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

    r10116 r10133  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using System.Linq;
    25 using System.Text;
    2624using HeuristicLab.Analysis.SolutionCaching.PermutationEncoding;
    27 using HeuristicLab.Analysis.SolutionCaching.RealVectorEncoding;
    2825using HeuristicLab.Common;
    2926using HeuristicLab.Core;
    30 using HeuristicLab.Encodings.RealVectorEncoding;
     27using HeuristicLab.Data;
     28using HeuristicLab.Encodings.PermutationEncoding;
    3129using HeuristicLab.Optimization;
    3230using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    5452        if (solutionCache == null) continue;
    5553
    56         DataTable dt = new DataTable("Convex Hull Volume over Generations");
     54        DataTable volDataTable = new DataTable("Convex hull volume over generations");
     55        DataTable nrOfPointsTable = new DataTable("Nr. of points of convex hull");
     56        DoubleValue overallVolumn = new DoubleValue();
     57
    5758        DataRow dtVolumeRow = new DataRow("Volume");
    58         DataRow dtNrPointsRow = new DataRow("Nr. of Points");
    59         dt.Rows.Add(dtVolumeRow);
    60         dt.Rows.Add(dtNrPointsRow);
     59        DataRow dtNrPointsRow = new DataRow("Nr. of points");
     60        volDataTable.Rows.Add(dtVolumeRow);
     61        nrOfPointsTable.Rows.Add(dtNrPointsRow);
    6162
     63        List<double[]> curHull = null;
    6264        var sols = solutionCache.GetSolutionsFromGeneration(i);
    6365        int dim = sols.First().Length;
    6466        while (sols.Count != 0) {
    65           double[][] dm = new double[sols.Count][];
    66           for (int j = 0; j < sols.Count; j++) {
    67             dm[j] = new double[sols.Count];
    68           }
    69 
    70           for (int j = 0; j < sols.Count; j++) {
    71             for (int k = 0; k < sols.Count; k++) {
    72               dm[j][k] = TSPSimilarityCalculator.CalculateSimilarity(sols[j], sols[k]);
    73             }
    74           }
    75           double[][] popPoints = DistanceMatrixToPoints.ConvertDistanceMatrixToPoints(DistanceMatrixToPoints.MetricMDS(dm, dim, true));
     67          double[][] dm = CalculateDistanceMatrixFromPermutations(sols);
     68          double[][] popPoints = DistanceMatrixToPoints.MetricMDS(dm, dim);
    7669
    7770          var convexHull = LPHull.Calculate(popPoints);
     
    8073          dtNrPointsRow.Values.Add(convexHull.Count);
    8174
     75          if (curHull == null) {
     76            curHull = convexHull;
     77          } else {
     78            var newPHull = curHull.Union(convexHull).ToArray();
     79            curHull = LPHull.Calculate(newPHull);
     80          }
     81
    8282          sols = solutionCache.GetSolutionsFromGeneration(++i);
    8383        }
     84        overallVolumn.Value = ConvexHullMeasures.CalculateVolume(curHull);
    8485
    85         run.Results.Add("Convex Hull Measures", dt);
     86        run.Results.Add("Overall volumn: ", overallVolumn);
     87        run.Results.Add("Convex hull volumn", volDataTable);
     88        run.Results.Add("Convex nr. of points", nrOfPointsTable);
     89      }
     90    }
     91
     92    private double[][] CalculateDistanceMatrixFromPermutations(List<Permutation> points) {
     93      double[][] tmpDm = new double[points.Count][];
     94      AllocArray(tmpDm, points.Count);
     95
     96      for (int i = 0; i < points.Count; i++) {
     97        for (int j = 0; j < points.Count; j++) {
     98          double diversity = TSPSimilarityCalculator.CalculateSimilarity(points[i], points[j]);
     99          tmpDm[i][j] = diversity;
     100        }
     101      }
     102
     103      return DistanceMatrixToPoints.TransformToDistances(tmpDm);
     104    }
     105
     106    private void AllocArray(double[][] arr, int size) {
     107      for (int i = 0; i < arr.Length; i++) {
     108        arr[i] = new double[size];
    86109      }
    87110    }
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/RunCollectionModifiers/RealVectorConvexHullModifier.cs

    r10119 r10133  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using System.Linq;
    25 using System.Text;
    2624using HeuristicLab.Analysis.SolutionCaching.RealVectorEncoding;
    2725using HeuristicLab.Common;
     
    5351        if (solutionCache == null) continue;
    5452
    55         var sols = solutionCache.GetSolutionsFromGeneration(i);
    5653        DataTable volDataTable = new DataTable("Convex hull volume over generations");
    5754        DataTable nrOfPointsTable = new DataTable("Nr. of points of convex hull");
     
    6461
    6562        List<double[]> curHull = null;
    66 
     63        var sols = solutionCache.GetSolutionsFromGeneration(i);
    6764        while (sols.Count != 0) {
    6865          var input = sols.Select(x => ConvertRealVectorToVertexArray(x)).ToArray();
Note: See TracChangeset for help on using the changeset viewer.