示例#1
0
        private void btnSolve_Click(object sender, RoutedEventArgs e)
        {
            Stopwatch    sw         = Stopwatch.StartNew();
            List <Point> tempResult = tsp.BruteForce();

            sw.Stop();

            TimeSpan elapsedTime      = sw.Elapsed;
            string   shortestDistance = String.Format("{0:0.00}", tsp.shortestDistance);

            this.lblRunTime.Content = "Distance: " + shortestDistance + "\nRun Time: " + elapsedTime.ToString();

            displayRunTime();
            drawLines(tempResult);
        }
        private void btnSolve_Click(object sender, RoutedEventArgs e)
        {
            if (type == "bruteForce")
            {
                Stopwatch    sw         = Stopwatch.StartNew();
                List <Point> tempResult = tsp.BruteForce();
                sw.Stop();

                TimeSpan elapsedTime      = sw.Elapsed;
                string   shortestDistance = String.Format("{0:0.00}", tsp.shortestDistance);
                this.lblRunTime.Content = "Distance: " + shortestDistance + "\nRun Time: " + elapsedTime.ToString();

                displayRunTime();
                drawLines(tempResult);
            }
            else if (type == "dfs")
            {
                Stopwatch    sw         = Stopwatch.StartNew();
                List <Point> tempResult = tsp.DFS(tSPConnections);
                sw.Stop();

                TimeSpan elapsedTime      = sw.Elapsed;
                string   shortestDistance = String.Format("{0:0.00}", tsp.shortestDistance);
                this.lblRunTime.Content = "Distance: " + shortestDistance + "\nRun Time: " + elapsedTime.ToString();

                displayRunTime();
                drawLines(tempResult);
            }
            else if (type == "bfs")
            {
                Stopwatch    sw         = Stopwatch.StartNew();
                List <Point> tempResult = tsp.BFS(tSPConnections);
                sw.Stop();

                TimeSpan elapsedTime      = sw.Elapsed;
                string   shortestDistance = String.Format("{0:0.00}", tsp.shortestDistance);
                this.lblRunTime.Content = "Distance: " + shortestDistance + "\nRun Time: " + elapsedTime.ToString();

                displayRunTime();
                drawLines(tempResult);
            }
            else if (type == "closestEdge")
            {
                Stopwatch    sw         = Stopwatch.StartNew();
                List <Point> tempResult = tsp.ClosestEdgeInsertion();
                sw.Stop();

                TimeSpan elapsedTime      = sw.Elapsed;
                string   shortestDistance = String.Format("{0:0.00}", tsp.shortestDistance);
                this.lblRunTime.Content = "Distance: " + shortestDistance + "\nRun Time: " + elapsedTime.ToString();

                displayRunTime();
                drawLines(tempResult);
            }
            else if (type == "geneticAlgorithm")
            {
                if (this.geneticAlgorithmOptions == null)
                {
                    this.geneticAlgorithmOptions = new GeneticAlgorithmOptions(this);
                }

                this.geneticAlgorithmOptions.Show();
            }
            else
            {
                MessageBox.Show(type + " is not implemented yet");
            }
        }