Example #1
0
        public BridgeCalculator(IEnumerable <T1> nodes, IEnumerable <T2> edges,
                                Func <T2, T1> edge2SourceNodeFunc, Func <T2, T1> edge2TargetNodeFunc)
        {
            //_nodes = nodes;
            //_edges = edges;
            _edge2SourceNodeFunc = edge2SourceNodeFunc;
            _edge2TargetNodeFunc = edge2TargetNodeFunc;

            _node2IdDict = new Dictionary <T1, int>();
            //_edge2IdDict = new Dictionary<T2, int>();
            int index = 0;

            foreach (var node in nodes)
            {
                _node2IdDict.Add(node, index++);
            }
            //index = 0;
            //foreach (var edge in edges)
            //{
            //    _edge2IdDict.Add(edge, index++);
            //}
            //Initialize graph
            _bridgeGraph      = new BridgeGraph(nodes.Count());
            _indices2EdgeDict = new Dictionary <Tuple <int, int>, T2>();
            foreach (var edge in edges)
            {
                var tuple = GetEdge(edge);
                _bridgeGraph.AddEdge(tuple.Item1, tuple.Item2);
            }
        }
Example #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);
            }
        }
Example #3
0
        public void AddEdge(T2 edge)
        {
            var tuple = GetEdge(edge);

            _bridgeGraph.AddEdge(tuple.Item1, tuple.Item2);
        }