Changeset 10275
- Timestamp:
- 01/04/14 01:39:50 (11 years ago)
- Location:
- branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/ConvexHullMeasures.cs
r10274 r10275 90 90 } 91 91 92 public static double[] CalculateCentroid (List<double[]> convexHull) {92 public static double[] CalculateCentroids(List<double[]> convexHull) { 93 93 int n = convexHull.Count; 94 94 int dim = convexHull.First().Length; … … 132 132 double ca = c.EuclideanDistance(a); 133 133 134 return Math.Acos((ab * ab + bc * bc - ca * ca) / (2 * ab * bc)); 134 //return degrees 135 return Math.Acos((ab * ab + bc * bc - ca * ca) / (2 * ab * bc)) * 180.0 / Math.PI; 135 136 } 136 137 … … 145 146 return thetas; 146 147 } 148 149 public static double CalculateMaxDiameter(List<double[]> convexHull) { 150 double maxDist = double.MinValue; 151 152 for (int i = 0; i < convexHull.Count; i++) { 153 for (int j = 0; j < convexHull.Count; j++) { 154 if (i != j) { 155 double dist = convexHull[i].EuclideanDistance(convexHull[j]); 156 if (dist > maxDist) 157 maxDist = dist; 158 } 159 } 160 } 161 return maxDist; 162 } 147 163 } 148 164 } -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers-3.3.csproj
r10262 r10275 93 93 <Private>False</Private> 94 94 </Reference> 95 <Reference Include="HeuristicLab.Problems.TestFunctions-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 96 <SpecificVersion>False</SpecificVersion> 97 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Problems.TestFunctions-3.3.dll</HintPath> 98 <Private>False</Private> 99 </Reference> 95 100 <Reference Include="HeuristicLab.Problems.TravelingSalesman-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 96 101 <SpecificVersion>False</SpecificVersion> -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/Plugin.cs.frame
r10116 r10275 33 33 [PluginDependency("HeuristicLab.Encodings.RealVectorEncoding", "3.3")] 34 34 [PluginDependency("HeuristicLab.Problems.TravelingSalesman", "3.3")] 35 [PluginDependency("HeuristicLab.Problems.TestFunctions", "3.3")] 35 36 [PluginDependency("HeuristicLab.Operators", "3.3")] 36 37 [PluginDependency("HeuristicLab.Optimization", "3.3")] -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/RunCollectionModifiers/RealVectorConvexHullModifier.cs
r10272 r10275 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 28 29 using HeuristicLab.Encodings.RealVectorEncoding; 29 30 using HeuristicLab.Optimization; 31 using HeuristicLab.Parameters; 30 32 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 33 using HeuristicLab.Problems.TestFunctions; 31 34 32 35 namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers { … … 35 38 public class RealVectorConvexHullModifier : ParameterizedNamedItem, IRunCollectionModifier { 36 39 private const string SolutionCacheResultName = "SolutionCache"; 40 private const string CentroidMovementDistancesName = "Centroid Movement Distances"; 41 private const string CentroidMotionName = "Centroid Motion"; 42 private const string BestSolutionName = "Best Solution"; 43 44 public IValueParameter<DoubleArray> BestSolutionParameter { 45 get { return (ValueParameter<DoubleArray>)Parameters[BestSolutionName]; } 46 } 37 47 38 48 [StorableConstructor] 39 49 protected RealVectorConvexHullModifier(bool deserializing) : base(deserializing) { } 40 50 protected RealVectorConvexHullModifier(RealVectorConvexHullModifier original, Cloner cloner) : base(original, cloner) { } 41 public RealVectorConvexHullModifier() { } 51 public RealVectorConvexHullModifier() { 52 Parameters.Add(new ValueParameter<DoubleArray>(BestSolutionName, new DoubleArray())); 53 } 42 54 public override IDeepCloneable Clone(Cloner cloner) { 43 55 return new RealVectorConvexHullModifier(this, cloner); … … 51 63 if (solutionCache == null) continue; 52 64 65 List<double[]> centroidList = new List<double[]>(); 66 var bestSolution = run.Results["Best Solution"] as SingleObjectiveTestFunctionSolution; 67 //var bestKnownSolution = ConvertRealVectorToVertexArray(bestSolution.BestKnownRealVector); 68 var bestKnownSolution = BestSolutionParameter.Value; 69 53 70 DataTable volDataTable = new DataTable("Convex hull volume over generations"); 54 71 DataTable nrOfPointsTable = new DataTable("Nr. of points of convex hull"); 72 DataTable centroidDistancesTable = new DataTable(CentroidMovementDistancesName); 73 DataTable centroidMotionTable = new DataTable(CentroidMotionName); 55 74 DoubleValue overallVolume = new DoubleValue(); 56 75 57 76 DataRow dtVolumeRow = new DataRow("Volume"); 58 77 DataRow dtNrPointsRow = new DataRow("Nr. of points"); 78 DataRow dtCentroidDistances = new DataRow("Distances"); 79 DataRow dtCentroidMotion = new DataRow("Motion"); 80 DataRow dtCentroidDistanceFromOptimum = new DataRow("Distance from optimum"); 81 centroidMotionTable.Rows.Add(dtCentroidMotion); 82 centroidDistancesTable.Rows.Add(dtCentroidDistances); 83 centroidDistancesTable.Rows.Add(dtCentroidDistanceFromOptimum); 59 84 volDataTable.Rows.Add(dtVolumeRow); 60 85 nrOfPointsTable.Rows.Add(dtNrPointsRow); 61 86 62 List<double[]> c urHull = null;87 List<double[]> completeHull = null; 63 88 var sols = solutionCache.GetSolutionsFromGeneration(i); 64 89 while (sols.Count != 0) { … … 72 97 } 73 98 dtNrPointsRow.Values.Add(convexHull.Count); 99 centroidList.Add(ConvexHullMeasures.CalculateCentroids(convexHull)); 74 100 75 if (curHull == null) { 76 curHull = convexHull; 101 //incrementally build complete convex hull 102 if (completeHull == null) { 103 completeHull = convexHull; 77 104 } else { 78 var newPHull = c urHull.Union(convexHull).ToArray();79 c urHull = LPHull.Calculate(newPHull);105 var newPHull = completeHull.Union(convexHull).ToArray(); 106 completeHull = LPHull.Calculate(newPHull); 80 107 } 81 108 … … 83 110 } 84 111 85 if (c urHull != null && curHull.Any() && curHull.First().Length < curHull.Count) {86 overallVolume.Value = ConvexHullMeasures.CalculateVolume(c urHull);112 if (completeHull != null && completeHull.Any() && completeHull.First().Length < completeHull.Count) { 113 overallVolume.Value = ConvexHullMeasures.CalculateVolume(completeHull); 87 114 } else { 88 115 overallVolume.Value = double.NaN; 89 116 } 90 117 118 CalculateMovementDistances(dtCentroidDistances, centroidList, run); 119 CalculateMotionMeasures(dtCentroidMotion, centroidList, run); 120 CalculateCentroidDistanceFromOptimum(dtCentroidDistanceFromOptimum, centroidList, bestKnownSolution.ToArray()); 121 91 122 run.Results["Overall volume"] = overallVolume; 123 run.Results["Overall diameter"] = new DoubleValue(ConvexHullMeasures.CalculateMaxDiameter(completeHull)); 92 124 run.Results["Convex hull volume"] = volDataTable; 93 125 run.Results["Nr. of points on convex hull"] = nrOfPointsTable; 126 run.Results[CentroidMovementDistancesName] = centroidDistancesTable; 127 run.Results[CentroidMotionName] = centroidMotionTable; 94 128 } 129 } 130 131 private void CalculateCentroidDistanceFromOptimum(DataRow row, List<double[]> centroidList, double[] bestKnownSolution) { 132 foreach (var centroid in centroidList) { 133 double distance = centroid.EuclideanDistance(bestKnownSolution); 134 row.Values.Add(distance); 135 } 136 } 137 138 private void CalculateMovementDistances(DataRow row, List<double[]> centroidList, IRun run) { 139 var distances = ConvexHullMeasures.CalculateMovementDistances(centroidList); 140 foreach (var distance in distances) { 141 row.Values.Add(distance); 142 } 143 run.Results["Centroid Movement Distance Avg."] = new DoubleValue(distances.Average()); 144 run.Results["Centroid Movement Distance Std.Dev."] = new DoubleValue(distances.StandardDeviation()); 145 run.Results["Centroid Movement Distance Sum"] = new DoubleValue(distances.Sum()); 146 run.Results["Centroid Movement Overall Distance"] = new DoubleValue(ConvexHullMeasures.CalculateOverallMovementDistances(centroidList)); 147 } 148 149 private void CalculateMotionMeasures(DataRow row, List<double[]> centroidList, IRun run) { 150 var motions = ConvexHullMeasures.CalculateCentroidsMotion(centroidList).Select(y => Math.Abs(y)).ToList(); 151 foreach (var motion in motions) { 152 row.Values.Add(motion); 153 } 154 run.Results["Centroid Motion Avg."] = new DoubleValue(motions.Average()); 155 run.Results["Centroid Motion Std.Dev."] = new DoubleValue(motions.StandardDeviation()); 156 run.Results["Centroid Motion Sum"] = new DoubleValue(motions.Sum()); 95 157 } 96 158
Note: See TracChangeset
for help on using the changeset viewer.