示例#1
0
        /// <summary>
        /// bt爆搜寻路(可搜折返),单向寻路,以进路为单位搜索
        /// </summary>
        /// <param name="Now"></param>
        /// <param name="res"></param>
        /// <param name="tempRoutes"></param>
        /// <param name="src"></param>
        /// <param name="tar"></param>
        /// <param name="k"></param>
        /// <param name="used"></param>
        void SearchSinglePath(ATSRoute Now, List <OptionalRoutes> res, OptionalRoutes tempRoutes, string tar, int k, HashSet <ATSRoute> routeUsed, RouteDirection routedir, int maxY, int minY)
        {
            if (k > deepth || res.Count > MaxResNum)
            {
                return;
            }
            foreach (var de in Now.InSections)
            {
                if (de.Name == tar)
                {
                    tempRoutes.UpdateDistance();
                    res.Add(new OptionalRoutes(tempRoutes));
                    return;
                }
            }

            foreach (var possibleRoute in Now.OptionalRoutes)
            {
                ATS.Signal signal = possibleRoute.StartSignal as ATS.Signal;
                double     y      = Canvas.GetTop(signal);
                if (possibleRoute.Dir == routedir && y >= minY && y <= maxY && !routeUsed.Contains(possibleRoute))
                //if (possibleRoute.Dir == routedir)
                {
                    tempRoutes.Routes.Add(possibleRoute);
                    routeUsed.Add(possibleRoute);
                    SearchSinglePath(tempRoutes.Routes.Last(), res, tempRoutes, tar, k + 1, routeUsed, routedir, maxY, minY);
                    tempRoutes.Routes.Remove(tempRoutes.Routes.Last());
                    routeUsed.Remove(possibleRoute);
                }
            }
        }
示例#2
0
 /// <summary>
 /// bt爆搜寻路
 /// </summary>
 /// <param name="Now"></param>
 /// <param name="res"></param>
 /// <param name="tempRoutes"></param>
 /// <param name="src"></param>
 /// <param name="tar"></param>
 /// <param name="k"></param>
 /// <param name="used"></param>
 void SearchPathBy(Device Now, List <OptionalRoutes> res, OptionalRoutes tempRoutes, string src, string tar, int k, HashSet <int> used, RouteDirection routedir)
 {
     if (k > deepth || res.Count > MaxResNum)
     {
         return;
     }
     if (Now.Name == tar)
     {
         tempRoutes.UpdateDistance();
         res.Add(new OptionalRoutes(tempRoutes));
     }
     else
     {
         List <ATSRoute> PossibleRoutes = Routes.FindAll((ATSRoute route) =>
         {
             foreach (Device d in route.IncomingSections)
             {
                 if (d.Name == Now.Name && !used.Contains(route.ID))
                 {
                     return(true);
                 }
             }
             return(false);
         });
         if (PossibleRoutes != null)
         {
             foreach (ATSRoute route in PossibleRoutes)
             {
                 if (route.Dir == routedir)
                 {
                     tempRoutes.Routes.Add(route);
                     used.Add(route.ID);
                     SearchPathBy(route.InSections.Last(), res, tempRoutes, src, tar, k + 1, used, routedir);
                     tempRoutes.Routes.Remove(tempRoutes.Routes.Last());
                     used.Remove(route.ID);
                 }
             }
         }
     }
 }
示例#3
0
        public void FindPathSD(string src1, string tar1, string src2, string tar2, RouteDirection dir, bool isReturn)
        {
            List <OptionalRoutes> res1 = new List <OptionalRoutes>();
            List <OptionalRoutes> res2 = new List <OptionalRoutes>();
            int             minY, maxY;
            List <ATSRoute> nowRoutes = Routes.FindAll((ATSRoute ar) =>
            {
                foreach (var de in ar.InSections)
                {
                    if (de.Name == src1)
                    {
                        return(true);
                    }
                }
                return(false);
            });

            List <ATSRoute> tarRoutes = Routes.FindAll((ATSRoute ar) =>
            {
                foreach (var de in ar.InSections)
                {
                    if (de.Name == tar1)
                    {
                        return(true);
                    }
                }
                //foreach (var de in ar.InCommingSections)
                //{
                //    if (de.Name == src1) return true;
                //}
                return(false);
            });

            double y1 = Canvas.GetTop(nowRoutes.First().StartSignal);
            double y2 = Canvas.GetTop(tarRoutes.First().StartSignal);

            maxY = (int)Math.Max(y1, y2) + Yoffset;
            minY = (int)Math.Min(y1, y2) - Yoffset;
            for (int i = 0; null != nowRoutes && i < nowRoutes.Count; i++)
            {
                SearchSinglePath(nowRoutes[i], res1, new OptionalRoutes(), tar1, 0, new HashSet <ATSRoute>(), dir, maxY, minY);
            }
            if (isReturn == false)
            {
                res1.Sort();
                this.Res = res1;
            }
            else
            {
                foreach (RouteDirection Dir in Enum.GetValues(typeof(RouteDirection)))
                {
                    if (dir != Dir)
                    {
                        dir = Dir;
                        break;
                    }
                }

                nowRoutes = Routes.FindAll((ATSRoute ar) =>
                {
                    foreach (var de in ar.InSections)
                    {
                        if (de.Name == src2)
                        {
                            return(true);
                        }
                    }
                    foreach (var de in ar.IncomingSections)
                    {
                        if (de.Name == src2)
                        {
                            return(true);
                        }
                    }
                    return(false);
                });
                tarRoutes = Routes.FindAll((ATSRoute ar) =>
                {
                    foreach (var de in ar.InSections)
                    {
                        if (de.Name == tar2)
                        {
                            return(true);
                        }
                    }
                    //foreach (var de in ar.InCommingSections)
                    //{
                    //    if (de.Name == src1) return true;
                    //}
                    return(false);
                });
                y1   = Canvas.GetTop(nowRoutes.First().StartSignal);
                y2   = Canvas.GetTop(tarRoutes.First().StartSignal);
                maxY = (int)Math.Max(y1, y2) + Yoffset;
                minY = (int)Math.Min(y1, y2) - Yoffset;
                for (int i = 0; null != nowRoutes && i < nowRoutes.Count; i++)
                {
                    OptionalRoutes tempRoutes = new OptionalRoutes();
                    tempRoutes.Routes.Add(nowRoutes[i]);
                    SearchSinglePath(nowRoutes[i], res2, tempRoutes, tar2, 0, new HashSet <ATSRoute>(), dir, maxY, minY);
                }
                int k1 = 0, k2 = 0, k = 0;
                res1.Sort();
                res2.Sort();
                while (res1 != null && res2 != null && k1 < res1.Count && k2 < res2.Count)
                {
                    res1[k1].Routes.AddRange(res2[k2].Routes);
                    res1[k1].Distance += res2[k2].Distance;
                    k1++;
                    k2++;
                }
                k                 = Math.Max(k1, k2);
                this.Res          = new List <OptionalRoutes>();
                this._RouteOpened = new HashSet <ATSRoute>();
                for (int i = 0; i < k; i++)
                {
                    this.Res.Add(res1[i]);
                }
            }
        }