//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;
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            //Melakukan pembangkitan gambar untuk hasil solusi sequence dari topological sort
            //Menggunakan library graphviz
            //Gambar akan ditampilkan pada picturebox1
            var getStartProcessQuery        = new GetStartProcessQuery();
            var getProcessStartInfoQuery    = new GetProcessStartInfoQuery();
            var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);

            // GraphGeneration can be injected via the IGraphGeneration interface

            //Deklarasi wrapper
            var wrapper = new GraphGeneration(getStartProcessQuery,
                                              getProcessStartInfoQuery,
                                              registerLayoutPluginCommand);

            // Membuat query ke graphviz
            string request = "digraph G{{rank = same;";

            for (int i = 0; i < resultGraph.getSize(); i++)
            {
                request = request + pemetaanIndex[solution[i]] + ";";
            }

            for (int i = 0; i < resultGraph.getSize(); i++)
            {
                for (int j = 0; j < resultGraph.getSize(); j++)
                {
                    if (resultGraph.isAdjacent(i, j))
                    {
                        request = request + pemetaanIndex[i] + "->" + pemetaanIndex[j] + ";";
                    }
                }
            }
            request = request + "}}";

            // Membangkitkan gambar lau disimpan dalam byte
            byte[] output = wrapper.GenerateGraph(request, Enums.GraphReturnType.Jpg);

            //Drawing ke object Image
            Image gambar = System.Drawing.Image.FromStream(new MemoryStream(output));

            //Tampilkan gambar;
            pictureBox1.Image = gambar;
        }
        //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));
 }