Beispiel #1
0
        /// <summary>
        /// Gets the get restriction function for the given profile.
        /// </summary>
        /// <param name="db">The router db.</param>
        /// <param name="profile">The vehicle profile.</param>
        /// <param name="first">When true, only restrictions starting with given vertex, when false only restrictions ending with given vertex already reversed, when null all restrictions are returned.</param>
        public static Func <uint, IEnumerable <uint[]> > GetGetRestrictions(this RouterDb db, Profiles.Profile profile, bool?first)
        {
            var vehicleTypes = new List <string>(profile.VehicleTypes);

            vehicleTypes.Insert(0, string.Empty);

            var restrictionDbs = new RestrictionsDb[vehicleTypes.Count];

            for (var i = 0; i < vehicleTypes.Count; i++)
            {
                RestrictionsDb restrictionsDb;
                if (db.TryGetRestrictions(vehicleTypes[i], out restrictionsDb))
                {
                    restrictionDbs[i] = restrictionsDb;
                }
            }

            return((vertex) =>
            {
                var restrictionList = new List <uint[]>();
                for (var i = 0; i < restrictionDbs.Length; i++)
                {
                    var restrictionsDb = restrictionDbs[i];
                    if (restrictionsDb == null)
                    {
                        continue;
                    }

                    var enumerator = restrictionsDb.GetEnumerator();
                    if (enumerator.MoveTo(vertex))
                    {
                        while (enumerator.MoveNext())
                        {
                            if (first.HasValue && first.Value)
                            {
                                if (enumerator[0] == vertex)
                                {
                                    restrictionList.Add(enumerator.ToArray());
                                }
                            }
                            else if (first.HasValue && !first.Value)
                            {
                                if (enumerator[(int)enumerator.Count - 1] == vertex)
                                {
                                    var array = enumerator.ToArray();
                                    array.Reverse();
                                    restrictionList.Add(array);
                                }
                            }
                            else
                            {
                                restrictionList.Add(enumerator.ToArray());
                            }
                        }
                    }
                }
                return restrictionList;
            });
        }
Beispiel #2
0
        /// <summary>
        /// Returns true if this db contains complex restrictions for the given vehicle type.
        /// </summary>
        public static bool HasComplexRestrictions(this RouterDb db, string vehicleType)
        {
            RestrictionsDb restrictions;

            if (db.TryGetRestrictions(vehicleType, out restrictions))
            {
                return(restrictions.HasComplexRestrictions);
            }
            return(false);
        }
Beispiel #3
0
        /// <summary>
        /// Returns true if this db contains restrictions for the given vehicle type.
        /// </summary>
        public static bool HasRestrictions(this RouterDb db, string vehicleType)
        {
            RestrictionsDb restrictions;

            return(db.TryGetRestrictions(vehicleType, out restrictions));
        }