Esempio n. 1
0
        private static void TestAllPairs()
        {
            //Graph for figure 4.15 part B
            Graph  g   = new Graph();
            Vertex v1  = new Vertex();
            Vertex v2  = new Vertex();
            Vertex v3  = new Vertex();
            Vertex v4  = new Vertex();
            Vertex v5  = new Vertex();
            Vertex v6  = new Vertex();
            Vertex v7  = new Vertex();
            Vertex v8  = new Vertex();
            Vertex v9  = new Vertex();
            Vertex v10 = new Vertex();
            Vertex v11 = new Vertex();
            Vertex v12 = new Vertex();

            g.AddVertex(v1);
            g.AddVertex(v2);
            g.AddVertex(v3);
            g.AddVertex(v4);
            g.AddVertex(v5);
            g.AddVertex(v6);
            g.AddVertex(v7);
            g.AddVertex(v8);
            g.AddVertex(v9);
            g.AddVertex(v10);
            g.AddVertex(v11);
            g.AddVertex(v12);

            g.AddEdge(new Edge(v1, v2, 5));
            g.AddEdge(new Edge(v1, v4, 10));
            g.AddEdge(new Edge(v2, v3, 7));
            g.AddEdge(new Edge(v2, v5, 1));
            g.AddEdge(new Edge(v3, v6, 4));
            g.AddEdge(new Edge(v4, v5, 3));
            g.AddEdge(new Edge(v5, v6, 3));
            g.AddEdge(new Edge(v1, v2, 5));
            g.AddEdge(new Edge(v4, v7, 11));
            g.AddEdge(new Edge(v1, v2, 5));
            g.AddEdge(new Edge(v5, v8, 7));
            g.AddEdge(new Edge(v6, v9, 5));
            g.AddEdge(new Edge(v7, v10, 9));
            g.AddEdge(new Edge(v7, v8, 2));
            g.AddEdge(new Edge(v8, v11, 1));
            g.AddEdge(new Edge(v8, v9, 0));
            g.AddEdge(new Edge(v9, v12, 12));
            g.AddEdge(new Edge(v11, v12, 4));

            float[,] d = GraphAlgorithms.AllPairsShortestPath(g);

            GraphAlgorithms.PrintMatrix(d, g.GetVertices().Count);
        }
Esempio n. 2
0
        private void onPrintMatrix(object sender, EventArgs e)
        {
            if (CurrentGraphPanel == null)
            {
                return;
            }

            Graph g = CurrentGraphPanel.Graph;

            g.UpdateMatrix();
            GraphAlgorithms.PrintMatrix(g.GetRawMatrix(), g.GetVertices().Count);
        }