예제 #1
0
        private void button_bfs_Click(object sender, EventArgs e)
        {
            if (File.Exists(filename))
            {
                treeView1.Nodes.Clear();
                treeView1.Refresh();
                richTextBox1.AppendText("Starting BFS Algorithm\n");
                ts = new TSort(filename);
                ArrayList sortedNode = new ArrayList();
                ts.img.Add(Graphviz.RenderImage(Utility.format2(ts.adjMatx, sortedNode, ts.nodename), "jpg"));
                sortedNode = ts.TopSortBFS(sortedNode);

                for (int i = 0; i < ts.message.ToArray().Length; i++)
                {
                    pictureBox1.Image = ts.img[i + 1];
                    pictureBox1.Refresh();
                    richTextBox1.AppendText(ts.message[i]);
                    richTextBox1.Refresh();
                    Thread.Sleep(500);
                }

                ts.status           = true;
                next_button.Enabled = true;
                play_button.Enabled = true;
                pictureBox1.Image   = ts.img[0];
                richTextBox1.AppendText("Done!!\n");

                List <List <int> > tes = ts.SemesterSort(sortedNode);
                for (int i = 0; i < tes.ToArray().Length; i++)
                {
                    TreeNode[] listcourse = new TreeNode[tes[i].ToArray().Length];
                    for (int j = 0; j < tes[i].ToArray().Length; j++)
                    {
                        listcourse[j] = new TreeNode(ts.nodename[tes[i][j]]);
                    }
                    TreeNode sem = new TreeNode("Semester " + (i + 1).ToString(), listcourse);
                    treeView1.Nodes.Add(sem);
                }
            }
            else
            {
                richTextBox1.AppendText("Error : File not Found!!\n");
            }
        }
예제 #2
0
        private void button_dfs_Click(object sender, EventArgs e)
        {
            if (File.Exists(filename))
            {
                treeView1.Nodes.Clear();
                treeView1.Refresh();
                richTextBox1.AppendText("Starting DFS Algorithm\n");
                ts = new TSort(filename);
                ArrayList sortedNode = new ArrayList();
                ts.img.Add(Graphviz.RenderImage(Utility.format1(ts.adjMatx, ts.timestamp, ts.nodename), "jpg"));
                int  i = 0, j = 0;
                bool found = false;
                while (j < ts.adjMatx.GetLength(1))
                {
                    if (sortedNode.Contains(j))
                    {
                        ++j; continue;
                    }
                    found = false;
                    while (!found && i < ts.adjMatx.GetLength(0))
                    {
                        if (ts.adjMatx[i, j])
                        {
                            found = true;
                        }
                        ++i;
                    }
                    if (found)
                    {
                        ++j; continue;
                    }
                    // Search the damn thing, starting from node j
                    sortedNode = ts.TopSortDFS(j, sortedNode);
                    ++j;
                }

                for (i = 0; i < ts.message.ToArray().Length; i++)
                {
                    pictureBox1.Image = ts.img[i + 1];
                    pictureBox1.Refresh();
                    richTextBox1.AppendText(ts.message[i]);
                    richTextBox1.Refresh();
                    Thread.Sleep(500);
                }

                ts.status           = true;
                next_button.Enabled = true;
                play_button.Enabled = true;
                pictureBox1.Image   = ts.img[0];
                richTextBox1.AppendText("Done!!\n");

                List <List <int> > tes = ts.SemesterSort(sortedNode);
                for (i = 0; i < tes.ToArray().Length; i++)
                {
                    TreeNode[] listcourse = new TreeNode[tes[i].ToArray().Length];
                    for (j = 0; j < tes[i].ToArray().Length; j++)
                    {
                        listcourse[j] = new TreeNode(ts.nodename[tes[i][j]]);
                    }
                    TreeNode sem = new TreeNode("Semester " + (i + 1).ToString(), listcourse);
                    treeView1.Nodes.Add(sem);
                }
            }
            else
            {
                richTextBox1.AppendText("Error : File not Found!!\n");
            }
        }