- Timestamp:
- 11/05/13 23:04:16 (11 years ago)
- Location:
- branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/AlgorithmBehaviorUnitTests.csproj
r10104 r10108 36 36 </PropertyGroup> 37 37 <ItemGroup> 38 <Reference Include="ALGLIB-3.7.0, Version=3.7.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 39 <SpecificVersion>False</SpecificVersion> 40 <HintPath>..\..\..\trunk\sources\bin\ALGLIB-3.7.0.dll</HintPath> 41 </Reference> 38 42 <Reference Include="HeuristicLab.Common-3.3"> 39 43 <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath> -
branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/DistanceMatrixToPointsTest.cs
r10078 r10108 22 22 using System; 23 23 using HeuristicLab.Analysis.AlgorithmBehavior.Analyzers; 24 using HeuristicLab.Common; 24 25 using Microsoft.VisualStudio.TestTools.UnitTesting; 25 26 … … 28 29 public class DistanceMatrixToPointsTest { 29 30 [TestMethod] 30 public void TestDistanceMatrixConversion () {31 int nrOfPoints = 4;31 public void TestDistanceMatrixConversionStatic() { 32 int nrOfPoints = 3; 32 33 int dim = 2; 33 34 double[][] orgPoints = new double[nrOfPoints][]; … … 36 37 double[][] newPoints = null; 37 38 38 39 39 AllocArray(orgPoints, dim); 40 40 AllocArray(orgDm, nrOfPoints); 41 41 AllocArray(newDm, nrOfPoints); 42 SamplePoints(orgPoints); 42 //SamplePoints(orgPoints); 43 StaticPoints(orgPoints); 43 44 CalculateDistanceMatrix(orgDm, orgPoints); 44 45 45 newPoints = DistanceMatrixToPoints. ConvertDistanceMatrixToPoints(orgDm);46 newPoints = DistanceMatrixToPoints.MetricMDS(orgDm); 46 47 47 48 CalculateDistanceMatrix(newDm, newPoints); 48 //TODO 49 Console.WriteLine("orgDm:"); 50 PrintDM(orgDm); 51 Console.WriteLine("newDm:"); 52 PrintDM(newDm); 49 53 54 for (int i = 0; i < orgDm.Length; i++) { 55 for (int j = 0; j < orgDm.Length; j++) { 56 double diff = orgDm[i][j] - newDm[i][j]; 57 Assert.IsTrue(diff.IsAlmost(0.0)); 58 } 59 } 60 } 61 62 private static void PrintDM(double[][] dm) { 63 for (int i = 0; i < dm.Length; i++) { 64 for (int j = 0; j < dm.Length; j++) { 65 Console.Write(dm[i][j] + " "); 66 } 67 Console.WriteLine(); 68 } 50 69 } 51 70 … … 60 79 } 61 80 81 private static void StaticPoints(double[][] points) { 82 points[0][0] = 2; 83 points[0][1] = 1; 84 85 points[1][0] = 5; 86 points[1][1] = 5; 87 88 points[2][0] = 3; 89 points[2][1] = 7; 90 } 91 62 92 private static void CalculateDistanceMatrix(double[][] dm, double[][] points) { 63 93 for (int i = 0; i < points.Length; i++) { 64 94 for (int j = 0; j < points.Length; j++) { 65 dm[i][j] = CalcEuclideanDistance(points[i],points[j]);95 dm[i][j] = points[i].EuclideanDistance(points[j]); 66 96 } 67 97 } 68 }69 70 private static double CalcEuclideanDistance(double[] p1, double[] p2) {71 double result = 0.0;72 for (int i = 0; i < p1.Length; i++) {73 result += Math.Pow(p1[i] - p2[i], 2);74 }75 return Math.Sqrt(result);76 98 } 77 99
Note: See TracChangeset
for help on using the changeset viewer.