Esempio n. 1
0
        public void ShortesPathTest(double[] expected, int n, int start, params int[][] g)
        {
            var graph = Common.GetAdjacencyList(n, g);

            var distances = BellmanFord.ShortestPath(graph, start);

            Common.AssertEqual(expected, distances);
        }
Esempio n. 2
0
        public void TestBellmanFord()
        {
            BellmanFord bellman = graph.BellmanFord(0);

            for (int i = 1; i < graph.V(); i++)
            {
                Edge[] path = bellman.ShortestPath(i);

                TestContext.WriteLine("Path: " + ToString(path));
                TestContext.WriteLine("Weight: " + bellman.Weight(i).ToString());
            }
        }
Esempio n. 3
0
    static void Main(string[] args)
    {
        Dictionary <string, Dictionary <string, int> > map = new Dictionary <string, Dictionary <string, int> >();

        map.Add("A", addEdge(addEdge(addEdge(new Dictionary <string, int>(), "B", 2), "C", 5), "D", 1));
        map.Add("B", addEdge(new Dictionary <string, int>(), "C", 1));
        map.Add("C", addEdge(new Dictionary <string, int>(), "F", 5));
        map.Add("D", addEdge(addEdge(addEdge(new Dictionary <string, int>(), "B", 2), "C", 3), "E", 1));
        map.Add("E", addEdge(addEdge(new Dictionary <string, int>(), "C", 1), "F", 2));


        BellmanFord bellmanFord = new BellmanFord();

        Console.WriteLine(bellmanFord.ShortestPath(map, "A", "A"));
        Console.ReadLine();
    }