Exemplo n.º 1
0
        public static void main()
        {
            //create a form
            System.Windows.Forms.Form form = new System.Windows.Forms.Form();


            //create a viewer object
            Microsoft.Glee.GraphViewerGdi.GViewer viewer = new Microsoft.Glee.GraphViewerGdi.GViewer();

            //create a graph object
            Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("graph");



            //create the graph content
            CoursePlan coursePlan = new CoursePlan("Daftar Kuliah.txt");

            coursePlan.Print();

            foreach (KeyValuePair <string, Subject> entry in coursePlan.subjects)
            {
                Subject subject = entry.Value;
                foreach (string element in subject.preq_of)
                {
                    graph.AddEdge(subject.name, element);
                }
            }

            DFS resultDFS = new DFS(coursePlan.subjects);

            resultDFS.Print();

            Console.WriteLine();
            BFS resultBFS = new BFS(coursePlan.subjects);

            resultBFS.Print();

            /*string strNode1 = "Circle";
             * string strNode2 = "Home";
             * string strNode3 = "Diamond";
             * string strNode4 = "Standard";
             *
             * graph.AddEdge(strNode1, strNode2);
             * graph.AddEdge(strNode2, strNode1);
             * graph.AddEdge(strNode2, strNode2);
             * graph.AddEdge(strNode1, strNode3);
             * graph.AddEdge(strNode1, strNode4);
             * graph.AddEdge(strNode4, strNode1);*/

            //graph.AddEdge(strNode2, "Node 0");
            //for (int i = 0; i & lt; 3; i++) graph.AddEdge("Node " + i.ToString(), "Node " + (i + 1).ToString());
            //for (int i = 0; i & lt; 3; i++) graph.AddEdge("Node " + (i + 1).ToString(), "Node " + i.ToString());


            //bind the graph to the viewer
            viewer.Graph = graph;

            //associate the viewer with the form
            form.SuspendLayout();
            viewer.Dock = System.Windows.Forms.DockStyle.Fill;
            form.Controls.Add(viewer);
            form.ResumeLayout();

            //show the form
            form.ShowDialog();
        }
Exemplo n.º 2
0
        public static string filename;// = "../../../../" + "Daftar Kuliah.txt";

        public static void main()
        {
            //create a form
            System.Windows.Forms.Form form = new System.Windows.Forms.Form();
            form.Size = new System.Drawing.Size(1000, 600);

            //create a viewer object
            Microsoft.Glee.GraphViewerGdi.GViewer viewer = new Microsoft.Glee.GraphViewerGdi.GViewer();
            viewer.OutsideAreaBrush = Brushes.LightCoral;

            //create a graph object
            Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("graph");
            graph.GraphAttr.Backgroundcolor = Microsoft.Glee.Drawing.Color.LightCoral;

            //create the graph content
            CoursePlan    coursePlan = new CoursePlan(filename);
            Subject       tempSub    = new Subject();
            BFS           bfsResult  = new BFS(coursePlan.subjects);
            CoursePlan    tempCourse = new CoursePlan(filename);
            string        temp       = "1. " + bfsResult.result[1][0];
            List <string> convert    = new List <string>();

            foreach (KeyValuePair <int, List <string> > entry in bfsResult.result)
            {
                foreach (string x in entry.Value)
                {
                    convert.Add(x);
                }
            }

            for (int i = 0; i < convert.Count - 1; i++)
            {
                tempSub = tempCourse.subjects[convert[i]];
                foreach (string x in tempSub.preq_of)
                {
                    int index = convert.IndexOf(x) + 1;
                    graph.AddEdge(((i + 1).ToString() + ". " + convert[i]), (index.ToString() + ". " + x));
                }
            }
            int j = 1;

            foreach (KeyValuePair <int, List <string> > entry in bfsResult.result)
            {
                foreach (string tempp in entry.Value)
                {
                    Microsoft.Glee.Drawing.Node n = graph.FindNode(j.ToString() + ". " + tempp);
                    switch (entry.Key % 5)
                    {
                    case 1:
                    {
                        n.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.MidnightBlue;
                        n.Attr.Fontcolor = Microsoft.Glee.Drawing.Color.LavenderBlush;
                        break;
                    }

                    case 2:
                    {
                        n.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.MediumBlue;
                        n.Attr.Fontcolor = Microsoft.Glee.Drawing.Color.LavenderBlush;
                        break;
                    }

                    case 3:
                    {
                        n.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.RoyalBlue;
                        break;
                    }

                    case 4:
                    {
                        n.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.DodgerBlue;
                        break;
                    }

                    default:
                    {
                        n.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.SkyBlue;
                        break;
                    }
                    }
                    j++;
                }
            }

            //bind the graph to the viewer
            viewer.Graph = graph;

            //associate the viewer with the form
            form.SuspendLayout();
            viewer.Dock = System.Windows.Forms.DockStyle.Fill;
            form.Controls.Add(viewer);
            form.ResumeLayout();

            //show the form
            form.ShowDialog();
        }