private void DrawPolygonOnBingMap(List <Node> route, Color color) { MapPolyline polygon = new MapPolyline(); polygon.Fill = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Transparent); polygon.Stroke = new System.Windows.Media.SolidColorBrush(color); polygon.StrokeThickness = 5; polygon.Opacity = 0.7; LocationCollection path = new LocationCollection(); for (int i = 0; i < route.Count - 2; i++) { if (alg.NodeDistancesDisjkstry[route.ElementAt(i).Position, route.ElementAt(i + 1).Position] == 0) { Dijkstry di = new Dijkstry(incidenceList); int[] pathSD = di.GetPath(route.ElementAt(i).Position, route.ElementAt(i + 1).Position); List <Node> dijkstryPath = new List <Node>(); if (pathSD != null) { //convert from int[] to List<Node> foreach (var p in pathSD) { foreach (var n in alg.NodesList) { if (n.Position == p) { dijkstryPath.Add(n); break; } } } foreach (var p in dijkstryPath) { path.Add(new Location(p.Y, p.X)); } } } else { path.Add(new Location(route.ElementAt(i).Y, route.ElementAt(i).X)); } } foreach (var node in route) { path.Add(new Location(node.Y, node.X)); } path.Add(path.ElementAt(0)); //i do punktu poczatkowego polygon.Locations = path; bingMap.Children.Add(polygon); }
//Dijkstry path private void MenuItem_Click_6(object sender, RoutedEventArgs e) { int SRC = 0; int DST = 0; DijkstryWindow dq = new DijkstryWindow(alg); dq.ShowDialog(); if (dq.DialogResult == true) { SRC = dq.FROM; DST = dq.TO; Dijkstry di = new Dijkstry(incidenceList); List <Node> dijkstryPath = new List <Node>(); int[] path = di.GetPath(SRC, DST); if (path != null) { //convert from int[] to List<Node> foreach (var p in path) { foreach (var n in alg.NodesList) { if (n.Position == p) { dijkstryPath.Add(n); break; } } } if (what == true) { canvas.Children.Clear(); DrawPoints(); DrawRoute(dijkstryPath, Brushes.Red); } else { DrawRouteOnBingMap(dijkstryPath, Colors.Red, true); } } else { MessageBox.Show("Niespójność danych, trasa nie istnieje", "Błąd danych wejściowych", MessageBoxButton.OK, MessageBoxImage.Error); } } }
private void LoadDataFromFile() { what = alg.LoadData(filePath); if (what) { incidenceList = Dijkstry.setIncidenceList(alg.numberOfNodes, alg.NodeDistances, alg.NodesList); } else if (!what) { incidenceList = Dijkstry.setIncidenceList(alg.numberOfNodes, alg.NodeDistances, alg.NodesList); //Dijkstry a; //for (int i = 0; i < alg.numberOfNodes - 1; i++) //{ // for (int j = 0; j < alg.numberOfNodes; j++) // { // if (alg.NodeDistances[i, j] == 0 && i != j) // { // if (j > 93) // { // } // a = new Dijkstry(incidenceList); // int[] tempPath = a.GetPath(i, j); // if (tempPath != null) // { // double distance = a.getPathDistance(); // alg.NodeDistances[i, j] = distance; // alg.NodeDistances[j, i] = distance; // } // else // { // alg.NodeDistances[i, j] = double.MaxValue; // alg.NodeDistances[j, i] = double.MaxValue; // } // } // } //} } alg.incidenceList = incidenceList; }
public List <Node> getDijkstryNodes(int src, int dst) { Dijkstry di = new Dijkstry(incidenceList); List <Node> dijkstryPath = new List <Node>(); int[] path = di.GetPath(src, dst); if (path != null) { //convert from int[] to List<Node> foreach (var p in path) { foreach (var n in NodesList) { if (n.Position == p) { dijkstryPath.Add(n); break; } } } } return(dijkstryPath); }