public static List <string> PrintAllPoints(DekstraAlgorim da) { List <string> retListOfPoints = new List <string>(); foreach (Vertex p in da.vertexList) { retListOfPoints.Add(string.Format("point name={0}, point value={1}, predok={2}", p.Name, p.PathLength, p.PrevVertex.Name ?? "нет предка")); } return(retListOfPoints); }
public static List <string> PrintAllMinPaths(DekstraAlgorim da) { List <string> retListOfPointsAndPaths = new List <string>(); foreach (Vertex p in da.vertexList) { if (p != da.beginVertex) { string s = string.Empty; foreach (Vertex p1 in da.MinPath(p)) { s += string.Format("{0} ", p1.Name); } retListOfPointsAndPaths.Add(string.Format("Point ={0}: \n Minimal Path to {1} = {2}", p.Name, da.beginVertex.Name, s)); } } return(retListOfPointsAndPaths); }
private void OK_ModalAlgoritms_Click(object sender, RoutedEventArgs e) { Hider.Visibility = Visibility.Hidden; ModalAlgoritms.Visibility = Visibility.Hidden; if (radio_deikstra.IsChecked == true) { DeffaultColorBridge(); ConsoleDeikstra.Text = "Result of Algorithm Deikstra"; DrawingController.CurrentStorage.VertexList[0].PathLength = 0; DekstraAlgorim da = new DekstraAlgorim(DrawingController.CurrentStorage.VertexList, DrawingController.CurrentStorage.EdgeList); da.AlgoritmRun(DrawingController.CurrentStorage.VertexList[0]); List <string> b = PrintGrath.PrintAllMinPaths(da); for (int i = 0; i < b.Count; i++) { ConsoleDeikstra.Text += b[i] + Environment.NewLine; } } if (radio_deep.IsChecked == true) { DeffaultColorBridge(); // Выполняем алгоримт поиска в глубину ConsoleDeikstra.Text = string.Empty; DeepSearchAlgorithm da = new DeepSearchAlgorithm(DrawingController.CurrentStorage.VertexList, DrawingController.CurrentStorage.EdgeList); ConsoleDeikstra.Text = "Result of Algorithm Deep Search \n" + da.Begin_Search(); // Окрашиваем пройденные вершины foreach (EdgeBag l in DrawingController.CurrentStorage.BindingBridgeWithAlgoEdge) { foreach (Edge ed in da.ResultListEdges) { if (IsOrientedGraph) { if ((l.DataEdge.FirstPoint == ed.FirstPoint && l.DataEdge.SecondPoint == ed.SecondPoint) || (l.DataEdge.FirstPoint == ed.SecondPoint && l.DataEdge.SecondPoint == ed.FirstPoint)) { foreach (var x in DrawAreaCanvas.Children) { if (l.GraphicEdge == x) { ((Line)x).Stroke = Brushes.Blue; } } } } else { if (l.DataEdge.FirstPoint == ed.FirstPoint && l.DataEdge.SecondPoint == ed.SecondPoint) { foreach (var x in DrawAreaCanvas.Children) { if (l.GraphicEdge == x) { ((Line)x).Stroke = Brushes.Blue; } } } } } } } if (radio_prim.IsChecked == true) { DeffaultColorBridge(); AlgorithmPrima ap = new AlgorithmPrima(DrawingController.CurrentStorage.VertexList, DrawingController.CurrentStorage.EdgeList, DrawingController.CurrentStorage.VertexList[0]); ap.algorithmByPrim(); foreach (EdgeBag l in DrawingController.CurrentStorage.BindingBridgeWithAlgoEdge) { foreach (Edge edge in ap.MSTRezult) { if (l.DataEdge.FirstPoint == edge.FirstPoint && l.DataEdge.SecondPoint == edge.SecondPoint) { foreach (var x in DrawAreaCanvas.Children) { if (l.GraphicEdge == x) { ((Line)x).Stroke = Brushes.DarkSeaGreen; } } } } } ConsoleDeikstra.Text = "Result of Algorithm Prima" + Environment.NewLine; foreach (Edge x in ap.MSTRezult) { ConsoleDeikstra.Text += "From " + x.FirstPoint.Name + " To " + x.SecondPoint.Name + Environment.NewLine; } } }