Exemple #1
0
        // +++++++++++++++++++++++++++++++++++++++++++++++++++
        // +++++++++++++++++++++++++++++++++++++++++++++++++++
        // +++++++++++++++++++++++++++++++++++++++++++++++++++

        private void solveButton_Clicked()
        {
            // *** Implement this method, use the variables "startNodeIndex" and
            // "stopNodeIndex" as the indices for your start and stop points, respectively ***
            Console.WriteLine("Solving");
            Stopwatch timer = new Stopwatch();

            timer.Start();
            Tuple <List <int>, List <double> > t = Dijkstras.run(points, adjacencyList,
                                                                 startNodeIndex, stopNodeIndex,
                                                                 arrayCheckBox.Checked);

            timer.Stop();
            List <int>    res       = t.Item1;
            List <double> distances = t.Item2;

            if (res == null)
            {
                return;
            }
            if (arrayCheckBox.Checked)
            {
                arraySpeed = timer.Elapsed.TotalSeconds;
            }
            else
            {
                heapSpeed = timer.Elapsed.TotalSeconds;
            }
            if (arraySpeed != -1)
            {
                arrayTimeBox.Text = arraySpeed.ToString();
            }
            if (heapSpeed != -1)
            {
                heapTimeBox.Text = heapSpeed.ToString();
            }
            if (arraySpeed != -1 && heapSpeed != -1)
            {
                differenceBox.Text = (arraySpeed / heapSpeed).ToString();
            }
            pathCostBox.Text = distances[stopNodeIndex].ToString();
            Pen pen = new Pen(Color.Blue, 1);
            int a, b;

            for (int i = 0; i < res.Count; i++)
            {
                if (i > 0)
                {
                    a = res[i - 1];
                    b = res[i];
                    this.graphics.DrawLine(pen, points[a], points[b]);
                }
            }

            Console.WriteLine("Done");
        }
Exemple #2
0
        private Tuple <double, List <Edge> > CalculatePathCosts(List <Edge> pointerList)
        {
            double totalCost = 0;

            foreach (Edge edge in pointerList)
            {
                edge.pathCost = Dijkstras.GetDistance(edge.startPoint, edge.endPoint);
                totalCost    += edge.pathCost;
            }

            return(Tuple.Create(totalCost, pointerList));
        }
Exemple #3
0
        // +++++++++++++++++++++++++++++++++++++++++++++++++++
        // +++++++++++++++++++++++++++++++++++++++++++++++++++
        // +++++++++++++++++++++++++++++++++++++++++++++++++++

        private void solveButton_Clicked()
        {
            // *** Implement this method, use the variables "startNodeIndex" and
            // "stopNodeIndex" as the indices for your start and stop points, respectively ***
            Console.WriteLine("Solving");

            List <int> res = Dijkstras.run(points, adjacencyList,
                                           startNodeIndex, stopNodeIndex,
                                           arrayCheckBox.Checked);

            Console.WriteLine("Done");
        }
Exemple #4
0
        // Use this to generate routing tables for every node
        private void solveButton_Click(object sender, EventArgs e)
        {
            LoadStartEndIndices();

            if (startNodeIndex != -1 && stopNodeIndex != -1 && startNodeIndex != stopNodeIndex)
            {
                Dijkstras dk = new Dijkstras(startNodeIndex, stopNodeIndex, points, adjacencyList);

                stopwatch = Stopwatch.StartNew();
                List <Edge> backPointerList = dk.CalculateOnePath();
                stopwatch.Stop();

                onePathTime = stopwatch.Elapsed.TotalMilliseconds;

                stopwatch = Stopwatch.StartNew();
                dk.CalculateAllPaths();
                stopwatch.Stop();

                allPathsTime = stopwatch.Elapsed.TotalMilliseconds;

                oneTimeBox.Text    = Convert.ToString(onePathTime / 1000);
                allTimeBox.Text    = Convert.ToString(allPathsTime / 1000);
                differenceBox.Text = Convert.ToString((onePathTime / allPathsTime) * 100);

                if (backPointerList.Count > 0)
                {
                    Tuple <double, List <Edge> > calculations = CalculatePathCosts(backPointerList);
                    backPointerList = calculations.Item2;
                    double totalCost = calculations.Item1;
                    pathCostBox.Text = Convert.ToString(totalCost);

                    DrawLineList(backPointerList);
                }
                else
                {
                    pathCostBox.Text = "Unreachable.";
                }
            }
            else
            {
                seedUsedLabel.Text = "Invalid start/end nodes.";
            }
        }
Exemple #5
0
        // Use this to generate routing tables for every node
        private void solveButton_Click(object sender, EventArgs e)
        {
            LoadStartEndIndices();

            if (startNodeIndex != -1 && stopNodeIndex != -1 && startNodeIndex != stopNodeIndex)
            {
                Dijkstras dk = new Dijkstras(startNodeIndex, stopNodeIndex, points, adjacencyList);

                stopwatch = Stopwatch.StartNew();
                List<Edge> backPointerList = dk.CalculateOnePath();
                stopwatch.Stop();

                onePathTime = stopwatch.Elapsed.TotalMilliseconds;

                stopwatch = Stopwatch.StartNew();
                dk.CalculateAllPaths();
                stopwatch.Stop();

                allPathsTime = stopwatch.Elapsed.TotalMilliseconds;

                oneTimeBox.Text = Convert.ToString(onePathTime / 1000);
                allTimeBox.Text = Convert.ToString(allPathsTime / 1000);
                differenceBox.Text = Convert.ToString((onePathTime / allPathsTime) * 100);

                if (backPointerList.Count > 0)
                {
                    Tuple<double, List<Edge>> calculations = CalculatePathCosts(backPointerList);
                    backPointerList = calculations.Item2;
                    double totalCost = calculations.Item1;
                    pathCostBox.Text = Convert.ToString(totalCost);

                    DrawLineList(backPointerList);
                }
                else
                {
                    pathCostBox.Text = "Unreachable.";
                }
            }
            else
            {
                seedUsedLabel.Text = "Invalid start/end nodes.";
            }
        }