예제 #1
0
        private void ButtonCalculate_Click(object sender, RoutedEventArgs e)
        {
            //Stopwatch
            long TimeAlgorithm;

            //Change UI
            GridPathInfo.Visibility   = Visibility.Visible;
            TabPanelYellow.Visibility = Visibility.Visible;

            //Get recommended path
            stopwatch.Restart();
            int percent = (int)SliderPercentage.Value;

            RecommendedPath = Recursion.FindRecommendedPath(percent);
            //RecommendedPath = Recursion.FindRecommendedPath(SliderPercentage.Value);
            stopwatch.Stop();
            TimeAlgorithm = stopwatch.ElapsedMilliseconds;

            //Change UI
            LabelRuntimeAlgorithm.Content = "Algorithm: " + TimeAlgorithm.ToString() + " ms";
            LabelRecommendedPath.Content  = "Recommended Path (" + Recursion.GetNumberOfTurns().ToString() + " Turns):";
            //LabelRecommendedPathLenght.Content = Recursion.GetPathLength().ToString();
            double RecommendedPathLength = Recursion.GetPathLength();
            double ShortestPathLength    = double.Parse(LabelShortestPathLenght.Content.ToString());

            LabelRecommendedPathLenght.Content     = RecommendedPathLength.ToString();
            LabelRecommendedPathPercentage.Content = (Math.Round((RecommendedPathLength - ShortestPathLength) / ShortestPathLength * 10000) / 100).ToString() + "%";
            Draw();
        }
예제 #2
0
        private void ButtonLoad_Click(object sender, RoutedEventArgs e)
        {
            //Stopwatch
            long TimeDijkstra, TimeAlgorithm;

            //Change UI
            CanvasGrid.Children.Clear();
            TabPanelYellow.Visibility   = Visibility.Hidden;
            GridPathInfo.Visibility     = Visibility.Hidden;
            SliderPercentage.Visibility = Visibility.Hidden;
            LabelPercentage.Visibility  = Visibility.Hidden;
            ButtonCalculate.Visibility  = Visibility.Hidden;

            //Reset paths
            RecommendedPath = null;
            LabelRecommendedPath.Content           = string.Empty;
            LabelRecommendedPathLenght.Content     = string.Empty;
            LabelRecommendedPathPercentage.Content = string.Empty;

            //Data Preprocessing
            if (!Data.ReadDataFromFile())
            {
                MessageBox.Show("Something went wrong");
                CanvasGrid.Children.Clear();
                return;
            }

            try
            {
                //Find shortest path length
                stopwatch.Restart();
                Dijkstra.FindShortestPathLength();
                stopwatch.Stop();
                TimeDijkstra = stopwatch.ElapsedMilliseconds;


                //Get shortest path
                stopwatch.Restart();
                ShortestPath = Recursion.FindRecommendedPath(0);
                stopwatch.Stop();
                TimeAlgorithm = stopwatch.ElapsedMilliseconds;

                //Change UI
                LabelRuntimeDijkstra.Content    = "Dijkstra: " + TimeDijkstra.ToString() + " ms";
                LabelRuntimeAlgorithm.Content   = "Algorithm: " + TimeAlgorithm.ToString() + " ms";
                LabelShortestPath.Content       = "Shortest Path (" + Recursion.GetNumberOfTurns().ToString() + " Turns):";
                LabelShortestPathLenght.Content = Recursion.GetPathLength().ToString();
                Draw();
                GridPathInfo.Visibility     = Visibility.Visible;
                SliderPercentage.Visibility = Visibility.Visible;
                LabelPercentage.Visibility  = Visibility.Visible;
                ButtonCalculate.Visibility  = Visibility.Visible;
            }
            catch (Exception)
            {
                MessageBox.Show("Graph is not complete");
                //throw;
            }
        }