NeighboringPathWays.cs 3.4 KB
using log4net;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CtuDeviceLib

{

    public class NeighboringPathWays
    {
        static List<NeighboringPathWay> _NeighboringPathWays { get; set; }

        public static bool Reload()
        {
            List<NeighboringPathWay> tempNeighboringPathWays = new List<NeighboringPathWay>();

            var pws = PathWays.GetAllPathWays();
            List<uint> keyPoints = new List<uint>();
            foreach (var pw in pws)
            {
                if (!keyPoints.Contains(pw.Paths[0]))
                {
                    keyPoints.Add(pw.Paths[0]);
                }
                else if (!keyPoints.Contains(pw.Paths[pw.Paths.Count - 1]))
                {
                    keyPoints.Add(pw.Paths[pw.Paths.Count - 1]);
                }
            }
            keyPoints.Sort();
            keyPoints.ForEach(s => LogUtil.debug($"【keyPoint={s}"));

            foreach (var p in keyPoints)
            {
                var ways = pws.FindAll(s => s.Paths.Contains(p));
                for (int i = 0; i < ways.Count - 1; i++)
                {
                    for (int j = i + 1; j < ways.Count; j++)
                    {
                        var tmpNB = new NeighboringPathWay()
                        {
                            KeyLandmark = p,
                            StartPathWay = ways[i].Id,
                            EndPathWay = ways[j].Id,
                            IsTwoWayLanes = ways[i].IsTwoWayLanes && ways[j].IsTwoWayLanes,
                        };

                        var find = tempNeighboringPathWays.Find(s => tmpNB.IsSame(s));
                        if (find == null)
                        {
                            tempNeighboringPathWays.Add(tmpNB);
                            LogUtil.debug($"生成邻接路线:startWay={tmpNB.StartPathWay},stopWay={tmpNB.EndPathWay},keyPoint={tmpNB.KeyLandmark},is-two-way={tmpNB.IsTwoWayLanes}");
                        }
                    }
                }

            }
            //var nb = new NeighboringPathWay();
            LogUtil.debug($"生成邻接路线完成");
            return true;
        }

    }
    /// <summary>
    /// 邻接路线
    /// </summary>
    public class NeighboringPathWay
    {
        /// <summary>
        /// 两路线的关键路标号
        /// </summary>
        public uint KeyLandmark {  get; set; }
        /// <summary>
        /// 起始路线编号
        /// </summary>
        public uint StartPathWay { get; set; }
        /// <summary>
        ///结束路线编号
        /// </summary>
        public uint EndPathWay { get; set;}
        /// <summary>
        /// 是否是双向路线
        /// </summary>
        public bool IsTwoWayLanes { get; set; }

        /// <summary>
        /// 是否是相同的邻接路线
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public bool IsSame( NeighboringPathWay other )
        {
            return other.IsTwoWayLanes == IsTwoWayLanes
                && KeyLandmark == other.KeyLandmark
                && ((StartPathWay == other.StartPathWay && EndPathWay == other.EndPathWay)||
                    (StartPathWay == other.EndPathWay && EndPathWay == other.StartPathWay));
        }
    }
}