Esempio n. 1
0
        //从PlanCourse取出一个当前累积权值最小,并且没有被处理过的节点
        private GridNode GetMinWeightRudeNode(PlanCourse planCourse, ArrayList nodeList, string originID)
        {
            double   weight   = double.MaxValue;
            GridNode destNode = null;

            foreach (GridNode node in nodeList)
            {
                if (node.ID == originID)
                {
                    continue;
                }

                PassedPath pPath = planCourse[node.ID];
                if (pPath.IsProcessed)
                {
                    continue;
                }

                if (pPath.Weight < weight)
                {
                    weight   = pPath.Weight;
                    destNode = node;
                }
            }

            return(destNode);
        }
Esempio n. 2
0
        internal PlanCourse(ArrayList nodeList, string originID)
        {
            this._htPassedPath = new Hashtable();

            GridNode originNode = null;

            foreach (GridNode node in nodeList)
            {
                if (node.ID == originID)
                {
                    originNode = node;
                }
                else
                {
                    PassedPath pPath = new PassedPath(node.ID);
                    this._htPassedPath.Add(node.ID, pPath);
                }
            }

            if (originNode == null)
            {
                throw new Exception("The origin node is not exist !");
            }

            this.InitializeWeight(originNode);
        }
Esempio n. 3
0
        //获取权值最小的路径
        //internal RoutePlanResult Paln(ArrayList nodeList ,string originID ,string destID)
        //{
        //    PlanCourse planCourse = new PlanCourse(nodeList ,originID) ;

        //    Node curNode = this.GetMinWeightRudeNode(planCourse ,nodeList ,originID) ;

        //    #region 计算过程
        //    while(curNode != null)
        //    {
        //        PassedPath curPath = planCourse[curNode.ID] ;
        //        foreach(Edge edge in curNode.EdgeList)
        //        {
        //            PassedPath targetPath = planCourse[edge.EndNodeID] ;
        //            double tempWeight = curPath.Weight + edge.Weight ;

        //            if(tempWeight < targetPath.Weight)
        //            {
        //                targetPath.Weight = tempWeight ;
        //                targetPath.PassedIDList.Clear() ;

        //                for(int i=0 ;i<curPath.PassedIDList.Count ;i++)
        //                {
        //                    targetPath.PassedIDList.Add(curPath.PassedIDList[i].ToString()) ;
        //                }

        //                targetPath.PassedIDList.Add(curNode.ID) ;
        //            }
        //        }

        //        //标志为已处理
        //        planCourse[curNode.ID].BeProcessed = true ;
        //        //获取下一个未处理节点
        //        curNode = this.GetMinWeightRudeNode(planCourse ,nodeList ,originID) ;
        //    }
        //    #endregion

        //    //表示规划结束
        //    return this.GetResult(planCourse ,destID) ;
        //}
        #endregion

        #region GetResult
        //从PlanCourse表中取出目标节点的PassedPath,这个PassedPath即是规划结果
        private void GetResult(PlanCourse planCourse, string destID)
        {
            PassedPath pPath = planCourse[destID];

            if (float.Equals(pPath.Weight, float.MaxValue))
            {
                //RoutePlanResult result1 = new RoutePlanResult(null ,int.MaxValue) ;
                //return result1 ;
            }

            string[] passedNodeIDs = new string[pPath.PassedIDList.Count];
            for (int i = 0; i < passedNodeIDs.Length; i++)
            {
                passedNodeIDs[i] = pPath.PassedIDList[i].ToString();
            }
            //RoutePlanResult result = new RoutePlanResult(passedNodeIDs ,pPath.Weight) ;

            //return result ;
        }
Esempio n. 4
0
        private void InitializeWeight(GridNode originNode)
        {
            if ((originNode.EdgeList == null) || (originNode.EdgeList.Count == 0))
            {
                return;
            }

            foreach (Edge edge in originNode.EdgeList)
            {
                PassedPath pPath = this[edge.EndNodeID];
                if (pPath == null)
                {
                    continue;
                }

                pPath.PassedIDList.Add(originNode.ID);
                pPath.Weight = edge.Weight;
            }
        }