public TopologicalSortShortestPath(WeightedDiGraph G, int s)
        {
            this.s = s;
            int V = G.V();

            marked = new bool[V];
            edgeTo = new Edge[V];
            cost   = new double[V];

            for (var i = 0; i < V; ++i)
            {
                cost[i] = Double.MaxValue;
            }

            cost[s] = 0;

            DepthFirstPostOrder dfo = new DepthFirstPostOrder(G.ToDiGraph());

            foreach (var v in dfo.PostOrder())
            {
                foreach (var e in G.adj(v))
                {
                    Relax(G, e);
                }
            }
        }
示例#2
0
        public void Test()
        {
            DiGraph dag = GraphGenerator.dag();

            var dfo = new DepthFirstPostOrder(dag);

            console.WriteLine(dfo.PostOrderToString());
        }
        public StronglyConnectedComponents(DiGraph G)
        {
            count = 0;
            var V = G.V();

            marked = new bool[V];
            id     = new int[V];

            var ts = new DepthFirstPostOrder(G.reverse());

            foreach (var v in ts.PostOrder())
            {
                if (!marked[v])
                {
                    dfs(G, v);
                    count++;
                }
            }
        }