Ejemplo n.º 1
0
        public HashSet <T2> GetBridges()
        {
            HashSet <T2> bridges = new HashSet <T2>();

            foreach (var bridge in _bridgeGraph.GetBridges())
            {
                if (bridge.Item1 <= bridge.Item2)
                {
                    bridges.Add(_indices2EdgeDict[bridge]);
                }
                else
                {
                    bridges.Add(_indices2EdgeDict[Tuple.Create(bridge.Item2, bridge.Item1)]);
                }
            }
            return(bridges);
        }
Ejemplo n.º 2
0
        public static void Test()
        {
            // Create graphs given in above diagrams
            Console.WriteLine("Bridges in first graph ");
            BridgeGraph g1 = new BridgeGraph(5);

            g1.AddEdge(1, 0);
            g1.AddEdge(0, 2);
            g1.AddEdge(2, 1);
            g1.AddEdge(0, 3);
            g1.AddEdge(3, 4);
            foreach (var bridge in g1.GetBridges())
            {
                Console.WriteLine("bridge: " + bridge.Item1 + " " + bridge.Item2);
            }

            Console.WriteLine("Bridges in Second graph");
            BridgeGraph g2 = new BridgeGraph(4);

            g2.AddEdge(0, 1);
            g2.AddEdge(1, 2);
            g2.AddEdge(2, 3);
            foreach (var bridge in g2.GetBridges())
            {
                Console.WriteLine("bridge: " + bridge.Item1 + " " + bridge.Item2);
            }

            Console.WriteLine("Bridges in Third graph ");
            BridgeGraph g3 = new BridgeGraph(7);

            g3.AddEdge(0, 1);
            g3.AddEdge(1, 2);
            g3.AddEdge(2, 0);
            g3.AddEdge(1, 3);
            g3.AddEdge(1, 4);
            g3.AddEdge(1, 6);
            g3.AddEdge(3, 5);
            g3.AddEdge(4, 5);
            foreach (var bridge in g3.GetBridges())
            {
                Console.WriteLine("bridge: " + bridge.Item1 + " " + bridge.Item2);
            }
        }