Пример #1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        private void solveButton_Clicked()
        {
            // As default, solve the problem using the heap
            PriorityQueue queue    = new PriorityQueueHeap();
            Stopwatch     watch    = Stopwatch.StartNew();
            List <int>    pathHeap = Dijkstras(ref queue, false);

            watch.Stop();

            // Calculate time for heap
            double heapTime = (double)watch.ElapsedMilliseconds / 1000;

            heapTimeBox.Text = String.Format("{0}", heapTime);

            List <int> pathArray = new List <int>();

            // Now If the Array box is checked, solve it again using an array, and compare answers
            if (arrayCheckBox.Checked)
            {
                PriorityQueue queueArray = new PriorityQueueArray();
                watch     = Stopwatch.StartNew();
                pathArray = Dijkstras(ref queueArray, true);
                watch.Stop();

                // Calculate time for array
                double arrayTime = (double)watch.ElapsedMilliseconds / 1000;
                arrayTimeBox.Text  = String.Format("{0}", arrayTime);
                differenceBox.Text = String.Format("{0}", (arrayTime - heapTime) / heapTime);

                // check if the two paths are the same
                for (int i = 0; i < pathArray.Count(); i++)
                {
                    if (pathArray[i] != pathHeap[i])
                    {
                        Console.WriteLine("At index " + i + " pathArray was :" + pathArray[i] + " and pathHeap was " + pathHeap[i]);
                    }
                }
            }

            // Draw the final minimum cost path
            drawPath(ref pathHeap, false);
            drawPath(ref pathArray, true);
        }
Пример #2
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        private void solveButton_Clicked()
        {
            // As default, solve the problem using the heap
            PriorityQueue queue = new PriorityQueueHeap();
            Stopwatch watch = Stopwatch.StartNew();
            List<int> pathHeap = Dijkstras(ref queue, false);
            watch.Stop();

            // Calculate time for heap
            double heapTime = (double)watch.ElapsedMilliseconds / 1000;
            heapTimeBox.Text = String.Format("{0}", heapTime);

            List<int> pathArray = new List<int>();
            // Now If the Array box is checked, solve it again using an array, and compare answers
            if (arrayCheckBox.Checked)
            {
                PriorityQueue queueArray = new PriorityQueueArray();
                watch = Stopwatch.StartNew();
                pathArray = Dijkstras(ref queueArray, true);
                watch.Stop();

                // Calculate time for array
                double arrayTime = (double)watch.ElapsedMilliseconds / 1000;
                arrayTimeBox.Text = String.Format("{0}", arrayTime);
                differenceBox.Text = String.Format("{0}", (arrayTime - heapTime)/heapTime);
                
                // check if the two paths are the same
                for (int i = 0; i < pathArray.Count(); i++)
                {
                    if (pathArray[i] != pathHeap[i])
                        Console.WriteLine("At index " + i + " pathArray was :" + pathArray[i] + " and pathHeap was " + pathHeap[i]);
                }
            }
            
            // Draw the final minimum cost path
            drawPath(ref pathHeap, false);
            drawPath(ref pathArray, true);
        }