public static void printDirectGraph(int[][] graphMatrix, int[][] basicGraph, int numberOfVertics)
        {
            Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("graph");

            for (int i = 0; i < numberOfVertics; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    if ((basicGraph[j][i] > 0) && graphMatrix[i][j] > 0)
                    {
                        Edge e = graph.AddEdge("Node" + (j + 1), "Node" + (i + 1));
                        e.EdgeAttr.Label = graphMatrix[i][j].ToString() + "/" + basicGraph[j][i];
                        e.EdgeAttr.Color = Microsoft.Glee.Drawing.Color.Green;
                    }
                }
            }

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

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

            //show the form
            maxFlowform.Show();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Desenha o grafo atual.
        /// </summary>
        private void DrawGraph(EDA.Graph graphToDraw, EDA.Node[] highlightedNodes)
        {
            List <EDA.Edge> edges = new List <EDA.Edge>();

            Glee.Graph drawingGraph = new Glee.Graph("Grafo - EDA2");
            // Adiciona nós ao grafo..
            foreach (EDA.Node node in graphToDraw.Nodes)
            {
                Glee.Node drawingNode = drawingGraph.AddNode(node.Name);
                drawingNode.Attr.Shape = Glee.Shape.Circle;
                if (highlightedNodes != null && Array.IndexOf(highlightedNodes, node) >= 0)
                {
                    drawingNode.Attr.Color = Glee.Color.Red;
                }
                // Consolida os arcos..
                edges.AddRange(node.Edges);
            }
            foreach (EDA.Edge edge in edges)
            {
                Glee.Edge drawingEdge = drawingGraph.AddEdge(edge.From.Name, edge.To.Name);
                drawingEdge.Attr.Label = String.Format("{0:F4}", edge.Cost);
            }
            // Gera controle de desenho..
            GleeUI.GViewer viewer = new GleeUI.GViewer();
            viewer.NavigationVisible = false;
            viewer.OutsideAreaBrush  = Brushes.White;
            viewer.RemoveToolbar();
            viewer.Graph = drawingGraph;
            viewer.Dock  = System.Windows.Forms.DockStyle.Fill;
            pnlGraph.Controls.Clear();
            pnlGraph.Controls.Add(viewer);
        }
        public static Microsoft.Glee.Drawing.Graph mstPrintGraph(int[][] graphMatrix, int numberOfVertex)

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

            for (int i = 0; i < numberOfVertex; i++)
            {
                for (int j = i; j < numberOfVertex; j++)
                {
                    if (graphMatrix[i][j] > 0)
                    {
                        Edge e = tempGraph.AddEdge("Node" + (i + 1), "Node" + (j + 1));
                        e.EdgeAttr.ArrowHeadAtTarget = ArrowStyle.None;

                        e.EdgeAttr.Label = graphMatrix[i][j].ToString();
                    }
                }
            }


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

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

            //show the form
            mstForm.Show();

            return(tempGraph);
        }
Exemplo n.º 4
0
        // ketika button 'Generate' diklik, membangun graf dari hasil bacaan file
        private void button2_Click(object sender, EventArgs e)
        {
            // membuat objek graf
            Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("graph");

            // membuat isi graf
            int numberOfNodes = Convert.ToInt32(richTextBox1.Lines[0]);

            _n = numberOfNodes;
            Init(_n);                    // inisialisasi graf
            string[] edge;
            for (int i = 1; i < _n; i++) // baca input graf dari richTextBox1
            {
                edge = richTextBox1.Lines[i].Split(' ');
                _x   = Convert.ToInt32(edge[0]);
                _y   = Convert.ToInt32(edge[1]);
                // membangun sisi
                graph.AddEdge(edge[0], edge[1]);
                Node node = graph.FindNode(edge[0]);
                // graf berbentuk lingkaran
                node.Attr.Shape = Microsoft.Glee.Drawing.Shape.Circle;
                node            = graph.FindNode(edge[1]);
                // membuat adjecent list
                Ukuran[_x] += 1;
                L[_x].Add(_y);
                // graf berbentuk lingkaran
                node.Attr.Shape = Microsoft.Glee.Drawing.Shape.Circle;
                // menghilangkan panah
                graph.GraphAttr.EdgeAttr.ArrowHeadAtTarget = ArrowStyle.None;
            }
            ;
            // graf dimasukkan ke viewer
            gViewer1.Graph = graph;
        }
        public static void printGraph(int[][] graphMatrix, int numberOfVertex, Form form)
        {
            //create a graph object
            Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("graph");

            for (int i = 0; i < numberOfVertex; i++)
            {
                for (int j = 0; j < numberOfVertex; j++)
                {
                    if (graphMatrix[i][j] > 0)
                    {
                        Edge e = graph.AddEdge("Node" + (i + 1), "Node" + (j + 1));


                        e.EdgeAttr.Label = graphMatrix[i][j].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.Show();
        }
Exemplo n.º 6
0
        private void button6_Click(object sender, EventArgs e)
        {
            //Menampilkan hasil pembacaan file dengan visualisasi DAG
            button1.Enabled = true;
            button4.Enabled = true;

            for (int i = 0; i < resultGraph.getSize(); i++)
            {
                for (int j = 0; j < resultGraph.getSize(); j++)
                {
                    if (resultGraph.isAdjacent(i, j))
                    {
                        string from, to;
                        pemetaanIndex.TryGetValue(i, out from);
                        pemetaanIndex.TryGetValue(j, out to);
                        graph.AddEdge(from, to);
                    }
                }
            }

            //Drawing
            selfEdge = new List <Edge>();
            for (int i = 0; i < resultGraph.getSize(); i++)
            {
                selfEdge.Add(graph.AddEdge(pemetaanIndex[i], pemetaanIndex[i]));
                selfEdge[i].Attr.Color = Microsoft.Glee.Drawing.Color.White;
                selfEdge[i].Attr.Label = "";
            }

            //Set graph
            viewer.Graph = graph;
            form.SuspendLayout();

            viewer.Dock = System.Windows.Forms.DockStyle.Fill;

            form.Controls.Add(viewer);

            form.ResumeLayout();
            form.MdiParent = this;
            //Show the form
            form.Show();
        }
Exemplo n.º 7
0
        static void buatMap(string mapLoc) //Membuat representasi peta dalam graf dan linkedlist
        {
            //Inisialisasi Graph
            //create a form

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

            //Inisialisasi variable static
            file    = new System.IO.StreamReader(@mapLoc);
            N       = Convert.ToInt32(file.ReadLine());
            nodeVal = new int[N + 1];
            visited = new bool[N + 1];
            pathArr = new int[N + 1];
            //ALGORITMA

            //inisialiasi ketetanggaan seluruh node dan nilai visited
            myList = new LinkedList <int> [N + 1];
            for (int i = 1; i <= N; i++)
            {
                visited[i] = false;
                myList[i]  = new LinkedList <int>();
            }

            //Input
            string[] inp = new string[2];
            int      temp1, temp2;

            for (int i = 0; i < N - 1; i++)
            {
                inp   = file.ReadLine().Split();
                temp1 = int.Parse(inp[0]);
                temp2 = int.Parse(inp[1]);

                //Mengisi ketetanggaan kedua node
                myList[temp1].AddLast(temp2);
                myList[temp2].AddLast(temp1);

                //Membuat Graph
                string tempst1 = temp1.ToString();
                string tempst2 = temp2.ToString();
                graph.AddEdge(tempst1, tempst2);
            }
            //Inisialisasi nilai awal simpul dengan nol
            for (int i = 1; i <= N; i++)
            {
                nodeVal[i] = 0;
            }
            giveNodeValue(1, 0);
        }
        public static void printAugmentedPath(int[][] graphMatrix, int numberOfVertex, int[] parent)
        {
            Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("graph");

            for (int i = 0; i < numberOfVertex; i++)
            {
                for (int j = 0; j < numberOfVertex; j++)
                {
                    if (graphMatrix[i][j] > 0)
                    {
                        Edge e = graph.AddEdge("Node" + (i + 1), "Node" + (j + 1));
                        e.EdgeAttr.Label = graphMatrix[i][j].ToString();
                    }
                }
            }

            int u;

            try
            {
                for (int v = numberOfVertex - 1; v != 0; v = parent[v])
                {
                    u = parent[v];
                    Node n1 = graph.FindNode("Node" + (u + 1));
                    Node n2 = graph.FindNode("Node" + (v + 1));

                    n1.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Red;
                    n2.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Red;

                    //    Edge e = graph.AddEdge("Node" + u, "Node" + v);
                    //   e.EdgeAttr.Color = Microsoft.Glee.Drawing.Color.Red;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Your graph is incorrect \nGraph should be directed with source and sink");
            }



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

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

            //show the form
            maxFlowform.Show();
        }
        public static Microsoft.Glee.Drawing.Graph printMinNode(int[][] graphMatrix, int numberOfVertex, int[] distance, int minNode)
        {
            //create a graph object
            Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("graph");

            for (int i = 0; i < numberOfVertex; i++)
            {
                for (int j = 0; j < numberOfVertex; j++)
                {
                    if (graphMatrix[i][j] > 0)
                    {
                        Edge e = graph.AddEdge("Node" + (i + 1), "Node" + (j + 1));

                        e.EdgeAttr.Label = graphMatrix[i][j].ToString();
                    }
                }
            }


            for (int i = 0; i < numberOfVertex; i++)
            {
                Node n = graph.FindNode("Node" + (i + 1));
                if (distance[i] == Int32.MaxValue)
                {
                    n.Attr.Label += "\n(" + "infinity" + ")";
                }
                else
                {
                    n.Attr.Label += "\n(" + distance[i].ToString() + ")";
                }
            }

            Node n1 = graph.FindNode("Node" + (minNode + 1));

            n1.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Red;

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

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

            //show the form
            dijkstraForm.Show();
            return(graph);
        }
Exemplo n.º 10
0
        //отрисовка графа
        private void DrawGraph(int currentTop)
        {
            this.GraphPanel.Controls.Clear();
            Microsoft.Glee.GraphViewerGdi.GViewer viewer = new Microsoft.Glee.GraphViewerGdi.GViewer();
            viewer.AsyncLayout = false;
            viewer.AutoScroll  = true;
            nodes = new string[nodesCount];
            for (int i = 0; i < nodesCount; ++i)
            {
                nodes[i] = (i + 1).ToString();
            }

            graph = new Microsoft.Glee.Drawing.Graph("Graph");
            for (int i = 0; i < nodesCount; ++i)
            {
                for (int j = 0; j < nodesCount; ++j)
                {
                    if (adjancyMatrix[i, j] != 0)
                    {
                        graph.AddEdge(nodes[i], "" /*adjancyMatrix[i, j].ToString()*/, nodes[j]);
                    }
                }
            }
            for (int i = 0; i < nodesCount; ++i)
            {
                Microsoft.Glee.Drawing.Node currentNode = graph.FindNode(nodes[i]);
                if (i == currentTop)
                {
                    currentNode.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Green;
                }
                else
                {
                    currentNode.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Yellow;
                }
                currentNode.Attr.Shape = Microsoft.Glee.Drawing.Shape.DoubleCircle;
            }
            Microsoft.Glee.GraphViewerGdi.GraphRenderer renderer = new Microsoft.Glee.GraphViewerGdi.GraphRenderer(graph);
            viewer.Graph = graph;
            this.GraphPanel.SuspendLayout();
            viewer.Dock = System.Windows.Forms.DockStyle.Fill;
            this.GraphPanel.Controls.Add(viewer);
            this.GraphPanel.ResumeLayout();

            //Bitmap graphImage = new Bitmap(GraphPanel.Width, GraphPanel.Height);
            //renderer.Render(graphImage);
            //GraphPanel.Image = graphImage;
        }
Exemplo n.º 11
0
        public static void main()
        {
            //create a form
            System.Windows.Forms.Form form = new System.Windows.Forms.Form();
            form.BackColor = System.Drawing.Color.Black;
            form.Size      = new System.Drawing.Size(1000, 600);

            //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");
            graph.GraphAttr.Backgroundcolor = Microsoft.Glee.Drawing.Color.LavenderBlush;

            //create the graph content
            CoursePlan coursePlan = new CoursePlan(filename);

            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);
                }
            }

            //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();

            // print to console
            //DFS resultDFS = new DFS(coursePlan.subjects);
            //resultDFS.Print();
        }
Exemplo n.º 12
0
        void makegraph()
        {
            string strNode1 = "user";
            string strNode2 = "likes";
            string strNode3 = "groups";
            string strNode4 = "movies";

            graph.AddEdge(strNode1, strNode2);
            graph.AddEdge(strNode1, strNode3);
            graph.AddEdge(strNode1, strNode4);

            foreach (string s in listL)
            {
                graph.AddEdge(strNode2, s);
            }
            foreach (string s in listG)
            {
                graph.AddEdge(strNode3, s);
            }
            foreach (string s in listM)
            {
                graph.AddEdge(strNode4, s);
            }


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

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

            //show the form
            // this.ShowDialog();
        }
Exemplo n.º 13
0
        //[STAThread]
        static void buildTree(ref StreamReader sr, int jmlRumah)
        {
            tree      = new List <List <int> >(jmlRumah + 1);
            pointsTo  = new int[jmlRumah + 1];
            isBody    = new bool[jmlRumah + 1];
            isBody[1] = true;

            for (int i = 0; i <= jmlRumah; i++)
            {
                tree.Add(new List <int>());
            }

            List <(int, int)> pending = new List <(int a, int b)>();

            for (int i = 0; i < jmlRumah - 1; i++)
            {
                string[] line = sr.ReadLine().Split();

                int a = Int32.Parse(line[0]);
                int b = Int32.Parse(line[1]);


                if (isBody[a])
                {
                    pointsTo[b] = a;
                    isBody[b]   = true;
                }
                else if (isBody[b])
                {
                    pointsTo[a] = b;
                    isBody[a]   = true;
                }
                else
                {
                    pending.Add((a, b));
                }
                tree[a].Add(b);
                tree[b].Add(a);
                // Add edges between 2 vertices to graph object:
                Microsoft.Glee.Drawing.Edge e = defaultG.AddEdge(line[0], line[1]);
                // Set edges without arrowhead => UNDIRECTED GRAPH!
                e.Attr.ArrowHeadAtTarget = ArrowStyle.None;
            }

            int idx = 0;

            while (pending.Any())
            {
                if (idx >= pending.Count())
                {
                    idx = 0;
                }
                int a = pending[idx].Item1;
                int b = pending[idx].Item2;
                if (isBody[a])
                {
                    pointsTo[b] = a;
                    isBody[b]   = true;
                    pending.RemoveAt(idx);
                }
                else if (isBody[b])
                {
                    pointsTo[a] = b;
                    isBody[a]   = true;
                    pending.RemoveAt(idx);
                }
                else
                {
                    idx++;
                }
            }
        }
Exemplo n.º 14
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();
        }
        public static void printDijkstraPath(int[][] graphMatrix, int numberOfVertex, int[] distance,
                                             int[] path, int distination)
        {
            //create a graph object
            Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("graph");

            for (int i = 0; i < numberOfVertex; i++)
            {
                for (int j = 0; j < numberOfVertex; j++)
                {
                    if (graphMatrix[i][j] > 0)
                    {
                        Edge e = graph.AddEdge("Node" + (i + 1), "Node" + (j + 1));

                        e.EdgeAttr.Label = graphMatrix[i][j].ToString();
                    }
                }
            }


            for (int i = 0; i < numberOfVertex; i++)
            {
                Node n = graph.FindNode("Node" + (i + 1));
                if (distance[i] == Int32.MaxValue)
                {
                    n.Attr.Label += "\n(" + "infinity" + ")";
                }
                else
                {
                    n.Attr.Label += "\n(" + distance[i].ToString() + ")";
                }
            }

            int iTemp = distination;
            int jTemp = 0;

            while (iTemp != (-1))
            {
                jTemp = path[iTemp];

                if (iTemp != 0)
                {
                    Node nsource = graph.FindNode("Node" + (jTemp + 1));
                    Node ntarget = graph.FindNode("Node" + (iTemp + 1));
                    foreach (var edge in nsource.OutEdges)
                    {
                        if (edge.TargetNode == ntarget)
                        {
                            edge.EdgeAttr.Color = Microsoft.Glee.Drawing.Color.Red;
                        }
                    }
                }


                iTemp = jTemp;
            }

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

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

            //show the form
            dijkstraForm.Show();
        }
        void makegraph()
        {
            string          strNode1    = fs.Name;
            string          strNode2    = "Likes";
            string          strNode3    = "Posts";
            string          strNode4    = "Movies";
            string          strNode5    = "Book";
            string          strNodeX    = "";
            string          strNodeLike = "Liked By";
            string          id          = "";
            DataGridViewRow selectedRow;

            try
            {
                if (dgvPosts.SelectedCells.Count > 0)
                {
                    int selectedrowindex = dgvPosts.SelectedCells[0].RowIndex;

                    selectedRow = dgvPosts.Rows[selectedrowindex];

                    id       = Convert.ToString(selectedRow.Cells["ID"].Value);
                    strNodeX = Convert.ToString(selectedRow.Cells["Message"].Value);
                    strNodeX = strNodeX.Substring(0, 20);
                }
            }
            catch { }

            //try { strNodeX = listBoxPosts.SelectedItem.ToString();  }
            //catch { }

            graph.AddEdge(strNode1, strNode2);
            graph.AddEdge(strNode1, strNode3);
            graph.AddEdge(strNode1, strNode4);
            graph.AddEdge(strNode1, strNode5);


            for (int Count = 0; Count < listBoxPages.Items.Count; Count++)
            {
                graph.AddEdge(strNode2, listBoxPages.Items[Count].ToString());
            }


            for (int Count = 0; Count < dgvPosts.Rows.Count; Count++)
            {
                try
                {
                    graph.AddEdge(strNode3, dgvPosts[1, Count].Value.ToString().Substring(0, 20));
                }
                catch { }
            }

            for (int Count = 0; Count < listBoxMovies.Items.Count; Count++)
            {
                graph.AddEdge(strNode4, listBoxMovies.Items[Count].ToString());
            }
            for (int Count = 0; Count < listBoxBooks.Items.Count; Count++)
            {
                graph.AddEdge(strNode5, listBoxBooks.Items[Count].ToString());
            }

            graph.AddEdge(strNodeX, strNodeLike);
            for (int Count = 0; Count < 5; ++Count)
            {
                graph.AddEdge(strNodeLike, lbPostLikeByUsers.Items[Count].ToString());
            }
            //bind the graph to the viewer
            viewer.Graph = graph;

            //associate the viewer with the form
            //Form2.SuspendLayout();
            viewer.Width = 1000;
            viewer.ZoomF = 4;
            this.SuspendLayout();
            viewer.Dock = System.Windows.Forms.DockStyle.Fill;
            viewer.Dock = tabPage2.Dock;
            tabPage2.Controls.Add(viewer);
            this.ResumeLayout();

            //show the form
            // this.ShowDialog();
        }
Exemplo n.º 17
0
        // ketika isi dari listBox diklik dan mengalami perubahan indeks
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            // jika input secara langsung, bukan file eksternal
            if (_direct)
            {
                // ambil indeks item list
                int      idx         = listBox1.SelectedIndex;
                string[] passed_path = _arrPath[idx].Split(' ');
                bool     found       = false;

                // membangun objek graf
                Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("graph");

                // membuat isi graf
                int      numberOfNodes = Convert.ToInt32(richTextBox1.Lines[0]);
                string[] edge;
                for (int i = 1; i < numberOfNodes; i++)
                {
                    edge = richTextBox1.Lines[i].Split(' ');
                    graph.AddEdge(edge[0], edge[1]);
                    Node node = graph.FindNode(edge[0]);
                    // mencari node yang ada pada path yang ditemukan
                    for (int j = 0; j < passed_path.Length; j++)
                    {
                        if (passed_path[j] == edge[0])
                        {
                            found = true;
                        }
                    }
                    if (found)
                    {
                        // ubah tampilan node yang ditemukan untuk menandakan jalur
                        node.Attr.Shape     = Microsoft.Glee.Drawing.Shape.Diamond;
                        node.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Yellow;
                        found = false;
                    }
                    else
                    {
                        // seperti bentuk node pada graf awal
                        node.Attr.Shape = Microsoft.Glee.Drawing.Shape.Circle;
                    }
                    node = graph.FindNode(edge[1]);

                    // mencari node yang ada pada path yang ditemukan
                    for (int j = 0; j < passed_path.Length; j++)
                    {
                        if (passed_path[j] == edge[1])
                        {
                            found = true;
                        }
                    }
                    if (found)
                    {
                        // ubah tampilan node yang ditemukan untuk menandakan jalur
                        node.Attr.Shape     = Microsoft.Glee.Drawing.Shape.Diamond;
                        node.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Yellow;
                        found = false;
                    }
                    else
                    {
                        // seperti bentuk node pada graf awal
                        node.Attr.Shape = Microsoft.Glee.Drawing.Shape.Circle;
                    }
                    graph.GraphAttr.EdgeAttr.ArrowHeadAtTarget = ArrowStyle.None;
                }
                ;
                // masukkan graf ke dalam viewer
                gViewer1.Graph = graph;
            }
            else // jika input dari file eksternal
            {
                // ambil indeks item list
                int      idx         = listBox1.SelectedIndex - 1;
                string[] passed_path = _arrPath[idx].Split(' ');
                bool     found       = false;

                // membangun objek graf
                Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("graph");

                // membuat isi graf
                int      numberOfNodes = Convert.ToInt32(richTextBox1.Lines[0]);
                string[] edge;
                for (int i = 1; i < numberOfNodes; i++)
                {
                    edge = richTextBox1.Lines[i].Split(' ');
                    graph.AddEdge(edge[0], edge[1]);
                    Node node = graph.FindNode(edge[0]);
                    // mencari node yang ada pada path yang ditemukan
                    for (int j = 0; j < passed_path.Length; j++)
                    {
                        if (passed_path[j] == edge[0])
                        {
                            found = true;
                        }
                    }
                    if (found)
                    {
                        // ubah tampilan node yang ditemukan untuk menandakan jalur
                        node.Attr.Shape     = Microsoft.Glee.Drawing.Shape.Diamond;
                        node.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Yellow;
                        found = false;
                    }
                    else
                    {
                        // seperti bentuk node pada graf awal
                        node.Attr.Shape = Microsoft.Glee.Drawing.Shape.Circle;
                    }
                    node = graph.FindNode(edge[1]);
                    for (int j = 0; j < passed_path.Length; j++)
                    {
                        if (passed_path[j] == edge[1])
                        {
                            found = true;
                        }
                    }
                    if (found)
                    {
                        // ubah tampilan node yang ditemukan untuk menandakan jalu
                        node.Attr.Shape     = Microsoft.Glee.Drawing.Shape.Diamond;
                        node.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Yellow;
                        found = false;
                    }
                    else
                    {
                        // seperti bentuk node pada graf awal
                        node.Attr.Shape = Microsoft.Glee.Drawing.Shape.Circle;
                    }
                    graph.GraphAttr.EdgeAttr.ArrowHeadAtTarget = ArrowStyle.None;
                }
                ;
                // memasukkan graf ke dalam viewer
                gViewer1.Graph = graph;
            }
        }
Exemplo n.º 18
0
        private void BuildGraph()
        {
            // The only way I can see to do this is to create another graph, and
            // copy what we want to the new graph, which is slow. Grim, we need
            // to rebuild addedNodes and edges as well.

            // Considering options, it's easier to do this each time anyway,
            // and don't build the initial graph at all. TODO, split this.

            GD.Graph newGraph = CreateGraph();
            Dictionary <string, object>         newAddedNodes = new Dictionary <string, object>();
            Dictionary <string, List <object> > newAddedEdges = new Dictionary <string, List <object> >();

            newGraph.GraphAttr.AspectRatio = _options.AspectRatio;
            newGraph.GraphAttr.NodeSep     = _options.NodeSep;

            foreach (KeyValuePair <string, object> pair in _addedNodes)
            {
                GD.Node node = pair.Value as GD.Node;

                if (!_options.ShowOrphans && !_notOrphans.ContainsKey(pair.Key))
                {
                    continue;
                }

                GD.Node newNode = newGraph.AddNode(node.Id);
                newNode.Attr             = node.Attr.Clone();
                newNode.Attr.LabelMargin = _options.TextSpacing;
                newNode.Attr.Fontsize    = _options.FontSize;

                newNode.UserData = node.UserData;
                newAddedNodes.Add(node.Id, newNode);
            }

            foreach (KeyValuePair <string, List <object> > pair in _addedEdges)
            {
                if (pair.Value.Count == 0)
                {
                    return;
                }

                string idFrom = (pair.Value[0] as GD.Edge).Source;
                string idTo   = (pair.Value[0] as GD.Edge).Target;

                if (_options.MultipleEdges)
                {
                    int count = _addedEdges[pair.Key].Count;

                    // Perhaps thicken edges.
                    if (_options.ThickenEdges)
                    {
                        // Interesting, but any greater than 2 looks bad.
                        int thickness = 1;
                        if (count > 1)
                        {
                            thickness = 2;
                        }

                        // Create a thickened edge. Take the properties of the first one.
                        GD.Edge edge    = pair.Value[0] as GD.Edge;
                        GD.Edge newEdge = newGraph.AddEdge(idFrom, idTo);
                        newEdge.Attr           = edge.Attr.Clone();
                        newEdge.Attr.LineWidth = thickness;
                        newAddedEdges.Add(pair.Key, new List <object>()
                        {
                            newEdge
                        });
                    }
                    else
                    {
                        // Show multiple edges.
                        newAddedEdges.Add(pair.Key, new List <object>());
                        foreach (GD.Edge edge in pair.Value)
                        {
                            GD.Edge newEdge = newGraph.AddEdge(idFrom, idTo);
                            newEdge.Attr = edge.Attr.Clone();
                            newAddedEdges[pair.Key].Add(newEdge);
                        }
                    }
                }
                else
                {
                    // Show single edges. Take the properties of the first one.
                    GD.Edge edge    = pair.Value[0] as GD.Edge;
                    GD.Edge newEdge = newGraph.AddEdge(idFrom, idTo);
                    newEdge.Attr = edge.Attr.Clone();
                    newAddedEdges.Add(pair.Key, new List <object> {
                        newEdge
                    });
                }
            }

            _hasOrphans = _notOrphans.Count < _addedNodes.Count;

            _graph      = newGraph;
            _addedEdges = newAddedEdges;
            _addedNodes = newAddedNodes;
        }
Exemplo n.º 19
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.º 20
0
        //отрисовка графа
        private void DrawGraph(int currentTop)
        {
            this.GraphPanel.Controls.Clear();
            Microsoft.Glee.GraphViewerGdi.GViewer viewer = new Microsoft.Glee.GraphViewerGdi.GViewer();
            viewer.AsyncLayout = false;
            viewer.AutoScroll = true;
            nodes = new string[nodesCount];
            for (int i = 0; i < nodesCount; ++i)
            {
                nodes[i] = (i + 1).ToString();
            }

            graph = new Microsoft.Glee.Drawing.Graph("Graph");
            for (int i = 0; i < nodesCount; ++i)
            {
                for (int j = 0; j < nodesCount; ++j)
                {
                    if (adjancyMatrix[i, j] != 0)
                    {
                        graph.AddEdge(nodes[i], ""/*adjancyMatrix[i, j].ToString()*/, nodes[j]);
                    }
                }
            }
            for (int i = 0; i < nodesCount; ++i)
            {
                Microsoft.Glee.Drawing.Node currentNode = graph.FindNode(nodes[i]);
                if (i == currentTop)
                {
                    currentNode.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Green;
                }
                else
                {
                    currentNode.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Yellow;
                }
                currentNode.Attr.Shape = Microsoft.Glee.Drawing.Shape.DoubleCircle;
            }
            Microsoft.Glee.GraphViewerGdi.GraphRenderer renderer = new Microsoft.Glee.GraphViewerGdi.GraphRenderer(graph);
            viewer.Graph = graph;
            this.GraphPanel.SuspendLayout();
            viewer.Dock = System.Windows.Forms.DockStyle.Fill;
            this.GraphPanel.Controls.Add(viewer);
            this.GraphPanel.ResumeLayout();

            //Bitmap graphImage = new Bitmap(GraphPanel.Width, GraphPanel.Height);
            //renderer.Render(graphImage);
            //GraphPanel.Image = graphImage;
        }