//browse private void button1_Click(object sender, EventArgs e) { comboBox2.Items.Clear(); comboBox3.Items.Clear(); //string directory; Microsoft.Msagl.Drawing.Graph grafVisualization = new Microsoft.Msagl.Drawing.Graph("graf"); browse.Filter = "*.txt (file berekstensi txt) | *.txt"; if (browse.ShowDialog() == DialogResult.OK) { int i; string fileDirectory = browse.FileName; string filename = browse.SafeFileName; input = File.ReadAllLines(fileDirectory); label4.Text = filename; graf = new Graf(input); //menambahkan simpul simpul pada comboBox for (i = 1; i <= graf.getGraphNode().Count; i++) { comboBox2.Items.Add(graf.getGraphNode()[i - 1].getNamaNode()); comboBox3.Items.Add(graf.getGraphNode()[i - 1].getNamaNode()); } //visualisasi graf awal grafVisualization = FrontEndUtility.grafVisualization(graf); gViewer1.Graph = grafVisualization; } }
//Memvisualisasikan graf hasil public static Microsoft.Msagl.Drawing.Graph colorizedGrafVisualization(Graf graf, List <Edge> rute) { int i; Microsoft.Msagl.Drawing.Graph grafVisualization = new Microsoft.Msagl.Drawing.Graph("graf"); int N = graf.getGraphNode().Count; Graf frontEndGraph = FrontEndUtility.deletedDuplicatedEdgesGraph(graf, graf.getGraphNode().Count); foreach (Node node in frontEndGraph.getGraphNode()) { if (node.getEdges().Count == 0) { grafVisualization.AddNode(node.getNamaNode()); } foreach (Edge edge in node.getEdges()) { double roundedBobot = Math.Round(edge.getBobot() * 100000, 2); var garis = grafVisualization.AddEdge(edge.getNode().getNamaNode(), roundedBobot.ToString(), edge.getNext().getNamaNode()); garis.Attr.ArrowheadAtTarget = Microsoft.Msagl.Drawing.ArrowStyle.None; garis.Attr.ArrowheadAtSource = Microsoft.Msagl.Drawing.ArrowStyle.None; for (i = 0; i < rute.Count; i++) { bool edgeFirstCheck = rute[i].getNode().getNamaNode() == edge.getNode().getNamaNode() && rute[i].getNext().getNamaNode() == edge.getNext().getNamaNode(); bool edgeSecondCheck = rute[i].getNode().getNamaNode() == edge.getNext().getNamaNode() && rute[i].getNext().getNamaNode() == edge.getNode().getNamaNode(); if (edgeFirstCheck || edgeSecondCheck) { garis.Attr.Color = Microsoft.Msagl.Drawing.Color.Blue; if (i == 0) { grafVisualization.FindNode(rute[i].getNode().getNamaNode()).Attr.FillColor = Microsoft.Msagl.Drawing.Color.LightBlue; grafVisualization.FindNode(rute[i].getNext().getNamaNode()).Attr.FillColor = Microsoft.Msagl.Drawing.Color.LightGreen; } else if (i == rute.Count - 1) { grafVisualization.FindNode(rute[i].getNode().getNamaNode()).Attr.FillColor = Microsoft.Msagl.Drawing.Color.Turquoise; grafVisualization.FindNode(rute[i].getNext().getNamaNode()).Attr.FillColor = Microsoft.Msagl.Drawing.Color.LightGreen; } else { grafVisualization.FindNode(rute[i].getNode().getNamaNode()).Attr.FillColor = Microsoft.Msagl.Drawing.Color.Turquoise; grafVisualization.FindNode(rute[i].getNext().getNamaNode()).Attr.FillColor = Microsoft.Msagl.Drawing.Color.Turquoise; } } } } } return(grafVisualization); }
//Menghapus edge duplikat pada frontend public static Graf deletedDuplicatedEdgesGraph(Graf graf, int N) { List <Edge> noDuplicateEdges = new List <Edge>(); List <Node> newNodes = new List <Node>(); Graf newGraph = new Graf(N); foreach (Node node in graf.getGraphNode()) { List <Edge> newEdges = new List <Edge>(); foreach (Edge edge in node.getEdges()) { string namaNodeTestedEdge = edge.getNode().getNamaNode(); string namaNextNodeTestedEdge = edge.getNext().getNamaNode(); bool exist = noDuplicateEdges.Any(x => x.getNode().getNamaNode() == namaNextNodeTestedEdge && x.getNext().getNamaNode() == namaNodeTestedEdge); if (!exist) { noDuplicateEdges.Add(edge); newEdges.Add(edge); } } Node newNode = new Node(node.getNamaNode(), node.getKoordinatNode()); newNode.setEdges(newEdges); newNodes.Add(newNode); } newGraph.setListNodes(newNodes); return(newGraph); }
//Memvisualisasikan graf awal public static Microsoft.Msagl.Drawing.Graph grafVisualization(Graf graf) { Microsoft.Msagl.Drawing.Graph grafVisualization = new Microsoft.Msagl.Drawing.Graph("graf"); int N = graf.getGraphNode().Count; //gViewer1.Controls.Clear(); Graf frontEndGraph = FrontEndUtility.deletedDuplicatedEdgesGraph(graf, graf.getGraphNode().Count); foreach (Node node in frontEndGraph.getGraphNode()) { if (node.getEdges().Count == 0) { grafVisualization.AddNode(node.getNamaNode()); } foreach (Edge edge in node.getEdges()) { double roundedBobot = Math.Round(edge.getBobot() * 100000, 2); var garis = grafVisualization.AddEdge(edge.getNode().getNamaNode(), roundedBobot.ToString(), edge.getNext().getNamaNode()); garis.Attr.ArrowheadAtTarget = Microsoft.Msagl.Drawing.ArrowStyle.None; garis.Attr.ArrowheadAtSource = Microsoft.Msagl.Drawing.ArrowStyle.None; } } return(grafVisualization); }