示例#1
0
        ///<summary>判断路径是否联通</summary>
        ///<param name="s">用户按照一定格式输入的路径信息 e.g.“A-B-C"</param>
        ///<returns>0为不连通 或 返回路径长度</returns>
        public double IsSolution(string s)
        {
            NetWork nw   = InitNetWork();
            double  dist = 0;

            string[] tmp = s.Trim().Split('-');
            for (int i = 0; i < tmp.Length - 1; i++)
            {
                //在有向图中寻找路径是否存在
                if (nw.FindRoute(tmp[i], tmp[i + 1]) == null)
                {
                    return(0);
                }
                else
                {
                    dist += nw.FindRoute(tmp[i], tmp[i + 1]).Weight;
                }
            }
            return(dist);
        }