public void Form1_Load(object sender, EventArgs e) { drones = new Drones[3]; drones[0] = new Drones("Vulcan Black Widow", 500, 100, 5); drones[1] = new Drones("Vulcan Payload Development", 5000, 150, 5); drones[2] = new Drones("Vulcan Airlift", 1000, 150, 10); string[] drone = new string[3]; for (int i = 0; i < 3; i++) { drone[i] = drones[i].name; } LoadData loader = new LoadData(); string filepath = @"e:\data source\addressbook.map"; //addressbook file path string addressBook = null, routes = null; int numLines = loader.fileDecrypt(filepath, ref addressBook); nodes = new Graph[(numLines - 1) * 4]; object[] addresses = new string[numLines - 1]; loader.loadNodes(addressBook, numLines, ref nodes); filepath = @"e:\data source\routes.map"; //routes file path loader.fileDecrypt(filepath, ref routes); loader.loadRoutes(routes, ref nodes); //загрузка соседей в каждый нод for (int i = 0; i < numLines - 1; i++) { addresses[i] = nodes[i].street + " " + nodes[i].house; } comboBox2.Items.AddRange(addresses); comboBox1.Items.AddRange(drone); mapBrowser.Navigate("https://www.google.ru/maps/@55.0457912,82.9236788,16.91z"); routing route = new routing(); map = new Graph[41, 41, 4]; grid = new SquareGrid(41, 41, 4); route.MapMaker(ref map, nodes, 41, 41, 4, 55.041513, 82.916838); }
public double StraightLineDistanceTo(Graph end) { routing route = new routing(); return(route.Haversine(Point.X, end.Point.X, Point.Y, end.Point.Y, Point.Z, end.Point.Z)); }
public void loadRoutes(string file, ref Graph[] node) { string[] lines = file.Split( new[] { Environment.NewLine }, StringSplitOptions.None ); int linesNum = lines.Length - 1; for (int i = 0; i < linesNum; i++) { string[] words = lines[i].Split('\t'); int lineLength = 0; for (int j = 0; j < words.Length; j++) { if (words[j] != "") { lineLength++; } } int[] indexes = new int[lineLength]; for (int j = 0; j < lineLength; j++) { Int32.TryParse(words[j], out indexes[j]); } for (int j = 1; j < lineLength; j++) { //Rib edge = new Rib(); routing route = new routing(); node[indexes[0] - 1].neighbourhood.Add(node[indexes[j] - 1]); //edge.ConnectedNode = node[indexes[j] - 1]; //edge.Length = route.Haversine(node[indexes[0] - 1].latitude, node[indexes[j] - 1].latitude, node[indexes[0] - 1].longitude, node[indexes[j] - 1].longitude, node[indexes[0] - 1].altitude, node[indexes[j] - 1].altitude); //node[indexes[0] - 1].connections.Add(edge); } } for (int i = 0; i < node.Length / 4; i++) { for (int j = 0; j < node.Length / 4; j++) { //Rib edge = new Rib(); routing route = new routing(); if (j == i && j < (node.Length / 4 - 1)) { j++; } node[i + (node.Length / 4)].neighbourhood.Add(node[j + (node.Length / 4)]); node[i + (node.Length / 4) * 2].neighbourhood.Add(node[j + (node.Length / 4) * 2]); node[i + (node.Length / 4) * 3].neighbourhood.Add(node[j + (node.Length / 4) * 3]); /*edge.ConnectedNode = node[j + (node.Length / 4)]; * edge.Length = route.Haversine(node[i + (node.Length / 4)].latitude, node[j + (node.Length / 4)].latitude, node[i + (node.Length / 4)].longitude, node[j + (node.Length / 4)].longitude, node[i + (node.Length / 4)].altitude, node[j + (node.Length / 4)].altitude); * node[i + (node.Length / 4)].connections.Add(edge); * * edge.ConnectedNode = node[j + (node.Length / 4) * 2]; * edge.Length = route.Haversine(node[i + (node.Length / 4) * 2].latitude, node[j + (node.Length / 4 * 2)].latitude, node[i + (node.Length / 4 * 2)].longitude, node[j + (node.Length / 4 * 2)].longitude, node[i + (node.Length / 4 * 2)].altitude, node[j + (node.Length / 4 * 2)].altitude); * node[i + (node.Length / 4 * 2)].connections.Add(edge); * * edge.ConnectedNode = node[j + (node.Length / 4) * 3]; * edge.Length = route.Haversine(node[i + (node.Length / 4) * 3].latitude, node[j + (node.Length / 4 * 3)].latitude, node[i + (node.Length / 4 * 3)].longitude, node[j + (node.Length / 4 * 3)].longitude, node[i + (node.Length / 4 * 3)].altitude, node[j + (node.Length / 4 * 3)].altitude); * node[i + (node.Length / 4 * 3)].connections.Add(edge);*/ } } for (int i = 0; i < (node.Length / 4); i++) { //Rib edge = new Rib(); routing route = new routing(); node[i].neighbourhood.Add(node[i + (node.Length / 4)]); node[i + (node.Length / 4)].neighbourhood.Add(node[i]); node[i + (node.Length / 4)].neighbourhood.Add(node[i + (node.Length / 4) * 2]); node[i + (node.Length / 4) * 2].neighbourhood.Add(node[i + (node.Length / 4) * 3]); node[i + (node.Length / 4) * 2].neighbourhood.Add(node[i + (node.Length / 4)]); node[i + (node.Length / 4) * 3].neighbourhood.Add(node[i + (node.Length / 4) * 2]); ////0 //edge.ConnectedNode = node[i + (node.Length / 4)]; //edge.Length = route.Haversine(node[i].latitude, node[i + (node.Length / 4)].latitude, node[i].longitude, node[i + (node.Length / 4)].longitude, node[i].altitude, node[i + (node.Length / 4)].altitude); //node[i].connections.Add(edge); ////1 //edge.ConnectedNode = node[i]; //edge.Length = route.Haversine(node[i].latitude, node[i + (node.Length / 4)].latitude, node[i].longitude, node[i + (node.Length / 4)].longitude, node[i].altitude, node[i + (node.Length / 4)].altitude); //node[i + (node.Length / 4)].connections.Add(edge); //edge.ConnectedNode = node[+(node.Length / 4) * 2]; //edge.Length = route.Haversine(node[i + (node.Length / 4)].latitude, node[i + (node.Length / 4) * 2].latitude, node[i + (node.Length / 4)].longitude, node[i + (node.Length / 4) * 2].longitude, node[i + (node.Length / 4)].altitude, node[i + (node.Length / 4) * 2].altitude); //node[i + (node.Length / 4)].connections.Add(edge); ////2 //edge.ConnectedNode = node[+(node.Length / 4) * 3]; //edge.Length = route.Haversine(node[i + (node.Length / 4) * 2].latitude, node[i + (node.Length / 4) * 3].latitude, node[i + (node.Length / 4) * 2].longitude, node[i + (node.Length / 4) * 3].longitude, node[i + (node.Length / 4) * 2].altitude, node[i + (node.Length / 4) * 3].altitude); //node[i + (node.Length / 4) * 2].connections.Add(edge); //edge.ConnectedNode = node[+(node.Length / 4)]; //edge.Length = route.Haversine(node[i + (node.Length / 4) * 2].latitude, node[i + (node.Length / 4)].latitude, node[i + (node.Length / 4) * 2].longitude, node[i + (node.Length / 4)].longitude, node[i + (node.Length / 4) * 2].altitude, node[i + (node.Length / 4)].altitude); //node[i + (node.Length / 4) * 2].connections.Add(edge); ////3 //edge.ConnectedNode = node[+(node.Length / 4) * 2]; //edge.Length = route.Haversine(node[i + (node.Length / 4) * 2].latitude, node[i + (node.Length / 4) * 3].latitude, node[i + (node.Length / 4) * 2].longitude, node[i + (node.Length / 4) * 3].longitude, node[i + (node.Length / 4) * 2].altitude, node[i + (node.Length / 4) * 3].altitude); //node[i + (node.Length / 4) * 3].connections.Add(edge); } }
private void BFS_Click(object sender, EventArgs e) { routing path = new routing(); Graph search = new Graph(); Location[] route = new Location[pointsCount]; Graph[] links = new Graph[pointsCount]; if (comboBox1.Text == "") { MessageBox.Show("Please select drone"); return; } switch (pointsCount) { case 0: MessageBox.Show("Not enough checkpoints. Please add more points to the route"); return; case 1: route[0] = search.findNode(linkLabel1.Text, map, 41, 41, 4); break; case 2: route[0] = search.findNode(linkLabel1.Text, map, 41, 41, 4); route[1] = search.findNode(linkLabel2.Text, map, 41, 41, 4); break; case 3: route[0] = search.findNode(linkLabel1.Text, map, 41, 41, 4); route[1] = search.findNode(linkLabel2.Text, map, 41, 41, 4); route[2] = search.findNode(linkLabel3.Text, map, 41, 41, 4); break; } int selected; string unserviced = "Sorry, chosen addresses:\n"; bool unsrvcd = false; for (int i = 0; i < pointsCount; i++) { if (route[i].x < 0) { unserviced += points[i] + "\n"; unsrvcd = true; } } if (unsrvcd) { unserviced += "are yet to be added to our coverage"; MessageBox.Show(unserviced); return; } for (selected = 0; selected < 3; selected++) { if (comboBox1.Text == drones[selected].name) { break; } } NewGrid(41, 41, 4, route); //AStarSearch astar = new AStarSearch(grid, route[0], route[1]); //ThePath = astar.ReconstructPath(route[0], route[1], astar.cameFrom); BFSSearch bfs = new BFSSearch(grid, route[0], route[1]); ThePath = bfs.ReconstructPath(route[0], route[1], bfs.cameFrom); KML makefile = new KML(); makefile.NewKML(ThePath, map); }
public void loadRoutes(string file, ref Graph[] node) { string[] lines = file.Split( new[] { Environment.NewLine }, StringSplitOptions.None ); int linesNum = lines.Length - 1; for (int i = 0; i < linesNum; i++) { string[] words = lines[i].Split('\t'); int lineLength = 0; for (int j = 0; j < words.Length; j++) { if (words[j] != "") { lineLength++; } } int[] indexes = new int[lineLength]; for (int j = 0; j < lineLength; j++) { Int32.TryParse(words[j], out indexes[j]); } for (int j = 1; j < lineLength; j++) { Rib edge = new Rib(); routing route = new routing(); node[indexes[0] - 1].neighbourhood.Add(node[indexes[j] - 1]); edge.ConnectedNode = node[indexes[j] - 1]; edge.Length = route.Haversine(node[indexes[0] - 1].latitude, node[indexes[j] - 1].latitude, node[indexes[0] - 1].longitude, node[indexes[j] - 1].longitude, node[indexes[0] - 1].altitude, node[indexes[j] - 1].altitude); node[indexes[0] - 1].connections.Add(edge); //node[indexes[0] - 1 + node.Length / 4].neighbourhood.Add(node[indexes[j] - 1 + node.Length / 4]); //работает правильно, на на уровне 50 метров в данном квратале нет препятствий //node[indexes[0] - 1 + node.Length / 4 * 2].neighbourhood.Add(node[indexes[j] - 1 + node.Length / 4 * 2]); //node[indexes[0] - 1 + node.Length / 4 * 3].neighbourhood.Add(node[indexes[j] - 1 + node.Length / 4 * 3]); } } for (int i = 0; i < node.Length / 4; i++) { for (int j = 0; j < node.Length / 4; j++) { Rib edge = new Rib(); routing route = new routing(); if (j == i && j < (node.Length / 4 - 1)) { j++; } node[i + (node.Length / 4)].neighbourhood.Add(node[j + (node.Length / 4)]); node[i + (node.Length / 4) * 2].neighbourhood.Add(node[j + (node.Length / 4) * 2]); node[i + (node.Length / 4) * 3].neighbourhood.Add(node[j + (node.Length / 4) * 3]); edge.ConnectedNode = node[j + (node.Length / 4)]; edge.Length = route.Haversine(node[i + (node.Length / 4)].latitude, node[j + (node.Length / 4)].latitude, node[i + (node.Length / 4)].longitude, node[j + (node.Length / 4)].longitude, node[i + (node.Length / 4)].altitude, node[j + (node.Length / 4)].altitude); node[i + (node.Length / 4)].connections.Add(edge); edge.ConnectedNode = node[j + (node.Length / 4) * 2]; edge.Length = route.Haversine(node[i + (node.Length / 4) * 2].latitude, node[j + (node.Length / 4 * 2)].latitude, node[i + (node.Length / 4 * 2)].longitude, node[j + (node.Length / 4 * 2)].longitude, node[i + (node.Length / 4 * 2)].altitude, node[j + (node.Length / 4 * 2)].altitude); node[i + (node.Length / 4 * 2)].connections.Add(edge); edge.ConnectedNode = node[j + (node.Length / 4) * 3]; edge.Length = route.Haversine(node[i + (node.Length / 4) * 3].latitude, node[j + (node.Length / 4 * 3)].latitude, node[i + (node.Length / 4 * 3)].longitude, node[j + (node.Length / 4 * 3)].longitude, node[i + (node.Length / 4 * 3)].altitude, node[j + (node.Length / 4 * 3)].altitude); node[i + (node.Length / 4 * 3)].connections.Add(edge); } } for (int i = 0; i < (node.Length / 4); i++) { Rib edge = new Rib(); routing route = new routing(); node[i].neighbourhood.Add(node[i + (node.Length / 4)]); node[i + (node.Length / 4)].neighbourhood.Add(node[i]); node[i + (node.Length / 4)].neighbourhood.Add(node[i + (node.Length / 4) * 2]); node[i + (node.Length / 4) * 2].neighbourhood.Add(node[i + (node.Length / 4) * 3]); node[i + (node.Length / 4) * 2].neighbourhood.Add(node[i + (node.Length / 4)]); node[i + (node.Length / 4) * 3].neighbourhood.Add(node[i + (node.Length / 4) * 2]); //0 edge.ConnectedNode = node[i + (node.Length / 4)]; edge.Length = route.Haversine(node[i].latitude, node[i + (node.Length / 4)].latitude, node[i].longitude, node[i + (node.Length / 4)].longitude, node[i].altitude, node[i + (node.Length / 4)].altitude); node[i].connections.Add(edge); //1 edge.ConnectedNode = node[i]; edge.Length = route.Haversine(node[i].latitude, node[i + (node.Length / 4)].latitude, node[i].longitude, node[i + (node.Length / 4)].longitude, node[i].altitude, node[i + (node.Length / 4)].altitude); node[i + (node.Length / 4)].connections.Add(edge); edge.ConnectedNode = node[+(node.Length / 4) * 2]; edge.Length = route.Haversine(node[i + (node.Length / 4)].latitude, node[i + (node.Length / 4) * 2].latitude, node[i + (node.Length / 4)].longitude, node[i + (node.Length / 4) * 2].longitude, node[i + (node.Length / 4)].altitude, node[i + (node.Length / 4) * 2].altitude); node[i + (node.Length / 4)].connections.Add(edge); //2 edge.ConnectedNode = node[+(node.Length / 4) * 3]; edge.Length = route.Haversine(node[i + (node.Length / 4) * 2].latitude, node[i + (node.Length / 4) * 3].latitude, node[i + (node.Length / 4) * 2].longitude, node[i + (node.Length / 4) * 3].longitude, node[i + (node.Length / 4) * 2].altitude, node[i + (node.Length / 4) * 3].altitude); node[i + (node.Length / 4) * 2].connections.Add(edge); edge.ConnectedNode = node[+(node.Length / 4)]; edge.Length = route.Haversine(node[i + (node.Length / 4) * 2].latitude, node[i + (node.Length / 4)].latitude, node[i + (node.Length / 4) * 2].longitude, node[i + (node.Length / 4)].longitude, node[i + (node.Length / 4) * 2].altitude, node[i + (node.Length / 4)].altitude); node[i + (node.Length / 4) * 2].connections.Add(edge); //3 edge.ConnectedNode = node[+(node.Length / 4) * 2]; edge.Length = route.Haversine(node[i + (node.Length / 4) * 2].latitude, node[i + (node.Length / 4) * 3].latitude, node[i + (node.Length / 4) * 2].longitude, node[i + (node.Length / 4) * 3].longitude, node[i + (node.Length / 4) * 2].altitude, node[i + (node.Length / 4) * 3].altitude); node[i + (node.Length / 4) * 3].connections.Add(edge); } }