// 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 void warnaiGraph() { for (int i = 0; i < countPath; i++) { string temp = pathArr[i].ToString(); graph.FindNode(temp).Attr.Fillcolor = Microsoft.Glee.Drawing.Color.OrangeRed; } }
private void button1_Click(object sender, EventArgs e) { //Ini adalah tomboll trigger untuk memanggil animasi dan algoritma dfs //Inisiasi button2.Enabled = true; button3.Enabled = true; DFS_Sort algoritmaDFS = new DFS_Sort(resultGraph.getSize()); //Mulai melakukan dfs int time = 1; for (int i = 0; i < resultGraph.getSize(); i++) { if (!algoritmaDFS.isVerticeVisited(i)) { algoritmaDFS.Search(resultGraph, i, ref time); } } algoritmaDFS.makeSolution(); //Melakukan animasi dfs dengan memanfaatkan track record for (int i = 0; i < algoritmaDFS.getOrderCount(); i++) { bool isEnd = algoritmaDFS.isVerticeOrderEnd(i); int currentNode = algoritmaDFS.getVerticeOrder(i); Node currentNodeObject = graph.FindNode(pemetaanIndex[currentNode]); if (!isEnd) { //Update time stamp selfEdge[currentNode].Attr.Label = (i + 1).ToString() + "/"; currentNodeObject.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Yellow; } else { selfEdge[currentNode].Attr.Label = selfEdge[currentNode].Attr.Label + (i + 1).ToString(); } if (i != 0) { int previousNode = algoritmaDFS.getVerticeOrder(i - 1); Node previousNodeObject = graph.FindNode(pemetaanIndex[previousNode]); previousNodeObject.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Red; } //Melakukan update gambar viewer.Graph = graph; viewer.Update(); System.Threading.Thread.Sleep(waktuDelay); } //Menyimpan solusi solution = algoritmaDFS.getAllSolution(); //form.ShowDialog(); }
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); }
// Uncolor Graph: public static void resetGraph() { for (int i = 0; i < Path.Count; i++) { // COLOR THE NODES TRAVERSED IN RED if (Path[i].ToString() == "1") { Microsoft.Glee.Drawing.Node n = defaultG.FindNode(Path[i].ToString()); n.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.SeaGreen; } else { Microsoft.Glee.Drawing.Node n = defaultG.FindNode(Path[i].ToString()); n.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.White; } } }
public static void printCalcDistance(int[][] graphMatrix, int numberOfVertex, int[] distance, int minNode, Microsoft.Glee.Drawing.Graph graph1) { //create a graph object Microsoft.Glee.Drawing.Graph graph = graph1; Node n1 = graph.FindNode("Node" + (minNode + 1)); foreach (var i in n1.OutEdges) { i.EdgeAttr.Color = Microsoft.Glee.Drawing.Color.Green; i.EdgeAttr.Fontcolor = Microsoft.Glee.Drawing.Color.Green; } for (int i = 0; i < numberOfVertex; i++) { Node n = graph.FindNode("Node" + (i + 1)); if (distance[i] != Int32.MaxValue) { n.Attr.Label += "->\n(" + distance[i].ToString() + ")"; } } //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(); }
public static Microsoft.Glee.Drawing.Graph printMstMinNode(int[][] graphMatrix, int numberOfVertex, int minNode, int[] parent, Microsoft.Glee.Drawing.Graph graph1) { //create a graph object // Microsoft.Glee.Drawing.Graph graph = graph1; Node n1 = tempGraph.FindNode("Node" + (minNode + 1)); //n1.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Red; n1.Attr.Color = Microsoft.Glee.Drawing.Color.Red; if (minNode != 0) { Node n0 = tempGraph.FindNode("Node" + (parent[minNode] + 1)); foreach (Edge e in n0.OutEdges) { if (e.TargetNode == n1) { e.EdgeAttr.Color = Microsoft.Glee.Drawing.Color.Red; } } } //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); }
//отрисовка графа 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; }
// FUNCTION TO DO LOAD GRAPH AND RUN DFS: public static void runDFS(Form1 f1) { defaultG = new Graph("graph"); if (graphForm.IsDisposed) { Console.WriteLine(graphForm == null); graphForm = new Form(); viewer = new Microsoft.Glee.GraphViewerGdi.GViewer(); } StreamReader sr = new StreamReader(@f1.getFileURL()); string Rumah = sr.ReadLine(); jmlRumah = Int32.Parse(Rumah); buildTree(ref sr, jmlRumah); // DFS arrive = new long[jmlRumah + 1]; leave = new long[jmlRumah + 1]; visited = new bool[jmlRumah + 1]; DFS(1, ref tree); // COLOR THE ROOT (1) WITH SEAGREEN COLOR Microsoft.Glee.Drawing.Node n1 = defaultG.FindNode("1"); n1.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.SeaGreen; // Make Root a double-circled vertex just for emphasis, hehe: n1.Attr.Shape = Microsoft.Glee.Drawing.Shape.DoubleCircle; // SHOWING THE GRAPH: // Bind the graph to the viewer viewer.Graph = defaultG; // Associate the viewer with the created form graphForm.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; graphForm.Controls.Add(viewer); graphForm.ResumeLayout(); graphForm.Refresh(); // Show the form as a new window, BUT not locked there! graphForm.Show(); }
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(); }
// 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; } }
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(); }
//отрисовка графа 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; }