Пример #1
0
        public KosarajuAlgorithm(DGraph G)
        {
            TopologicalSorting Gts = new TopologicalSorting(G);

            DGraph Gtr = G.Transposition();

            int[] mark = new int[G.VerticesCount];
            for (int i = 0; i < G.VerticesCount; ++i)
                mark[i] = -1;
            SCCEdg = new List<List<DEdge>>();
            SCCVrt = new List<List<int>>();

            for (int i = Gtr.VerticesCount - 1; i >= 0; --i)
                if (mark[Gts[i]] == -1)
                {
                    List<DEdge> tscce = new List<DEdge>();
                    SCCEdg.Add(tscce);

                    List<int> tsccv = new List<int>();
                    SCCVrt.Add(tsccv);

                    AddSCC(Gts[i], ref mark, Gtr);

                    SCCVrt[SCCCount].Sort();
                    ++SCCCount;
                }
        }
Пример #2
0
        public TopologicalSorting(DGraph G)
        {
            TS = new List<int>();
            bool[] was = new bool[G.VerticesCount];

            for (int i = 0; i < G.VerticesCount; ++i)
                if (!was[i])
                    DFS(i, ref was, G);
        }
Пример #3
0
        void DFS(int v, ref bool[] was, DGraph G)
        {
            was[v] = true;

            for (int i = 0; i < G.VertexDegree(v); ++i)
                if (!was[G.GetEdge(v, i).End])
                    DFS(G.GetEdge(v, i).End, ref was, G);

            TS.Add(v);
        }
Пример #4
0
 public DGraph(DGraph g)
     : this(g.VerticesCount)
 {
     for (int i = 0; i < g.VerticesCount; ++i)
         for (int j = 0; j < g[i].Count; ++j)
         {
             G[i].Add(g[i, j]);
             ++edg_num;
         }
 }
Пример #5
0
        void AddSCC(int v, ref int[] mark, DGraph G)
        {
            mark[v] = SCCCount;
            SCCVrt[SCCCount].Add(v);

            for (int i = 0; i < G.VertexDegree(v); ++i)
                if (mark[G.GetEdge(v, i).End] == SCCCount || mark[G.GetEdge(v, i).End] == -1)
                {
                    SCCEdg[SCCCount].Add(G.GetEdge(v, i).Reverse());
                    if (mark[G.GetEdge(v, i).End] == -1)
                        AddSCC(G.GetEdge(v, i).End, ref mark, G);
                }
        }
Пример #6
0
        private void ReadGraphFromATextFile_Click(object sender, EventArgs e)
        {
            openInputTxt.ShowDialog();
            string file = openInputTxt.FileName;

            G = new DGraph();
            G.ReadFromTxtFile(file);
        }
Пример #7
0
        private void ReadGraphFromAConsole_Click(object sender, EventArgs e)
        {
            AllocConsole();

            G = new DGraph();
            G.ReadFromConsole();

            FreeConsole();
        }
Пример #8
0
        public DGraph Transposition()
        {
            DGraph res = new DGraph(VerticesCount);
            for (int i = 0; i < VerticesCount; ++i)
                for (int j = 0; j < VertexDegree(i); ++j)
                    res.AddEdge(GetEdge(i, j).Reverse());

            return res;
        }