public void Form1_Load(object sender, EventArgs e) { 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]; string[] 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; } routing route = new routing(); route.MapMaker(ref map, nodes, 41, 41, 4, 55.041513, 82.916838); }
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); } }
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)); }