Esempio n. 1
0
        public static void Main(string[] args)
        {
            Point[]   points    = null;
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            LoadCities(out points);
            stopwatch.Stop();
            Console.WriteLine("Loading of cities.txt took: " + stopwatch.Elapsed);

            stopwatch.Reset();
            stopwatch.Start();
            LinearSearch <Point> linearSearch = new LinearSearch <Point>();

            linearSearch.Create(points, CalculatePointDistance);
            stopwatch.Stop();
            Console.WriteLine("Creation of linear search took: " + stopwatch.Elapsed);

            stopwatch.Reset();
            stopwatch.Start();
            VpTree <Point> vpTree = new VpTree <Point>();

            vpTree.Create(points, CalculatePointDistance);
            stopwatch.Stop();
            Console.WriteLine("Creation of VP tree search took: " + stopwatch.Elapsed);

            Point[] resultsLinear = null;
            Point[] resultsVpTree = null;

            double[] distancesLinear = null;
            double[] distancesVpTree = null;

            Point ourtarget = new Point();

            ourtarget.latitude  = 43.466438;            // Use same target as Steve Hanov did
            ourtarget.longitude = -80.519185;

            stopwatch.Reset();
            stopwatch.Start();
            linearSearch.Search(ourtarget, 8, out resultsLinear, out distancesLinear);
            stopwatch.Stop();
            Console.WriteLine("Linear search took: " + stopwatch.Elapsed);

            stopwatch.Reset();
            stopwatch.Start();
            vpTree.Search(ourtarget, 8, out resultsVpTree, out distancesVpTree);
            stopwatch.Stop();
            Console.WriteLine("VP tree search took: " + stopwatch.Elapsed);

            Console.WriteLine("RESULTS:");
            for (int i = 0; i < resultsVpTree.Length; i++)
            {
                Console.WriteLine(resultsVpTree[i].city);
                Console.WriteLine(" " + distancesVpTree[i]);
            }
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            Point[] points = null;
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            LoadCities(out points);
            stopwatch.Stop();
            Console.WriteLine("Loading of cities.txt took: " + stopwatch.Elapsed);

            stopwatch.Reset();
            stopwatch.Start();
            LinearSearch<Point> linearSearch = new LinearSearch<Point>();
            linearSearch.Create(points, CalculatePointDistance);
            stopwatch.Stop();
            Console.WriteLine("Creation of linear search took: " + stopwatch.Elapsed);

            stopwatch.Reset();
            stopwatch.Start();
            VpTree<Point> vpTree = new VpTree<Point>();
            vpTree.Create(points, CalculatePointDistance);
            stopwatch.Stop();
            Console.WriteLine("Creation of VP tree search took: " + stopwatch.Elapsed);

            Point[] resultsLinear = null;
            Point[] resultsVpTree = null;

            double[] distancesLinear = null;
            double[] distancesVpTree = null;

            Point ourtarget = new Point();
            ourtarget.latitude = 43.466438; // Use same target as Steve Hanov did
            ourtarget.longitude = -80.519185;

            stopwatch.Reset();
            stopwatch.Start();
            linearSearch.Search(ourtarget, 8, out resultsLinear, out distancesLinear);
            stopwatch.Stop();
            Console.WriteLine("Linear search took: " + stopwatch.Elapsed);

            stopwatch.Reset();
            stopwatch.Start();
            vpTree.Search(ourtarget, 8, out resultsVpTree, out distancesVpTree);
            stopwatch.Stop();
            Console.WriteLine("VP tree search took: " + stopwatch.Elapsed);

            Console.WriteLine("RESULTS:");
            for (int i = 0; i < resultsVpTree.Length; i++)
            {
                Console.WriteLine(resultsVpTree[i].city);
                Console.WriteLine(" " + distancesVpTree[i]);
            }
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            Point[] points = null;

            LoadCities(out points);

            LinearSearch <Point> linearSearch = new LinearSearch <Point>();

            linearSearch.Create(points, CalculatePointDistance);

            VpTree <Point> vpTree = new VpTree <Point>();

            vpTree.Create(points, CalculatePointDistance);

            Point[] resultsLinear = null;
            Point[] resultsVpTree = null;

            double[] distancesLinear = null;
            double[] distancesVpTree = null;

            System.Random rand = new System.Random();
            Point         ourtarget;

            for (int i = 0; i < 100; i++)
            {
                ourtarget = new Point("random", rand.NextDouble() * 180 - 90, rand.NextDouble() * 180 - 90);

                linearSearch.Search(ourtarget, 5 + i / 10, out resultsLinear, out distancesLinear);

                vpTree.Search(ourtarget, 5 + i / 10, out resultsVpTree, out distancesVpTree);

                CompareResults(resultsLinear, resultsVpTree);
            }

            if (errorCount == 0)
            {
                Console.WriteLine("TEST PASSED!");
            }
            else
            {
                Console.WriteLine("TEST FAILED!");
            }
        }
Esempio n. 4
0
        public static void Main(string[] args)
        {
            Point[] points = null;

            LoadCities(out points);

            LinearSearch<Point> linearSearch = new LinearSearch<Point>();
            linearSearch.Create(points, CalculatePointDistance);

            VpTree<Point> vpTree = new VpTree<Point>();
            vpTree.Create(points, CalculatePointDistance);

            Point[] resultsLinear = null;
            Point[] resultsVpTree = null;

            double[] distancesLinear = null;
            double[] distancesVpTree = null;

            System.Random rand = new System.Random();
            Point ourtarget;

            for (int i = 0; i < 100; i++)
            {
                ourtarget = new Point("random", rand.NextDouble() * 180 - 90, rand.NextDouble() * 180 - 90);

                linearSearch.Search(ourtarget, 5+i/10, out resultsLinear, out distancesLinear);

                vpTree.Search(ourtarget, 5+i/10, out resultsVpTree, out distancesVpTree);

                CompareResults(resultsLinear, resultsVpTree);
            }

            if (errorCount == 0)
            {
                Console.WriteLine("TEST PASSED!");
            }
            else
            {
                Console.WriteLine("TEST FAILED!");
            }
        }