public void resetGraph() // Mengembalikan graf ke wujud awal saat dibentuk { for (int i = 1; i < map.getHouses(); i++) { for (int j = 0; j < map.getPath(i).Count(); j++) { string str1 = i.ToString(); string str2 = map.getPath(i)[j].ToString(); graph.FindNode(str1).Attr.FillColor = Microsoft.Msagl.Drawing.Color.White; graph.FindNode(str2).Attr.FillColor = Microsoft.Msagl.Drawing.Color.White; } } }
private void Load_Graph_Click(object sender, RoutedEventArgs e) // Membuat graf satu arah dari file peta yang sudah diload sebelumnya { try { map = new Graf(dirGraph); Enter_Query.IsEnabled = true; Open_Query.IsEnabled = true; Next.IsEnabled = false; this.gViewer.Graph = null; graph = new Msagl.Graph("graph"); for (int i = map.getHouses() - 1; i > 0; i--) { for (int j = map.getPath(i).Count() - 1; j >= 0; j--) { string str1 = i.ToString(); string str2 = map.getPath(i)[j].ToString(); graph.AddEdge(str1, str2).Attr.ArrowheadAtTarget = Msagl.ArrowStyle.None; Microsoft.Msagl.Drawing.Node from = graph.FindNode(str1); Microsoft.Msagl.Drawing.Node to = graph.FindNode(str2); from.Attr.FillColor = Microsoft.Msagl.Drawing.Color.White; from.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Circle; to.Attr.FillColor = Microsoft.Msagl.Drawing.Color.White; to.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Circle; } } this.gViewer.Graph = graph; } catch { MessageBox.Show(" Error Code 0x05021999\n File Input Error", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public void recurseSolve(int curr, int target, ref bool found, Graf path, ref List <int> result) // Algoritma pencarian menggunakan DFS { List <int> neighbor = path.getPath(curr); if (curr == target) { found = true; now = target; checker = 0; _timer.Start(); result.Add(target); if (result.Count() != 0) { nowpath = result[0].ToString(); } else { nowpath = ""; } for (int j = 1; j < result.Count(); j++) { nowpath += " -> " + result[j]; } AutoClosingMessageBox.Show(nowpath, "Path", 1000); } else if (neighbor == null) { found = false; prev = curr; checker = 0; _timer2.Start(); result.Remove(curr); if (result.Count() != 0) { prevpath = result[0].ToString(); } else { prevpath = ""; } for (int j = 1; j < result.Count(); j++) { prevpath += " -> " + result[j]; } AutoClosingMessageBox.Show(prevpath, "Path", 1000); } else { now = curr; checker = 0; _timer.Start(); result.Add(curr); if (result.Count() != 0) { nowpath = result[0].ToString(); } else { nowpath = ""; } for (int j = 1; j < result.Count(); j++) { nowpath += " -> " + result[j]; } AutoClosingMessageBox.Show(nowpath, "Path", 1000); int i = 0; while ((i < neighbor.Count) && (!found)) { recurseSolve(neighbor[i], target, ref found, path, ref result); i++; } if (!found) { prev = curr; checker = 0; _timer2.Start(); result.Remove(curr); if (result.Count() != 0) { prevpath = result[0].ToString(); } else { prevpath = ""; } for (int j = 1; j < result.Count(); j++) { prevpath += " -> " + result[j]; } AutoClosingMessageBox.Show(prevpath, "Path", 1000); } } }