Exemplo n.º 1
0
        private void SerachNext(List <RouteLength> roulengthlist, List <RouteModel> routelist, string route, int length, string from, string to)
        {
            string newroute  = route;
            int    newlength = length;

            for (int i = 0; i < routelist.Count; i++)
            {
                if (routelist[i].From == from)
                {
                    if (routelist[i].To == to)
                    {
                        newroute   = newroute + "|" + routelist[i].To;
                        newlength += routelist[i].RouteLength;
                        RouteLength r = new RouteLength();
                        r.RouteList = newroute;
                        r.Length    = newlength;
                        roulengthlist.Add(r);
                    }
                    else
                    {
                        if (checkpointin(newroute, routelist[i].To))
                        {
                            string tempnewroute  = newroute + "|" + routelist[i].To;
                            int    tempnewlength = newlength + routelist[i].RouteLength;
                            SerachNext(roulengthlist, routelist, tempnewroute, tempnewlength, routelist[i].To, to);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void SerachRoute(Hashtable roulentable, List <RouteModel> routelist, string route, int length, string from, string oldfrom, Hashtable stationmap)
        {
            string newroute  = route;
            int    newlength = length;

            for (int i = 0; i < routelist.Count; i++)
            {
                if (routelist[i].From == from)
                {
                    if (!newroute.Contains(routelist[i].To))
                    {
                        //double oldaddress = Convert.ToDouble(stationmap[oldfrom]);
                        //double newaddress = Convert.ToDouble(stationmap[routelist[i].To]);
                        if (Convert.ToDouble(stationmap[routelist[i].To]) > Convert.ToDouble(stationmap[oldfrom]))
                        {
                            //一个可能值
                            string key = stationmap[oldfrom] + "," + stationmap[routelist[i].To];
                            if (roulentable.ContainsKey(key))
                            {
                                //有重复值
                                if (((RouteLength)roulentable[key]).Length > (newlength + routelist[i].RouteLength))
                                {
                                    //一个新值
                                    roulentable[key] = new RouteLength(newroute + "|" + routelist[i].To, newlength + routelist[i].RouteLength);
                                }
                            }
                            else
                            {
                                //没有重复值  添加新值
                                roulentable[key] = new RouteLength(newroute + "|" + routelist[i].To, newlength + routelist[i].RouteLength);
                            }
                        }
                        string tempnewroute  = newroute + "|" + routelist[i].To;
                        int    tempnewlength = newlength + routelist[i].RouteLength;
                        SerachRoute(roulentable, routelist, tempnewroute, tempnewlength, routelist[i].To, oldfrom, stationmap);
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 优化第一步:点点成线.
        /// </summary>
        /// <param name="roulentable"></param>
        /// <param name="routelist"></param>
        /// <param name="route"></param>
        /// <param name="length"></param>
        /// <param name="from"></param>
        /// <param name="oldfrom"></param>
        /// <param name="stationmap"></param>
        private void CzltSerachRoute(Hashtable roulentable, List<RouteModel> routelist, string route, int length, string from, string oldfrom, Hashtable stationmap)
        {
            string newroute = route;
            int newlength = length;
            fromTemp = from;
            List<RouteModel> routelist1 = routelist.FindAll(new Predicate<RouteModel>(FindConvert));
            for (int i = 0; i < routelist1.Count; i++)
            {
                if (!newroute.Contains(routelist1[i].To))
                {
                    string tempnewroute = string.Empty;
                    int tempnewlength = 0;
                    if (stationmap[routelist1[i].To] != null)
                    {
                        if (Convert.ToDouble(stationmap[routelist1[i].To]) > Convert.ToDouble(stationmap[oldfrom]))
                        {
                            //一个可能值
                            string key = stationmap[oldfrom] + "," + stationmap[routelist1[i].To];
                            if (roulentable.ContainsKey(key))
                            {
                                //有重复值
                                if (((RouteLength)roulentable[key]).Length > (newlength + routelist1[i].RouteLength))
                                {
                                    //一个新值
                                    roulentable[key] = new RouteLength(newroute + "|" + routelist1[i].To, newlength + routelist1[i].RouteLength);
                                }
                            }
                            else
                            {
                                //没有重复值  添加新值
                                roulentable[key] = new RouteLength(newroute + "|" + routelist1[i].To, newlength + routelist1[i].RouteLength);
                            }
                            tempnewroute = newroute + "|" + routelist1[i].To;
                            tempnewlength = newlength + routelist1[i].RouteLength;
                        }
                        continue;
                    }

                    tempnewroute = newroute + "|" + routelist1[i].To;
                    tempnewlength = newlength + routelist1[i].RouteLength;
                    CzltSerachRoute(roulentable, routelist, tempnewroute, tempnewlength, routelist1[i].To, oldfrom, stationmap);
                }
            }

        }
Exemplo n.º 4
0
        /// <summary>
        /// 近一步对线进行优化
        /// </summary>
        /// <param name="rolenttable"></param>
        /// <param name="routelist"></param>
        /// <param name="route"></param>
        /// <param name="length"></param>
        /// <param name="lastFrom"></param>
        /// <param name="lastTo"></param>
        /// <param name="startfrom"></param>
        /// <param name="endTo"></param>
        /// <param name="pCount"></param>
        /// <returns></returns>
        private Hashtable SerachHashRoute(Hashtable rolenttable, Hashtable routelist, string route, int length, string lastFrom, string lastTo, string startfrom, string endTo,int pCount)
        {
            string newRoute = string.Empty;
            int newLength = 0;
            if (Convert.ToDouble(lastTo) <= Convert.ToDouble(endTo))
            {
                if (routelist.ContainsKey(lastTo + "," + endTo))
                {
                    RouteLength rtFisrt = (RouteLength)routelist[lastTo + "," + endTo];
                    string strFirstKey = lastFrom + "," + endTo;
                    if (!rolenttable.ContainsKey(strFirstKey))
                    {
                        if (string.IsNullOrEmpty(route))
                            route = rtFisrt.RouteList;
                        else
                            route = route + "|" + rtFisrt.RouteList;
                        length += rtFisrt.Length;
                        rolenttable[strFirstKey] = new RouteLength(route, length);
                    }
                    else
                    {
                        RouteLength rtFirstNewTemp = (RouteLength)rolenttable[strFirstKey];

                        if (rtFirstNewTemp.Length > (length + rtFisrt.Length))
                        {
                            if (string.IsNullOrEmpty(route))
                                route = rtFisrt.RouteList;
                            else
                                route = route + "|" + rtFisrt.RouteList;
                            length = length + rtFisrt.Length;
                            rolenttable[strFirstKey] = new RouteLength(route, length);
                        }
                    }

                }
                else
                {
                    if (string.IsNullOrEmpty(route))
                    {
                        foreach (string strKey in routelist.Keys)
                        {
                            string[] skeys = strKey.Split(',');
                            //该次线段的起始位置和上次的线段的结尾一致
                            if (skeys[0].Equals(lastTo))
                            {
                                newRoute = route;
                                newLength = length;
                                //获取两点间的线段
                                RouteLength rt = (RouteLength)routelist[strKey];
                                if (Convert.ToDouble(skeys[1]) > Convert.ToDouble(startfrom))
                                {
                                    //设置该次线段的键值
                                    string strKeyTemp = startfrom + "," + skeys[1];

                                    //临时路径表中不存在该路径
                                    if (!rolenttable.ContainsKey(strKeyTemp))
                                    {
                                        if (string.IsNullOrEmpty(newRoute))
                                            newRoute = rt.RouteList;
                                        else
                                            newRoute = newRoute + "|" + rt.RouteList;
                                        newLength += rt.Length;
                                        rolenttable[strKeyTemp] = new RouteLength(newRoute, newLength);
                                    }
                                    else//临时路径表中存在该路径
                                    {
                                        RouteLength rtNewTemp = (RouteLength)rolenttable[strKeyTemp];

                                        if (rtNewTemp.Length > (newLength + rt.Length))
                                        {
                                            if (string.IsNullOrEmpty(newRoute))
                                                newRoute = rt.RouteList;
                                            else
                                                newRoute = newRoute + "|" + rt.RouteList;
                                            newLength = newLength + rt.Length;
                                            rolenttable[strKeyTemp] = new RouteLength(newRoute, newLength);
                                        }
                                        else
                                        {
                                            if (string.IsNullOrEmpty(newRoute))
                                                newRoute = rtNewTemp.RouteList;
                                            else
                                                newRoute = newRoute + "|" + rtNewTemp.RouteList;
                                            newLength = newLength + rtNewTemp.Length;
                                        }

                                    }

                                    if (skeys[1].Equals(endTo) || Convert.ToDouble(skeys[1]) > Convert.ToDouble(endTo))
                                    {
                                        continue;
                                    }

                                    if (pCount >= 10)
                                        continue;

                                    SerachHashRoute(rolenttable, routelist, newRoute, newLength, skeys[0], skeys[1], startfrom, endTo,pCount);
                                }
                            }
                        }
                    }
                }
            }
            return (Hashtable)rolenttable.Clone();
        }
Exemplo n.º 5
0
 private void SerachRoute(Hashtable roulentable, List<RouteModel> routelist, string route, int length, string from, string oldfrom, Hashtable stationmap)
 {
     string newroute = route;
     int newlength = length;
     for (int i = 0; i < routelist.Count; i++)
     {
         if (routelist[i].From == from)
         {
             if (!newroute.Contains(routelist[i].To))
             {
                 //double oldaddress = Convert.ToDouble(stationmap[oldfrom]);
                 //double newaddress = Convert.ToDouble(stationmap[routelist[i].To]);
                 if (Convert.ToDouble(stationmap[routelist[i].To]) > Convert.ToDouble(stationmap[oldfrom]))
                 {
                     //一个可能值
                     string key = stationmap[oldfrom] + "," + stationmap[routelist[i].To];
                     if (roulentable.ContainsKey(key))
                     {
                         //有重复值
                         if (((RouteLength)roulentable[key]).Length > (newlength + routelist[i].RouteLength))
                         {
                             //一个新值
                             roulentable[key] = new RouteLength(newroute + "|" + routelist[i].To, newlength + routelist[i].RouteLength);
                         }
                     }
                     else
                     {
                         //没有重复值  添加新值
                         roulentable[key] = new RouteLength(newroute + "|" + routelist[i].To, newlength + routelist[i].RouteLength);
                     }
                 }
                 string tempnewroute = newroute + "|" + routelist[i].To;
                 int tempnewlength = newlength + routelist[i].RouteLength;
                 SerachRoute(roulentable, routelist, tempnewroute, tempnewlength, routelist[i].To, oldfrom, stationmap);
             }
         }
     }
 }
Exemplo n.º 6
0
        private void SearchWhile(Hashtable roulentable, List<RouteModel> routelist, string route, int length, string from, string oldfrom, Hashtable stationmap)
        {
            Stack<MultiRecord> RouteStack = new Stack<MultiRecord>();
            MultiRecord Record = null;
            List<RouteModel> PointRoute = SearchPoint(from, route, routelist);
            if (PointRoute.Count > 0)
            {
                Record = new MultiRecord(route, length, from, oldfrom, PointRoute);
                RouteStack.Push(Record);
                while (true)
                {
                    if (Record.NextRoute())
                    {
                        RouteModel temproute = Record.IndexRouteModel;
                        if (Convert.ToDouble(stationmap[temproute.To]) > Convert.ToDouble(stationmap[oldfrom]))
                        {
                            //一个可能值
                            string key = stationmap[oldfrom] + "," + stationmap[temproute.To];
                            if (roulentable.ContainsKey(key))
                            {
                                //有重复值
                                if (((RouteLength)roulentable[key]).Length > (Record.Length + temproute.RouteLength))
                                {
                                    //一个新值
                                    roulentable[key] = new RouteLength(Record.Route + "|" + temproute.To, Record.Length + temproute.RouteLength);
                                }
                            }
                            else
                            {
                                //没有重复值  添加新值
                                roulentable[key] = new RouteLength(Record.Route + "|" + temproute.To, Record.Length + temproute.RouteLength);
                            }
                        }
                        string tempnewroute = Record.Route + "|" + temproute.To;
                        int tempnewlength = Record.Length + temproute.RouteLength;
                        List<RouteModel> newroutepoint = SearchPoint(temproute.To, tempnewroute, routelist);
                        if (newroutepoint.Count > 0)
                        {
                            MultiRecord newrecord = new MultiRecord(tempnewroute, tempnewlength, temproute.To, oldfrom, newroutepoint);
                            RouteStack.Push(newrecord);
                            Record = newrecord;
                        }

                    }
                    else
                    {
                        if (RouteStack.Count > 0)
                        {
                            Record = RouteStack.Pop();
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                return;
            }
        }
Exemplo n.º 7
0
 private static bool FindKeyRoulenContains(RouteLength rl)
 {
     if (rl != null && rl.Key.Contains(_findKeyContains))
         return true;
     return false;
 }
Exemplo n.º 8
0
        /// <summary>
        /// 2011-2-26
        /// </summary>
        /// <param name="pOldRouteLengthList"></param>
        /// <param name="pNewRouteLengthList"></param>
        /// <param name="startfrom"></param>
        /// <param name="lastFrom"></param>
        /// <param name="lastTo"></param>
        /// <param name="route"></param>
        /// <param name="length"></param>
        /// <param name="pRouteStationAddress"></param>
        /// <param name="rountStationCount"></param>
        /// <param name="pUpdateFlag"></param>
        /// <returns></returns>
        private bool SerachRoute20110226(List<RouteLength> pOldRouteLengthList, List<RouteLength> pNewRouteLengthList, string startfrom, string endTo, string lastFrom, string lastTo, string route, int length, string pRouteStationAddress, int rountStationCount, bool pUpdateFlag, ref bool pReturnFlag)
        {
            try
            {
                rountStationCount += 1;
                string newRoute = string.Empty;
                int newLength = 0;
                string routeStationAddress = string.Empty;

                _findKeyEquals = startfrom + "," + endTo;
                RouteLength sRoute = pNewRouteLengthList.Find(new Predicate<RouteLength>(FindKeyRoulenEquals));
                if (sRoute != null && sRoute.Length < length)
                    return pUpdateFlag;

                _findKeyEquals = lastTo + "," + endTo;
                RouteLength findRoute = pOldRouteLengthList.Find(new Predicate<RouteLength>(FindKeyRoulenEquals));
                if (findRoute != null)
                {
                    #region 【存在上次最后的基站 到 完结基站的路径】
                    if (!lastTo.Equals(startfrom))
                    {
                        routeStationAddress = pRouteStationAddress;
                        string strFinishKey = startfrom + "," + endTo;//完结键值
                        _findKeyEquals = strFinishKey;
                        RouteLength findFinishRoute = pOldRouteLengthList.Find(new Predicate<RouteLength>(FindKeyRoulenEquals));

                        if (findFinishRoute == null)//完结路径不存在
                        {
                            string[] strRounteAddresses1 = findRoute.RouteStationAddress.Split(',');
                            bool addressFlag1 = false;
                            if (strRounteAddresses1.Length > 1)
                            {
                                for (int mi = 1; mi < strRounteAddresses1.Length; mi++)
                                {
                                    if (!string.IsNullOrEmpty(strRounteAddresses1[mi]) && pRouteStationAddress.Contains(strRounteAddresses1[mi]))
                                    {
                                        addressFlag1 = true;
                                        break;
                                    }
                                }
                            }
                            if (!addressFlag1)
                            {
                                if (string.IsNullOrEmpty(route))
                                    route = findRoute.RouteList;
                                else
                                    route = route + "|" + findRoute.RouteList.Substring(findRoute.RouteList.IndexOf("|") + 1);

                                length += findRoute.Length;

                                routeStationAddress += "," + findRoute.RouteStationAddress.Substring(findRoute.RouteStationAddress.IndexOf(",") + 1);

                                findFinishRoute = new RouteLength(strFinishKey, route, length, rountStationCount, routeStationAddress);
                                pNewRouteLengthList.Add(findFinishRoute);
                                pUpdateFlag = true;
                                if (findRoute.RountStationCount > 1)
                                    pReturnFlag = true;
                            }
                        }
                        else
                        {
                            if (findFinishRoute.RountStationCount > 1)
                            {
                                if (findFinishRoute.Length > (length + findRoute.Length))
                                {
                                    if (string.IsNullOrEmpty(route))
                                        route = findRoute.RouteList;
                                    else
                                        route = route + "|" + findRoute.RouteList.Substring(findRoute.RouteList.IndexOf("|") + 1);
                                    length = length + findRoute.Length;
                                    routeStationAddress += "," + findRoute.RouteStationAddress.Substring(findRoute.RouteStationAddress.IndexOf(",") + 1);

                                    int finishIndex = pNewRouteLengthList.IndexOf(findFinishRoute);
                                    pNewRouteLengthList[finishIndex].Length = length;
                                    pNewRouteLengthList[finishIndex].RountStationCount = rountStationCount;
                                    pNewRouteLengthList[finishIndex].RouteList = route;
                                    pNewRouteLengthList[finishIndex].RouteStationAddress = routeStationAddress;
                                    pUpdateFlag = true;
                                    if (findRoute.RountStationCount > 1)
                                        pReturnFlag = true;
                                }
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    //查询上次最后的基站开头的路径线
                    _findKeyContains = lastTo + ",";
                    List<RouteLength> findAllRoute = pOldRouteLengthList.FindAll(new Predicate<RouteLength>(FindKeyRoulenContains));
                    if (findAllRoute != null && findAllRoute.Count > 0)//存在上次最后的基站开头的路径线
                    {
                        for (int i = 0; i < findAllRoute.Count; i++)//遍历上次最后的基站开头的路径线
                        {
                            RouteLength findRl = findAllRoute[i];
                            string[] skeys = findRl.Key.Split(',');//分割获取得到的键值
                            if (skeys[0].Equals(lastTo) && !skeys[1].Equals(lastFrom) && !skeys[1].Equals(startfrom))
                            {
                                newRoute = route;
                                newLength = length;
                                if (string.IsNullOrEmpty(pRouteStationAddress))
                                    routeStationAddress = skeys[0];
                                else
                                    routeStationAddress = pRouteStationAddress;

                                //生成新的唯一标示
                                string strNewKey = startfrom + "," + skeys[1];

                                if (findRl.RountStationCount > 1)//当前获取的路径不是最基础的线段
                                {
                                    //判断获取的线段中的分站点与当前路径中的分站点是否有重复
                                    string[] strRounteAddresses = findRl.RouteStationAddress.Split(',');
                                    bool addressFlag = false;
                                    if (strRounteAddresses.Length > 1)
                                    {
                                        for (int mi = 1; mi < strRounteAddresses.Length; mi++)
                                        {
                                            if (!string.IsNullOrEmpty(strRounteAddresses[mi]) && routeStationAddress.Contains(strRounteAddresses[mi]))
                                            {
                                                addressFlag = true;
                                                break;
                                            }
                                        }

                                        //没有重复
                                        if (!addressFlag)
                                        {
                                            _findKeyEquals = strNewKey;
                                            RouteLength rlNew = pNewRouteLengthList.Find(new Predicate<RouteLength>(FindKeyRoulenEquals));

                                            //临时存路径的内存是否存在该条路径
                                            if (rlNew == null)//不存在
                                            {
                                                if (string.IsNullOrEmpty(newRoute))
                                                    newRoute = findRl.RouteList;
                                                else
                                                    newRoute = newRoute + "|" + findRl.RouteList.Substring(findRl.RouteList.IndexOf("|") + 1);

                                                newLength += findRl.Length;

                                                routeStationAddress += "," + findRl.RouteStationAddress.Substring(findRl.RouteStationAddress.IndexOf(",") + 1);

                                                //rlNew = new RouteLength(strNewKey, newRoute, newLength, rountStationCount, routeStationAddress);
                                                //pNewRouteLengthList.Add(rlNew);
                                                //pUpdateFlag = true;
                                            }
                                            else//存在
                                            {
                                                routeStationAddress += "," + findRl.RouteStationAddress.Substring(findRl.RouteStationAddress.IndexOf(",") + 1);

                                                if (rlNew.RountStationCount > 1)
                                                {
                                                    if (rlNew.Length > (newLength + findRl.Length))
                                                    {
                                                        if (string.IsNullOrEmpty(newRoute))
                                                            newRoute = findRl.RouteList;
                                                        else
                                                            newRoute = newRoute + "|" + findRl.RouteList.Substring(findRl.RouteList.IndexOf("|") + 1);

                                                        newLength += findRl.Length;

                                                        int newIndex = pNewRouteLengthList.IndexOf(rlNew);
                                                        pNewRouteLengthList[newIndex].Length = newLength;
                                                        pNewRouteLengthList[newIndex].RouteList = newRoute;
                                                        pNewRouteLengthList[newIndex].RountStationCount = rountStationCount;
                                                        pNewRouteLengthList[newIndex].RouteStationAddress = routeStationAddress;
                                                        pUpdateFlag = true;
                                                    }
                                                    else
                                                        continue;
                                                }
                                                else
                                                {
                                                    if (rlNew.Length < (newLength + findRl.Length))
                                                        continue;

                                                    if (string.IsNullOrEmpty(newRoute))
                                                        newRoute = findRl.RouteList;
                                                    else
                                                        newRoute = newRoute + "|" + findRl.RouteList.Substring(findRl.RouteList.IndexOf("|") + 1);
                                                    newLength += findRl.Length;
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    if (!routeStationAddress.Contains(skeys[1]))
                                    {
                                        _findKeyEquals = strNewKey;
                                        RouteLength rlNew1 = pNewRouteLengthList.Find(new Predicate<RouteLength>(FindKeyRoulenEquals));

                                        if (rlNew1 == null)//不存在
                                        {
                                            routeStationAddress += "," + skeys[1];
                                            if (string.IsNullOrEmpty(newRoute))
                                                newRoute = findRl.RouteList;
                                            else
                                                newRoute = newRoute + "|" + findRl.RouteList.Substring(findRl.RouteList.IndexOf("|") + 1);

                                            newLength += findRl.Length;

                                            //rlNew1 = new RouteLength(strNewKey, newRoute, newLength, rountStationCount, routeStationAddress);
                                            //pNewRouteLengthList.Add(rlNew1);
                                            //pUpdateFlag = true;
                                        }
                                        else//存在
                                        {
                                            routeStationAddress += "," + findRl.RouteStationAddress.Substring(findRl.RouteStationAddress.IndexOf(",") + 1);

                                            if (rlNew1.RountStationCount > 1)
                                            {
                                                if (rlNew1.Length > (newLength + findRl.Length))
                                                {
                                                    if (string.IsNullOrEmpty(newRoute))
                                                        newRoute = findRl.RouteList;
                                                    else
                                                        newRoute = newRoute + "|" + findRl.RouteList.Substring(findRl.RouteList.IndexOf("|") + 1);
                                                    newLength += findRl.Length;
                                                    int newIndex1 = pNewRouteLengthList.IndexOf(rlNew1);
                                                    pNewRouteLengthList[newIndex1].Length = newLength;
                                                    pNewRouteLengthList[newIndex1].RouteList = newRoute;
                                                    pNewRouteLengthList[newIndex1].RountStationCount = rountStationCount;
                                                    pNewRouteLengthList[newIndex1].RouteStationAddress = routeStationAddress;
                                                    pUpdateFlag = true;
                                                }
                                                else
                                                    continue;
                                            }
                                            else
                                            {
                                                if (rlNew1.Length < (newLength + findRl.Length))
                                                    continue;

                                                if (string.IsNullOrEmpty(newRoute))
                                                    newRoute = findRl.RouteList;
                                                else
                                                    newRoute = newRoute + "|" + findRl.RouteList.Substring(findRl.RouteList.IndexOf("|") + 1);
                                                newLength += findRl.Length;
                                            }
                                        }
                                    }
                                }

                                //超过10次循环下个路径段
                                if (rountStationCount >= 3)
                                    continue;

                                pUpdateFlag = SerachRoute20110226(pOldRouteLengthList, pNewRouteLengthList, startfrom, endTo, skeys[0], skeys[1], newRoute, newLength, routeStationAddress, rountStationCount, pUpdateFlag, ref pReturnFlag);
                                if (pReturnFlag)
                                    break;
                            }
                        }
                    }
                }
            }
            catch (Exception ee)
            {
                string eeeee = ee.Message;
            }
            return pUpdateFlag;
        }
Exemplo n.º 9
0
 private static bool FindKeyRoulenEquals(RouteLength rl)
 {
     try
     {
         if (rl != null && rl.Key.Equals(_findKeyEquals))
             return true;
     }
     catch (Exception ee)
     {
         string eemxx = ee.Message;
     }
     return false;
 }
Exemplo n.º 10
0
 /// <summary>
 /// 反方向寻找路径点
 /// </summary>
 /// <param name="oldHt"></param>
 /// <param name="nowRoulentable"></param>
 /// <param name="strStationAddress"></param>
 /// <param name="endStationAddress"></param>
 /// <returns></returns>
 private Hashtable GetReversePoint(Hashtable oldHt, Hashtable nowRoulentable, string strStationAddress, string endStationAddress)
 {
     Hashtable ht = new Hashtable();
     ht = oldHt;
     foreach (string strKey1 in nowRoulentable.Keys)
     {
         string[] strTemp1 = strKey1.Split(',');
         if (strTemp1[1].Equals(strStationAddress))
         {
             foreach (string strKey2 in nowRoulentable.Keys)
             {
                 if (!nowRoulentable[strKey1].Equals(nowRoulentable[strKey2]))
                 {
                     string[] strTemp2 = strKey2.Split(',');
                     #region [结尾相同处理]
                     if (strTemp1[1].Equals(strTemp2[1]) && strTemp1[1].Equals(endStationAddress))
                     {
                         if (Convert.ToDouble(strTemp1[0]) < Convert.ToDouble(strTemp2[0]))
                         {
                             RouteLength rl1 = (RouteLength)nowRoulentable[strKey1];
                             RouteLength rl2 = (RouteLength)nowRoulentable[strKey2];
                             string strKey4 = strTemp1[0] + "," + strTemp2[0];
                             if (!nowRoulentable.ContainsKey(strKey4))
                             {
                                 if (!ht.ContainsKey(strKey4))
                                 {
                                     string[] strRouteTemps = rl2.RouteList.Split('|');
                                     string strRouteTemp = string.Empty;
                                     for (int i = strRouteTemps.Length - 1; i >= 0; i--)
                                     {
                                         strRouteTemp += "|" + strRouteTemps[i];
                                     }
                                     ht[strKey4] = new RouteLength(rl1.RouteList + strRouteTemp, rl1.Length + rl2.Length);
                                 }
                                 else
                                 {
                                     RouteLength rl4 = (RouteLength)ht[strKey4];
                                     if (rl4.Length > (rl1.Length + rl2.Length))
                                     {
                                         string[] strRouteTemps = rl2.RouteList.Split('|');
                                         string strRouteTemp = string.Empty;
                                         for (int i = strRouteTemps.Length - 1; i >= 0; i--)
                                         {
                                             strRouteTemp += "|" + strRouteTemps[i];
                                         }
                                         ht[strKey4] = new RouteLength(rl1.RouteList + strRouteTemp, rl1.Length + rl2.Length);
                                     }
                                 }
                             }
                             else
                             {
                                 RouteLength rl5 = (RouteLength)nowRoulentable[strKey4];
                                 if (!ht.ContainsKey(strKey4))
                                 {
                                     if (rl5.Length > (rl1.Length + rl2.Length))
                                     {
                                         string[] strRouteTemps = rl2.RouteList.Split('|');
                                         string strRouteTemp = string.Empty;
                                         for (int i = strRouteTemps.Length - 1; i >= 0; i--)
                                         {
                                             strRouteTemp += "|" + strRouteTemps[i];
                                         }
                                         ht[strKey4] = new RouteLength(rl1.RouteList + strRouteTemp, rl1.Length + rl2.Length);
                                     }
                                     else
                                     {
                                         ht[strKey4] = rl5;
                                     }
                                 }
                                 else
                                 {
                                     RouteLength rl6 = (RouteLength)ht[strKey4];
                                     if (rl6.Length > (rl1.Length + rl2.Length))
                                     {
                                         string[] strRouteTemps = rl2.RouteList.Split('|');
                                         string strRouteTemp = string.Empty;
                                         for (int i = strRouteTemps.Length - 1; i >= 0; i--)
                                         {
                                             strRouteTemp += "|" + strRouteTemps[i];
                                         }
                                         ht[strKey4] = new RouteLength(rl1.RouteList + strRouteTemp, rl1.Length + rl2.Length);
                                     }
                                 }
                             }
                         }
                     }
                     #endregion
                 }
             }
         }
     }
     return ht;
 }
Exemplo n.º 11
0
        /// <summary>
        /// 生成第一步 相邻分站之间连成线
        /// </summary>
        /// <param name="roulentable"></param>
        /// <param name="routelist"></param>
        /// <param name="route"></param>
        /// <param name="length"></param>
        /// <param name="from"></param>
        /// <param name="oldfrom"></param>
        /// <param name="stationmap"></param>
        private void CzltSerachRoute(List<RouteLength> roulentable, List<RouteModel> routelist, string route, int length, string from, string oldfrom, Hashtable stationmap)
        {
            string newroute = route;
            int newlength = length;
            fromTemp = from;
            List<RouteModel> routelist1 = routelist.FindAll(new Predicate<RouteModel>(FindConvert));
            for (int i = 0; i < routelist1.Count; i++)
            {
                if (!newroute.Contains(routelist1[i].To))
                {
                    string tempnewroute = string.Empty;
                    int tempnewlength = 0;
                    if (stationmap[routelist1[i].To] != null)
                    {
                        //一个可能值
                        string key = stationmap[oldfrom] + "," + stationmap[routelist1[i].To];
                        _findKeyEquals = key;
                        RouteLength rlEquals = roulentable.Find(new Predicate<RouteLength>(FindKeyRoulenEquals));
                        if (rlEquals != null)//有重复值
                        {
                            if (rlEquals.RountStationCount == 1)//两点直接连线
                            {
                                if (rlEquals.Length > (newlength + routelist1[i].RouteLength))
                                {
                                    int indexRoulenTable = roulentable.IndexOf(rlEquals);
                                    roulentable[indexRoulenTable].Length = newlength + routelist1[i].RouteLength;
                                    roulentable[indexRoulenTable].RouteList = newroute + "|" + routelist1[i].To;
                                }
                            }
                        }
                        else//没有重复值  添加新值
                        {
                            rlEquals = new RouteLength(key, newroute + "|" + routelist1[i].To, newlength + routelist1[i].RouteLength, 1, key);
                            roulentable.Add(rlEquals);
                        }
                        tempnewroute = newroute + "|" + routelist1[i].To;
                        tempnewlength = newlength + routelist1[i].RouteLength;
                        continue;
                    }

                    tempnewroute = newroute + "|" + routelist1[i].To;
                    tempnewlength = newlength + routelist1[i].RouteLength;
                    CzltSerachRoute(roulentable, routelist, tempnewroute, tempnewlength, routelist1[i].To, oldfrom, stationmap);
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// 将线段连成长线-即完整的轨迹线(正方向)
        /// </summary>
        /// <param name="nowRoulentable"></param>
        /// <param name="strStationAddress"></param>
        /// <returns></returns>
        private Hashtable RouteAppend(Hashtable nowRoulentable, string strStationAddress)
        {
            Hashtable htNew = new Hashtable();
            htNew = (Hashtable)nowRoulentable.Clone();

            foreach (string strKey1 in nowRoulentable.Keys)
            {
                string[] strTemp1 = strKey1.Split(',');
                if (strTemp1[0].Equals(strStationAddress))
                {
                    foreach (string strKey2 in nowRoulentable.Keys)
                    {
                        if (!nowRoulentable[strKey1].Equals(nowRoulentable[strKey2]))
                        {
                            string[] strTemp2 = strKey2.Split(',');
                            #region [起始头相同处理]
                            if (strTemp1[0].Equals(strTemp2[0]) && strTemp1[0].Equals(strStationAddress))
                            {
                                if (Convert.ToDouble(strTemp1[1]) < Convert.ToDouble(strTemp2[1]))
                                {
                                    RouteLength rl1 = (RouteLength)nowRoulentable[strKey1];
                                    RouteLength rl2 = (RouteLength)nowRoulentable[strKey2];
                                    string strKey3 = strTemp1[1] + "," + strTemp2[1];
                                    if (!nowRoulentable.ContainsKey(strKey3))
                                    {
                                        if (!htNew.ContainsKey(strKey3))
                                        {
                                            string[] strRouteTemps = rl1.RouteList.Split('|');
                                            string strRouteTemp = string.Empty;
                                            for (int i = strRouteTemps.Length - 1; i >= 0; i--)
                                            {
                                                strRouteTemp += strRouteTemps[i] + "|";
                                            }
                                            htNew[strKey3] = new RouteLength(strRouteTemp + rl2.RouteList, rl1.Length + rl2.Length);
                                        }
                                        else
                                        {
                                            RouteLength rl3 = (RouteLength)htNew[strKey3];
                                            if (rl3.Length > (rl1.Length + rl2.Length))
                                            {
                                                string[] strRouteTemps = rl1.RouteList.Split('|');
                                                string strRouteTemp = string.Empty;
                                                for (int i = strRouteTemps.Length - 1; i >= 0; i--)
                                                {
                                                    strRouteTemp += strRouteTemps[i] + "|";
                                                }
                                                htNew[strKey3] = new RouteLength(strRouteTemp + rl2.RouteList, rl1.Length + rl2.Length);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        RouteLength rl5 = (RouteLength)nowRoulentable[strKey3];
                                        if (!htNew.ContainsKey(strKey3))
                                        {
                                            if (rl5.Length > (rl1.Length + rl2.Length))
                                            {
                                                string[] strRouteTemps = rl1.RouteList.Split('|');
                                                string strRouteTemp = string.Empty;
                                                for (int i = strRouteTemps.Length - 1; i >= 0; i--)
                                                {
                                                    strRouteTemp += strRouteTemps[i] + "|";
                                                }
                                                htNew[strKey3] = new RouteLength(strRouteTemp + rl2.RouteList, rl1.Length + rl2.Length);
                                            }
                                            else
                                            {
                                                htNew[strKey3] = rl5;
                                            }
                                        }
                                        else
                                        {
                                            RouteLength rl6 = (RouteLength)htNew[strKey3];
                                            if (rl6.Length > (rl1.Length + rl2.Length))
                                            {
                                                string[] strRouteTemps = rl1.RouteList.Split('|');
                                                string strRouteTemp = string.Empty;
                                                for (int i = strRouteTemps.Length - 1; i >= 0; i--)
                                                {
                                                    strRouteTemp += strRouteTemps[i] + "|";
                                                }
                                                htNew[strKey3] = new RouteLength(strRouteTemp + rl2.RouteList, rl1.Length + rl2.Length);
                                            }
                                        }
                                    }
                                }
                            }
                            #endregion
                        }
                    }
                }
            }
            return (Hashtable)htNew.Clone();
        }
Exemplo n.º 13
0
 private void SerachNext(List<RouteLength> roulengthlist, List<RouteModel> routelist, string route, int length, string from, string to)
 {
     string newroute = route;
     int newlength = length;
     for (int i = 0; i < routelist.Count; i++)
     {
         if (routelist[i].From == from)
         {
             if (routelist[i].To == to)
             {
                 newroute = newroute + "|" + routelist[i].To;
                 newlength += routelist[i].RouteLength;
                 RouteLength r = new RouteLength();
                 r.RouteList = newroute;
                 r.Length = newlength;
                 roulengthlist.Add(r);
             }
             else
             {
                 if (checkpointin(newroute, routelist[i].To))
                 {
                     string tempnewroute = newroute + "|" + routelist[i].To;
                     int tempnewlength = newlength + routelist[i].RouteLength;
                     SerachNext(roulengthlist, routelist, tempnewroute, tempnewlength, routelist[i].To, to);
                 }
             }
         }
     }
 }