Esempio n. 1
0
        public void SearchRoute(Vehicle v)
        {
            v.RouteIndex = 0;
            v.cost       = 0;
            v.TPtr       = 0;// tFram = 0;
            v.Finished   = false;
            // v.StopTime = v.sto;
            if (!checkXY(v))
            {
                v.CurState = State.cannotToDestination;
                MessageBox.Show("起点或终点超出地图界限");
                return;
            }
            ////AstarSearch astarSearch = new AstarSearch(Elc);
            List <MyPoint> scannerNode = new List <MyPoint>();

            if (!Elc.IsSpecialArea(v.BeginX, v.BeginY))
            {
                scannerNode = Elc.GetScanner();
            }
            List <MyPoint> routeList = astarSearch.Search(Elc, scannerNode, v.LockNode, v.BeginX, v.BeginY, v.EndX, v.EndY, v.Dir, v.algorithm);

            Elc.mapnode[v.BeginX, v.BeginY].NodeCanUsed = v.Id;
            // Elc.mapnode[startX, startY].NodeCanUsed = false;//搜索完,小车自己所在的地方被小车占用
            if (routeList.Count < 1)
            {
                // MessageBox.Show("没有搜索到路线:"+v_num);
                v.CurState = State.cannotToDestination;
                //v.LockNode.cl;
            }
            else
            {
                v.Route = routeList;
                if (Elc.IsQueueEntra(v.EndX, v.EndY))
                {
                    MyPoint nextEnd = ElecMap.Instance.CalculateScannerPoint(new MyPoint(v.EndX, v.EndY, Direction.Right));
                    if (nextEnd.X == v.BeginX && nextEnd.Y == v.BeginY)
                    {
                        v.Route    = new List <MyPoint>();
                        v.Arrive   = true;
                        v.CurState = State.Free;
                        return;
                    }
                    List <MyPoint> addRoute = astarSearch.Search(Elc, new List <MyPoint>(), v.LockNode, v.EndX, v.EndY, nextEnd.X, nextEnd.Y, v.Dir, v.algorithm);
                    if (addRoute != null && addRoute.Count > 1)
                    {
                        for (int i = 1; i < addRoute.Count; i++)
                        {
                            v.Route.Add(addRoute[i]);
                        }
                        v.EndX   = nextEnd.X;
                        v.EndY   = nextEnd.Y;
                        v.EndLoc = "ScanArea";
                    }
                }
            }
        }
Esempio n. 2
0
 public void SearchRoute(Vehicle v)
 {
     lock (searchLock)
     {
         if (v.agvInfo == null)
         {
             return;
         }
         v.BeginX     = v.GetRealX();
         v.BeginY     = v.GetRealY();
         v.RouteIndex = 0;
         v.cost       = 0;
         v.TPtr       = 0;// tFram = 0;
         v.Finished   = false;
         v.Arrive     = false;
         v.StopTime   = ConstDefine.STOP_TIME;
         if (!checkXY(v))
         {
             v.CurState = State.cannotToDestination;
             MessageBox.Show("起点或终点超出地图界限");
             return;
         }
         ////AstarSearch astarSearch = new AstarSearch(Elc);
         List <MyPoint> scannerNode   = new List <MyPoint>();
         bool           isSpecialArea = false;
         if (!Elc.IsSpecialArea(v.BeginX, v.BeginY))
         {
             scannerNode = Elc.GetScanner();
         }
         else
         {
             if (Elc.IsSpecialArea(v.EndX, v.EndY))//开始起点都是特殊区(从扫描仪绕到排队入口)
             {
                 MyPoint nextEnd = ElecMap.Instance.CalculateScannerPoint(new MyPoint(v.EndX, v.EndY, Direction.Right));
                 v.EndX        = nextEnd.X;
                 v.EndY        = nextEnd.Y;
                 v.StartLoc    = "DestArea"; // "WaitArea";
                 v.EndLoc      = "ScanArea"; // "ScanArea";
                 isSpecialArea = true;
             }
         }
         List <MyPoint> routeList = astarSearch.Search(Elc, scannerNode, v.LockNode, v.BeginX, v.BeginY, v.EndX, v.EndY, v.Dir, v.algorithm);
         // Elc.mapnode[startX, startY].NodeCanUsed = false;//搜索完,小车自己所在的地方被小车占用
         if (routeList.Count < 1)
         {
             // MessageBox.Show("没有搜索到路线:"+v_num);
             v.CurState = State.cannotToDestination;
             //v.LockNode.cl;
         }
         else
         {
             if (isSpecialArea)
             {
                 v.Route = routeList;
                 return;
             }
             if (Elc.IsQueueEntra(v.EndX, v.EndY))
             {
                 MyPoint nextEnd = ElecMap.Instance.CalculateScannerPoint(new MyPoint(v.EndX, v.EndY, Direction.Right));
                 if (nextEnd.X == v.BeginX && nextEnd.Y == v.BeginY)
                 {
                     v.Route    = new List <MyPoint>();
                     v.Arrive   = true;
                     v.CurState = State.Free;
                     return;
                 }
                 List <MyPoint> addRoute = astarSearch.Search(Elc, new List <MyPoint>(), v.LockNode, v.EndX, v.EndY, nextEnd.X, nextEnd.Y, v.Dir, v.algorithm);
                 if (addRoute != null && addRoute.Count > 1)
                 {
                     for (int i = 1; i < addRoute.Count; i++)
                     {
                         routeList.Add(addRoute[i]);
                     }
                     v.EndX   = nextEnd.X;
                     v.EndY   = nextEnd.Y;
                     v.EndLoc = "ScanArea";
                 }
             }
             v.Route = routeList;
         }
     }
 }
Esempio n. 3
0
        public void SearchRoute(Vehicle v)
        {
            v.RouteIndex = 0;
            v.cost       = 0;
            v.TPtr       = 0;// tFram = 0;
            v.StopTime   = ConstDefine.STOP_TIME;

            if (!checkXY(v))
            {
                v.CurState = State.cannotToDestination;
                MessageBox.Show("起点或终点超出地图界限");
                return;
            }
            ////AstarSearch astarSearch = new AstarSearch(Elc);
            List <MyPoint> scannerNode = new List <MyPoint>();

            if (!Elc.IsSpecialArea(v.BeginX, v.BeginY))
            {
                scannerNode = Elc.GetScanner();
            }
            List <MyPoint> routeList = astarSearch.Search(Elc, scannerNode, v.LockNode, v.Id, Elc.WidthNum, Elc.HeightNum, v.BeginX, v.BeginY, v.EndX, v.EndY, v.Dir);

            //this.Speed = 0;
            Elc.mapnode[v.BeginX, v.BeginY].NodeCanUsed = v.Id;
            // Elc.mapnode[startX, startY].NodeCanUsed = false;//搜索完,小车自己所在的地方被小车占用
            if (routeList.Count < 1)
            {
                // MessageBox.Show("没有搜索到路线:"+v_num);
                v.CurState = State.cannotToDestination;
                //v.LockNode.cl;
            }
            else
            {
                v.Route = routeList;
                if (Elc.IsQueueEntra(v.EndX, v.EndY))
                {
                    MyPoint        nextEnd  = ElecMap.Instance.CalculateScannerPoint(new MyPoint(v.EndX, v.EndY));
                    List <MyPoint> addRoute = astarSearch.Search(Elc, new List <MyPoint>(), v.LockNode, v.Id, Elc.WidthNum, Elc.HeightNum, v.EndX, v.EndY, nextEnd.X, nextEnd.Y, v.Dir);
                    if (addRoute != null && addRoute.Count > 1)
                    {
                        for (int i = 1; i < addRoute.Count; i++)
                        {
                            v.Route.Add(addRoute[i]);
                        }
                        //v.EndX = nextEnd.X;
                        //v.EndY = nextEnd.Y;
                        v.EndLoc = "ScanArea";
                    }
                }
                // this.vehical_state = State.carried;

                //Route = new ConcurrentDictionary<int, MyLocation>();
                //List<int> specialPoint = new List<int>();
                //checkSpecialPoint(routeList, specialPoint);

                //for (int i = 0; i < routeList.Count; i++)
                //{
                //    this.Route.TryAdd(i, routeList[i]);
                //}

                //for (int i = 0; i < specialPoint.Count - 1; i++)
                //{
                //    FormRoute(routeList, specialPoint[i], specialPoint[i + 1]);
                //}
            }
        }