Пример #1
0
        static public LocationGraph GenerateRouteGraph(String startName, LocationValue startLocation, String endName, LocationValue endLocation, List <WaypointRoute> routes)
        {
            LocationGraph result = new LocationGraph();

            double distanceThreshold = 1.0;

            //List<String> routeNames = new List<string>(this.Keys);
            String name;

            for (int i = 0; i < routes.Count; i++)
            {
                name = routes[i].Name;
                WaypointRoute route = routes[i];
                LocationGraph.LocationNode lastNode = null;
                foreach (Waypoint wp in route)
                {
                    LocationGraph.LocationNode node = new LocationGraph.LocationNode(wp.Name, wp.Location);
                    result.AddNode(node);
                    if (lastNode != null)
                    {
                        result.BiConnect(lastNode, node);
                    }
                    lastNode = node;
                }

                if (i > 0)
                {
                    WaypointRoute lastRoute = routes[i - 1];
                    Boolean       done      = false;
                    for (int j = 1; j < lastRoute.Count; j++)
                    {
                        if (done)
                        {
                            break;
                        }
                        for (int k = 1; k < route.Count; k++)
                        {
                            if (done)
                            {
                                break;
                            }
                            Waypoint      lastRouteP1 = lastRoute[j - 1];
                            Waypoint      lastRouteP2 = lastRoute[j];
                            Waypoint      nextRouteP1 = route[k - 1];
                            Waypoint      nextRouteP2 = route[k];
                            LocationValue intersect   = BehaviorHelper.LineIntersect(lastRouteP1.Location, lastRouteP2.Location,
                                                                                     nextRouteP1.Location, nextRouteP2.Location);

                            /*if (intersect != null)
                             * {
                             *  string newName = String.Format("Intersection_{0}_{1}_{2}_{3}", lastRouteP1.Name, lastRouteP2.Name, nextRouteP1.Name, nextRouteP2.Name);
                             *  LocationGraph.LocationNode intersectNode = new LocationGraph.LocationNode(newName, intersect);
                             *  result.AddNode(intersectNode);
                             *  result.BiConnect(intersectNode.Name, lastRouteP1.Name);
                             *  result.BiConnect(intersectNode.Name, lastRouteP2.Name);
                             *  result.BiConnect(intersectNode.Name, nextRouteP1.Name);
                             *  result.BiConnect(intersectNode.Name, nextRouteP2.Name);
                             * }
                             * else*/
                            if (BehaviorHelper.Distance(lastRouteP1.Location, nextRouteP1.Location) < distanceThreshold)
                            {
                                result.BiConnect(lastRouteP1.Name, nextRouteP1.Name);
                                done = true;
                            }
                            else if (BehaviorHelper.Distance(lastRouteP1.Location, nextRouteP2.Location) < distanceThreshold)
                            {
                                result.BiConnect(lastRouteP1.Name, nextRouteP2.Name);
                                done = true;
                            }
                            else if (BehaviorHelper.Distance(lastRouteP2.Location, nextRouteP1.Location) < distanceThreshold)
                            {
                                result.BiConnect(lastRouteP2.Name, nextRouteP1.Name);
                                done = true;
                            }
                            else if (BehaviorHelper.Distance(lastRouteP2.Location, nextRouteP2.Location) < distanceThreshold)
                            {
                                result.BiConnect(lastRouteP2.Name, nextRouteP2.Name);
                                done = true;
                            }
                        }
                    }
                }
            }


            //result.ProximityConnect(10);
            //result.IntersectConnect();

            LocationNode startNode = new LocationNode(startName, startLocation);
            LocationNode endNode   = new LocationNode(endName, endLocation);

            result.InsertByProximity(startNode);
            result.InsertByProximity(endNode);

            return(result);
        }
Пример #2
0
        static public LocationGraph GenerateRouteGraph(String startName,LocationValue startLocation, String endName, LocationValue endLocation, List<WaypointRoute> routes)
        {
            LocationGraph result = new LocationGraph();

            double distanceThreshold = 1.0;

            //List<String> routeNames = new List<string>(this.Keys);
            String name;
            for (int i = 0; i < routes.Count; i++)
            {
                name = routes[i].Name;
                WaypointRoute route = routes[i];
                LocationGraph.LocationNode lastNode = null;
                foreach (Waypoint wp in route)
                {
                    LocationGraph.LocationNode node = new LocationGraph.LocationNode(wp.Name, wp.Location);
                    result.AddNode(node);
                    if (lastNode != null)
                    {
                        result.BiConnect(lastNode, node);
                    }
                    lastNode = node;
                }

                if (i > 0)
                {
                    WaypointRoute lastRoute = routes[i - 1];
                    Boolean done = false;
                    for (int j = 1; j < lastRoute.Count; j++)
                    {
                        if (done) break;
                        for (int k = 1; k < route.Count; k++)
                        {
                            if (done) break;
                            Waypoint lastRouteP1 = lastRoute[j - 1];
                            Waypoint lastRouteP2 = lastRoute[j];
                            Waypoint nextRouteP1 = route[k - 1];
                            Waypoint nextRouteP2 = route[k];
                            LocationValue intersect = BehaviorHelper.LineIntersect(lastRouteP1.Location, lastRouteP2.Location,
                                                                                   nextRouteP1.Location, nextRouteP2.Location);
                            /*if (intersect != null)
                            {
                                string newName = String.Format("Intersection_{0}_{1}_{2}_{3}", lastRouteP1.Name, lastRouteP2.Name, nextRouteP1.Name, nextRouteP2.Name);
                                LocationGraph.LocationNode intersectNode = new LocationGraph.LocationNode(newName, intersect);
                                result.AddNode(intersectNode);
                                result.BiConnect(intersectNode.Name, lastRouteP1.Name);
                                result.BiConnect(intersectNode.Name, lastRouteP2.Name);
                                result.BiConnect(intersectNode.Name, nextRouteP1.Name);
                                result.BiConnect(intersectNode.Name, nextRouteP2.Name);
                            }
                            else*/ 
                            if (BehaviorHelper.Distance(lastRouteP1.Location, nextRouteP1.Location) < distanceThreshold)
                            {
                                result.BiConnect(lastRouteP1.Name, nextRouteP1.Name);
                                done = true;
                            }
                            else if (BehaviorHelper.Distance(lastRouteP1.Location, nextRouteP2.Location) < distanceThreshold)
                            {
                                result.BiConnect(lastRouteP1.Name, nextRouteP2.Name);
                                done = true;
                            }
                            else if (BehaviorHelper.Distance(lastRouteP2.Location, nextRouteP1.Location) < distanceThreshold)
                            {
                                result.BiConnect(lastRouteP2.Name, nextRouteP1.Name);
                                done = true;
                            }
                            else if (BehaviorHelper.Distance(lastRouteP2.Location, nextRouteP2.Location) < distanceThreshold)
                            {
                                result.BiConnect(lastRouteP2.Name, nextRouteP2.Name);
                                done = true;
                            }
                        }
                    }
                }
            }
            

            //result.ProximityConnect(10);
            //result.IntersectConnect();

            LocationNode startNode = new LocationNode(startName, startLocation);
            LocationNode endNode = new LocationNode(endName, endLocation);

            result.InsertByProximity(startNode);
            result.InsertByProximity(endNode);

            return result;
        }