Beispiel #1
0
        public void KdTreeWithCoordinate_ReturnsTheSameResult_AsKdTreeWithArrayOfDouble()
        {
            var linearSearchWithOriginalKdTree = new KDTree <double, Coordinate>(2, CoordinatesAsDoubleArray, ArrayOfCoordinates, KdTreeHelper.L2Norm_Squared_Double)
                                                 .NearestNeighborClusterLinear(500, ArrayOfCoordinates).ToList();

            var linearSearchWithCoordinateKdTree = new KDTreeCoordinate <Coordinate>(2, ArrayOfCoordinates, KdTreeHelper.L2Norm_Squared_Coordinate)
                                                   .NearestNeighborClusterLinear(500, ArrayOfCoordinates).ToList();

            var radialSearchWithOriginalKdTreeRadial = new KDTree <double, Coordinate>(2, CoordinatesAsDoubleArray, ArrayOfCoordinates, KdTreeHelper.L2Norm_Squared_Double)
                                                       .NearestNeighborClusterRadial(radius: Radius.SuperSlowButAccurate, pointsPerCluster: 500, coordinates: ArrayOfCoordinates).ToList();

            var radialSearchWithCoordinateKdTreeRadial = new KDTreeCoordinate <Coordinate>(2, ArrayOfCoordinates, KdTreeHelper.L2Norm_Squared_Coordinate)
                                                         .NearestNeighborClusterRadial(radius: Radius.SuperSlowButAccurate, pointsPerCluster: 500, coordinates: ArrayOfCoordinates).ToList();

            linearSearchWithOriginalKdTree[0]
            .SequenceEqual(linearSearchWithCoordinateKdTree[0])
            .Should()
            .BeTrue();

            linearSearchWithOriginalKdTree[1]
            .SequenceEqual(linearSearchWithCoordinateKdTree[1])
            .Should()
            .BeTrue();


            radialSearchWithOriginalKdTreeRadial[0]
            .SequenceEqual(radialSearchWithCoordinateKdTreeRadial[0])
            .Should()
            .BeTrue();

            radialSearchWithOriginalKdTreeRadial[1]
            .SequenceEqual(radialSearchWithCoordinateKdTreeRadial[1])
            .Should()
            .BeTrue();
        }
Beispiel #2
0
        public void BothVersionOfKdTree_ReturnsTheSameSetOfCoordinates_GivenASetOfPoints()
        {
            var pointsNeeded = 100;

            var originalKdTree = new KDTree <double, Coordinate>(2, CoordinatesAsDoubleArray, ArrayOfCoordinates, KdTreeHelper.L2Norm_Squared_Double);

            var coordinateKdTree = new KDTreeCoordinate <Coordinate>(2, ArrayOfCoordinates, KdTreeHelper.L2Norm_Squared_Coordinate);

            var pointsFromOriginal = originalKdTree.NearestNeighborsLinear(CoordinatesAsDoubleArray.First(), pointsNeeded);

            var pointsFromModified = coordinateKdTree.NearestNeighborsLinear(ArrayOfCoordinates.First(), pointsNeeded);

            pointsFromOriginal.SequenceEqual(pointsFromModified).Should().BeTrue();
        }
Beispiel #3
0
        public void BothVersionOfKdTreeGenerateTheSameTreeStructure()
        {
            var originalKdTree = new KDTree <double, Coordinate>(2, CoordinatesAsDoubleArray, ArrayOfCoordinates, KdTreeHelper.L2Norm_Squared_Double);

            var coordinateKdTree = new KDTreeCoordinate <Coordinate>(2, ArrayOfCoordinates, KdTreeHelper.L2Norm_Squared_Coordinate);

            for (int i = 0; i < _numberOfCoordinates; i++)
            {
                if (coordinateKdTree.InternalTreeOfPoints[i] != null)
                {
                    originalKdTree.InternalPointArray[i][0].Should().Be(coordinateKdTree.InternalTreeOfPoints[i].Latitude);
                }
            }
        }
Beispiel #4
0
        public void KdTreeLinearSearchCoordinate_ReturnsTheSameResultAs_NearestNeighbourBruteForce()
        {
            var pathClusterFinderWithListNeighboringPoints = new PathClusterFinderWithList(_listOfCoordinates, _pointPerCluster)
                                                             .GetPointClusters().ToList();

            var nearestPointsKdTreeLinear =
                new KDTreeCoordinate <Coordinate>(2, ArrayOfCoordinates,
                                                  KdTreeHelper.L2Norm_Squared_Coordinate)
                .NearestNeighborClusterLinear(_pointPerCluster, ArrayOfCoordinates)
                .ToList();

            pathClusterFinderWithListNeighboringPoints[0].OrderBy(k => k.CoordinateId)
            .SequenceEqual(nearestPointsKdTreeLinear[0].OrderBy(k => k.CoordinateId))
            .Should()
            .BeTrue();

            pathClusterFinderWithListNeighboringPoints[1].OrderBy(k => k.CoordinateId)
            .SequenceEqual(nearestPointsKdTreeLinear[1].OrderBy(k => k.CoordinateId))
            .Should()
            .BeTrue();
        }