示例#1
0
        public void TestShortestPathBetweenTheSameNode()
        {
            ShortestDistance sd = new ShortestDistance();

            int source       = 0;
            int target       = 0;
            int shortestPath = sd.ShortestPath(testNodeNetwork, source, target)[0][0];

            Assert.AreEqual(0, shortestPath);
        }
示例#2
0
        public void TestThatTheNetworkOfNodesIsAClosedNetwork()
        {
            ShortestDistance sd = new ShortestDistance();
            Node             nd = new Node();

            int[][] arrayToTest = nd.CreateNodeNetwork();
            for (int i = 0; i < 10; i++)
            {
                Assert.AreNotEqual(int.MaxValue, sd.ShortestPath(arrayToTest, 0, i)[0][0]);
            }
        }
        //Calculates the path weight of the two given nodes
        private void FindPathButton_Click(object sender, EventArgs e)
        {
            shortestPathText.Text = "Shortest path is: ";
            ShortestDistance sd = new ShortestDistance();
            int sourceNode      = selectStartNodeComboBox.SelectedIndex;
            int endNode         = selectEndNodeComboBox.SelectedIndex;

            int[][] result             = sd.ShortestPath(nodeNetwork, sourceNode, endNode);
            int     shortestPathWeight = result[0][0];

            int[] path = result[1];
            if (shortestPathWeight != 0)
            {
                PrintPathWay(endNode, path, endNode);
            }
            else
            {
                shortestPathText.Text = "Shortest path doesn't exist because start and end nodes are the same";
            }
            resultText.Text = "The shortest path between \"" + (sourceNode + 1) + "\" and \"" + (endNode + 1) + "\" has a weight of " + shortestPathWeight.ToString() + ".";
        }