static void Main(string[] args) { var random = new Random(); // Create 1million random points (with values from 0 to 10million) var items = new List <Point>(); for (int i = 0; i < 1000000; i++) { Point point = new Point($"Point{i}", random.Next(10000001)); items.Add(point); // Console.WriteLine($"{point.Key} {point.Value}"); } // Build tree var vpTree = new VantagePointTree <Point>(items); // Choose a random search target point var targetPoint = new Point("PointSearch", random.Next(10000001)); Console.WriteLine($"Search: {targetPoint}"); // Search the tree for 100 points similar to targetPoint var results = vpTree.Search(targetPoint, 100); foreach (var result in results) { Console.WriteLine($"{result}"); } }
public void Test1() { var items = new List <Point> { new Point("Point0", 9), new Point("Point1", 48), new Point("Point2", 52), new Point("Point3", 75), new Point("Point4", 77), new Point("Point5", 35), new Point("Point6", 36), new Point("Point7", 61), new Point("Point8", 17), new Point("Point9", 57), new Point("Point10", 87), new Point("Point11", 8), new Point("Point12", 90), new Point("Point13", 45), new Point("Point14", 88), new Point("Point15", 64), new Point("Point16", 37), new Point("Point17", 12), new Point("Point18", 78), new Point("Point19", 51) }; var vpTree = new VantagePointTree <Point>(Point.DistanceFunction, items); var targetPoint = new Point("PointSearch", 54); _output.WriteLine($"Search: {targetPoint}"); var results = vpTree.Search(targetPoint, 5); foreach (var result in results) { _output.WriteLine($"{result}"); } // TODO must implement IEquatable on Point for this to work as is // Assert.Equal(new TreeSearchResult<Point>(new Point("Point2", 52), 2), results[0]); // Assert.Equal(new TreeSearchResult<Point>(new Point("Point9", 57), 3), results[1]); // Assert.Equal(new TreeSearchResult<Point>(new Point("Point19", 51), 3), results[2]); // Assert.Equal(new TreeSearchResult<Point>(new Point("Point1", 48), 6), results[3]); // Assert.Equal(new TreeSearchResult<Point>(new Point("Point7", 61), 7), results[4]); }
static void Main() { var stopwatch = new Stopwatch(); var random = new Random(); // Create 1million random points (with values from 0 to 10million) stopwatch.Restart(); var items = new List <Point>(); for (int i = 0; i < 1000000; i++) { Point point = new Point($"Point{i}", random.Next(10000001)); items.Add(point); // Console.WriteLine($"{point.Key} {point.Value}"); } stopwatch.Stop(); Console.WriteLine("Creation took {0}", stopwatch.Elapsed); // Build tree stopwatch.Restart(); var vpTree = new VantagePointTree <Point>(Point.DistanceFunction, items); stopwatch.Stop(); Console.WriteLine("Tree build took {0}", stopwatch.Elapsed); // Choose a random search target point var targetPoint = new Point("PointSearch", random.Next(10000001)); Console.WriteLine($"Search: {targetPoint}"); // Search the tree for points similar to targetPoint stopwatch.Restart(); var results = vpTree.Search(targetPoint, 5); stopwatch.Stop(); Console.WriteLine("Search took {0}", stopwatch.Elapsed); foreach (var result in results) { Console.WriteLine($"{result}"); } }