public void shortest_path_StateUnderTest_ExpectedBehavior(DijkstrasGraph <char> g, char start, char stop, int expected)
        {
            // Act
            var result = g.shortest_path(start, stop);

            // Assert
            Assert.Equal <int>(expected, result.Count);
        }
예제 #2
0
 public JohnsonsGraph(int nodeCount)
 {
     this.nodeCount    = nodeCount;
     augmentedMatrix   = new int[nodeCount + 2][nodeCount + 2];
     SOURCE_NODE       = nodeCount + 1;
     potential         = new int[nodeCount + 2];
     bellmanFord       = new BellmanFordGraph(nodeCount + 1);
     dijkstras         = new DijkstrasGraph(nodeCount);
     allShortestsPaths = new int[nodeCount + 1][nodeCount + 1];
 }
예제 #3
0
        public void DijkstraShortestPath_Test(Tuple <int, int, int>[] input, Tuple <int, int>[] output)
        {
            var gr = new DijkstrasGraph <int>(input);

            gr.EnforceOrder = true;
            gr.CalcPathLen(1);
            Tuple <int, int>[] pathLengths = new Tuple <int, int> [gr.VerticesCount];
            for (int i = 0; i < gr.VerticesCount; i++)
            {
                var v = gr.Vertices[i];
                pathLengths[i] = Tuple.Create(v.Key, v.PathLen);
            }
            Assert.AreEqual(output, pathLengths);
        }
        public static IEnumerable <object[]> TestGraphData()
        {
            var g = new DijkstrasGraph <char>();

            g.add_vertex('A', new Dictionary <char, int>()
            {
                { 'B', 7 }, { 'C', 8 }
            });
            g.add_vertex('B', new Dictionary <char, int>()
            {
                { 'A', 7 }, { 'F', 2 }
            });
            g.add_vertex('C', new Dictionary <char, int>()
            {
                { 'A', 8 }, { 'F', 6 }, { 'G', 4 }
            });
            g.add_vertex('D', new Dictionary <char, int>()
            {
                { 'F', 8 }
            });
            g.add_vertex('E', new Dictionary <char, int>()
            {
                { 'H', 1 }
            });
            g.add_vertex('F', new Dictionary <char, int>()
            {
                { 'B', 2 }, { 'C', 6 }, { 'D', 8 }, { 'G', 9 }, { 'H', 3 }
            });
            g.add_vertex('G', new Dictionary <char, int>()
            {
                { 'C', 4 }, { 'F', 9 }
            });
            g.add_vertex('H', new Dictionary <char, int>()
            {
                { 'E', 1 }, { 'F', 3 }
            });
            return(new[] {
                new object[] { g, 'A', 'H', 3 }
            });
        }
        private DijkstrasGraph <char> CreateDijkstrasGraph()
        {
            var g = new DijkstrasGraph <char>();

            return(g);
        }