Пример #1
0
        private static List <Lane> FindCompatibleHighestPrio(string[] lanes)
        {
            List <Lane> prioLanes = new List <Lane>();
            //Adds the lane with the highest priority of all the lanes to the list.
            Lane highestPrio = FindHighestPrio(lanes);

            if (highestPrio.GetPriority() == 0)
            {
                return(prioLanes);
            }
            prioLanes.Add(highestPrio);

            List <Lane> compatibleLanes(string[] compatibleKeys)
            {
                Lane prio         = FindHighestPrio(compatibleKeys);
                bool isCompatible = true;

                if (lanes.Contains(prio.GetGroup()))
                {
                    foreach (Lane lane in prioLanes)
                    {
                        if (!(lane.GetGroupedLanes().Contains(prio.GetGroup())))
                        {
                            isCompatible = false; break;
                        }
                    }
                    if (isCompatible)
                    {
                        prioLanes.Add(prio);
                    }
                }


                string stringToRemove = prio.GetGroup();

                compatibleKeys = compatibleKeys.Where(val => val != stringToRemove).ToArray();
                if (compatibleKeys.Length == 0)
                {
                    return(prioLanes);
                }
                return(compatibleLanes(compatibleKeys));
            }

            compatibleLanes(highestPrio.GetGroupedLanes());
            return(prioLanes);
        }
Пример #2
0
        private static Lane FindHighestPrio(string[] keys)
        {
            Lane lane = null;

            foreach (string key in keys)
            {
                Lane value;
                if (lanes.TryGetValue(key, out value))
                {
                    if (lane == null)
                    {
                        lane = value; continue;
                    }
                    else if (value.GetPriority() >= lane.GetPriority())
                    {
                        lane = value;
                    }
                }
            }

            return(lane);
        }