Exemple #1
0
        public NextNode calcMinDistance()
        {
            NextNode nextNode = new NextNode();

            S = new LinkedList <NextNode>();
            S.AddFirst(new NextNode(currentNode, currentNode, 0));
            LinkedList <NextNode> U = new LinkedList <NextNode>();

            for (int i = 0; i < RES.LOC_MAX; i++)
            {
                if (i != currentNode)
                {
                    U.AddLast(new NextNode(currentNode, i, RES.DISTANCE_MAX));
                }
            }

            List <NextNode> disList    = new List <NextNode>();
            List <NextNode> minDisList = new List <NextNode>();

            while (U.Count > 0)
            {
                NextNode minNode = findNeighbors(S.Last <NextNode>(), U, S);
                S.AddLast(minNode);
                U.Remove(minNode);
            }
            return(nextNode);
        }
Exemple #2
0
 private static void setIt(NextNode nodeU, NextNode thisNode, int city, int distance)
 {
     if (nodeU.next != thisNode.next && nodeU.next == city)
     {
         if (thisNode.distance + distance < nodeU.distance)
         {
             nodeU.distance = thisNode.distance;
             thisNode.copyDirsTo(nodeU);
             nodeU.addNode(city, distance);
         }
     }
 }
Exemple #3
0
        private NextNode findNeighbors(NextNode thisNode, LinkedList <NextNode> edges, LinkedList <NextNode> S)
        {
            int currentNode = thisNode.next;

            switch (currentNode)
            {
            case RES.BJ:
                foreach (NextNode n in edges)
                {
                    setIt(n, thisNode, RES.TJ, getDistance(currentNode, RES.TJ));
                    setIt(n, thisNode, RES.HLJ, getDistance(currentNode, RES.HLJ));
                    setIt(n, thisNode, RES.SD, getDistance(currentNode, RES.SD));
                    setIt(n, thisNode, RES.SC, getDistance(currentNode, RES.SC));
                    setIt(n, thisNode, RES.HB, getDistance(currentNode, RES.HB));
                }
                break;

            case RES.HLJ:
                foreach (NextNode n in edges)
                {
                    setIt(n, thisNode, RES.BJ, getDistance(currentNode, RES.BJ));
                    setIt(n, thisNode, RES.TJ, getDistance(currentNode, RES.TJ));
                }
                break;

            case RES.TJ:
                foreach (NextNode n in edges)
                {
                    setIt(n, thisNode, RES.HLJ, getDistance(currentNode, RES.HLJ));
                    setIt(n, thisNode, RES.BJ, getDistance(currentNode, RES.BJ));
                    setIt(n, thisNode, RES.SD, getDistance(currentNode, RES.SD));
                    setIt(n, thisNode, RES.SH, getDistance(currentNode, RES.SH));
                }
                break;

            case RES.SD:
                foreach (NextNode n in edges)
                {
                    setIt(n, thisNode, RES.BJ, getDistance(currentNode, RES.BJ));
                    setIt(n, thisNode, RES.TJ, getDistance(currentNode, RES.TJ));
                    setIt(n, thisNode, RES.SC, getDistance(currentNode, RES.SC));
                    setIt(n, thisNode, RES.HB, getDistance(currentNode, RES.HB));
                    setIt(n, thisNode, RES.SH, getDistance(currentNode, RES.SH));
                }
                break;

            case RES.SC:
                foreach (NextNode n in edges)
                {
                    setIt(n, thisNode, RES.BJ, getDistance(currentNode, RES.BJ));
                    setIt(n, thisNode, RES.SD, getDistance(currentNode, RES.SD));
                    setIt(n, thisNode, RES.HB, getDistance(currentNode, RES.HB));
                    setIt(n, thisNode, RES.GD, getDistance(currentNode, RES.GD));
                }
                break;

            case RES.HB:
                foreach (NextNode n in edges)
                {
                    setIt(n, thisNode, RES.BJ, getDistance(currentNode, RES.BJ));
                    setIt(n, thisNode, RES.SD, getDistance(currentNode, RES.SD));
                    setIt(n, thisNode, RES.SC, getDistance(currentNode, RES.SC));
                    setIt(n, thisNode, RES.SH, getDistance(currentNode, RES.SH));
                    setIt(n, thisNode, RES.GD, getDistance(currentNode, RES.GD));
                }
                break;

            case RES.SH:
                foreach (NextNode n in edges)
                {
                    setIt(n, thisNode, RES.TJ, getDistance(currentNode, RES.TJ));
                    setIt(n, thisNode, RES.SD, getDistance(currentNode, RES.SD));
                    setIt(n, thisNode, RES.HB, getDistance(currentNode, RES.HB));
                    setIt(n, thisNode, RES.GD, getDistance(currentNode, RES.GD));
                }
                break;

            case RES.GD:
                foreach (NextNode n in edges)
                {
                    setIt(n, thisNode, RES.SC, getDistance(currentNode, RES.SC));
                    setIt(n, thisNode, RES.HB, getDistance(currentNode, RES.HB));
                    setIt(n, thisNode, RES.SH, getDistance(currentNode, RES.SH));
                }
                break;
            }
            NextNode minNode = edges.First <NextNode>();

            for (int i = 1; i < edges.Count(); i++)
            {
                if (minNode.distance > edges.ElementAt <NextNode>(i).distance)
                {
                    minNode = edges.ElementAt <NextNode>(i);
                }
            }
            return(minNode);
        }
Exemple #4
0
 public void copyDirsTo(NextNode node)
 {
     this.dirs.CopyTo(node.dirs, 0);
     node.index = this.index;
 }
Exemple #5
0
        private void OnTimerEvent(Object source, ElapsedEventArgs e)
        {
            this.Enabled = false;


            if (runningList.Count() <= 0)
            {
                return;
            }
            foreach (Distance d in nodes)
            {
                d.calcMinDistance();
            }
            List <TreeModel> toRemove = new List <TreeModel>();

            foreach (TreeModel t in runningList)
            {
                if (t.trackRoute == null)
                {
                    t.trackRoute = nodes[t.src].getNextNode(t.dst);
                }
                t.trackRoute.distance -= 100;
                if (t.trackRoute.distance <= 0)
                {
                    this.Enabled = false;
                    //到达目的地
                    if (t.trackRoute.next == t.dst)
                    {
                        NextNode n = t.trackRoute;
                        //写入数据库
                        DBO.newRecord(t.Name, t.trackRoute.current, t.trackRoute.next, RES.SENDING);
                        DBO.newRecord(t.Name, t.trackRoute.next, t.trackRoute.next, RES.ARRIVED);
                        //修改UI表项
                        ZsmTreeView currentTree = treeList[n.current][1];
                        ZsmTreeView nextTree    = treeList[n.next][2];
                        foreach (TreeModel dateNode in currentTree.ItemsSourceData)
                        {
                            if (dateNode.Children.Contains(t))
                            {
                                dateNode.Children.Remove(t);
                                IList <TreeModel> nextSource = nextTree.ItemsSourceData;
                                int dateIndex = nextSource.Count();
                                while (dateIndex-- > 0)
                                {
                                    TreeModel date2 = nextSource.ElementAt <TreeModel>(dateIndex);
                                    if (dateNode.Name.Equals(date2.Name))
                                    {
                                        break;
                                    }
                                }
                                if (dateIndex == -1)
                                {
                                    TreeModel newDate = new TreeModel(dateNode.Name);
                                    newDate.type     = TreeModel.DATE;
                                    newDate.Children = new List <TreeModel>();
                                    newDate.Children.Add(t);
                                    nextSource.Add(newDate);
                                }
                                else
                                {
                                    nextSource.ElementAt <TreeModel>(dateIndex).Children.Add(t);
                                }
                            }
                        }
                        toRemove.Add(t);
                        if (t.IsChecked)
                        {
                            context.moveToArrivedCheckedList(t);
                        }
                    }
                    //到达下一站
                    else
                    {
                        NextNode n = nodes[t.trackRoute.next].getNextNode(t.dst);
                        //写入数据库
                        DBO.newRecord(t.Name, t.trackRoute.current, t.trackRoute.next, RES.SENDING);
                        //修改UI表项
                        ZsmTreeView currentTree = treeList[n.current][1];
                        ZsmTreeView nextTree    = treeList[n.next][1];
                        foreach (TreeModel dateNode in treeList[t.trackRoute.current][1].ItemsSourceData)
                        {
                            if (dateNode.Children.Contains(t))
                            {
                                dateNode.Children.Remove(t);
                                IList <TreeModel> nextSource = treeList[t.trackRoute.next][1].ItemsSourceData;
                                int dateIndex = nextSource.Count();
                                while (dateIndex-- > 0)
                                {
                                    TreeModel date2 = nextSource.ElementAt <TreeModel>(dateIndex);
                                    if (dateNode.Name.Equals(date2.Name))
                                    {
                                        break;
                                    }
                                }
                                if (dateIndex == -1)
                                {
                                    TreeModel newDate = new TreeModel(dateNode.Name);
                                    newDate.type     = TreeModel.DATE;
                                    newDate.Children = new List <TreeModel>();
                                    newDate.Children.Add(t);
                                    nextSource.Add(newDate);
                                }
                                else
                                {
                                    nextSource.ElementAt <TreeModel>(dateIndex).Children.Add(t);
                                }
                            }
                        }
                        //进入下一节点
                        t.trackRoute = n;
                    }
                }
            }
            foreach (TreeModel t in toRemove)
            {
                runningList.Remove(t);
            }
            this.Enabled = true;
            foreach (ZsmTreeView[] trees in treeList)
            {
                foreach (ZsmTreeView tree in trees)
                {
                    sync.Post(context.startUpdateUI, tree);
                    sync.Post(context.endUpdateUI, tree);
                }
            }
        }