//MemberFunction
        public void Search(DirectedEdgeMatrix edge)
        //Search the graph from the vertice with 0 indegree
        {
            //Menghitung derajat masuk
            for (int i = 0; i < Size; i++)
            {
                indegree[i] = edge.countIndegree(i);
            }
            int j;

            for (int i = 0; i < Size; i++)
            {
                j = 0;
                //Mencari simpul yang belum dikunjungi yang memiliki indegree 0
                while (indegree[j] != 0 || VisitedSet.isVisited(j))
                {
                    j++;
                }
                VisitedSet.visit(j);
                Solution.Add(j);
                //Pencatatan indegree setiap langkah
                for (int k = 0; k < Size; k++)
                {
                    indegreePerStep[i, k] = indegree[k];
                }
                //Pengurangan indegree tentangga simpul yang dipilih
                for (int k = 0; k < Size; k++)
                {
                    if (edge.isAdjacent(j, k))
                    {
                        indegree[k] -= 1;
                    }
                }
            }
        }
Exemple #2
0
        public void read(string filename, out DirectedEdgeMatrix M, out Dictionary <int, string> MatKul)
        {
            string[] lines = System.IO.File.ReadAllLines(filename);
            string[] hasilSplit;
            Dictionary <string, int> indexMatkul = new Dictionary <string, int>();

            MatKul = new Dictionary <int, string>();
            int n = 0;

            //Pembentukan ukuran matrix
            foreach (string line in lines)
            {
                n++;
            }
            M = new DirectedEdgeMatrix(n);
            int    i = 0;
            int    j;
            string matkul;

            //Parsing untuk pembentukan dictionary matkul
            foreach (string line in lines)
            {
                hasilSplit = line.Replace(".", "").Replace(" ", "").Split(',');
                MatKul.Add(i, hasilSplit[0]);
                indexMatkul.Add(hasilSplit[0], i);
                i++;
            }
            i = 0;
            //Parsing dan memasukan data pada file input ke dalam matriks
            foreach (string line in lines)
            {
                j          = 0;
                hasilSplit = line.Replace(".", "").Replace(" ", "").Split(',');
                matkul     = hasilSplit[0];
                foreach (String prerequisite in hasilSplit)
                {
                    if (!matkul.Equals(prerequisite))
                    {
                        indexMatkul.TryGetValue(prerequisite, out j);
                        M.addEdge(j, i);
                    }
                    j++;
                }
                i++;
            }
        }
        //Constructor
        //Constructor sekaligus membentuk isi Semester;
        public Pengambilan_Matkul(List <int> Solution, DirectedEdgeMatrix M)
        {
            //Pembentukan array berdasarkan ukuran graf M
            Semester          = new List <List <int> >(M.getSize());
            MatkulPerSemester = new List <int>(M.getSize());
            for (int i = 0; i < M.getSize(); i++)
            {
                Semester.Add(new List <int>(M.getSize()));
            }

            //Pemilihan Matkul pada tiap semester
            int j           = 0;
            int countMatkul = 0;

            for (int i = 0; i < M.getSize(); i++)
            {
                if (Semester[0].Count == 0)
                {
                    Semester[j].Add(Solution[i]);
                    countMatkul += 1;
                }
                else
                {
                    //Jika ada prerequisitenya, diambil pada semester berikutnya
                    bool foundPrerequisite = false;
                    for (int k = 0; k < countMatkul; k++)
                    {
                        if (M.isAdjacent(Semester[j][k], Solution[i]))
                        {
                            foundPrerequisite = true;
                        }
                    }
                    if (foundPrerequisite)
                    {
                        MatkulPerSemester.Add(countMatkul);
                        j++;
                        countMatkul = 0;
                    }
                    countMatkul += 1;
                    Semester[j].Add(Solution[i]);
                }
            }
            JumlahSemester = j + 1; MatkulPerSemester.Add(countMatkul);
            MatkulPerSemester.Add(countMatkul);
        }
 public void Search(DirectedEdgeMatrix edge, int VerticeCheck, ref int time)
 //Search the vertice Check, then search the next vertices from vertice Check
 {
     VisitedSet.visit(VerticeCheck);
     VerticeTimeStamps[VerticeCheck] = new TimeStamp(time);
     //Penelurusan mulai
     CheckOrder.Add(new DFSCheck(VerticeCheck, false));
     time += 1;
     //Penelusuran anak
     for (int i = 0; i < Size; i++)
     {
         if ((!VisitedSet.isVisited(i)) && (edge.isAdjacent(VerticeCheck, i)))
         {
             Search(edge, i, ref time);
         }
     }
     //Penelusuran selesai
     VerticeTimeStamps[VerticeCheck].setEnd(time);
     CheckOrder.Add(new DFSCheck(VerticeCheck, true));
 }