示例#1
0
        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));
        }
示例#2
0
        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);
            }
        }