Пример #1
0
        /// <summary>
        ///
        /// </summary>
        public override bool AddToWhiteList(IAttributeCollection attributes, Whitelist whitelist)
        {
            if (_attributesTable == null)
            {
                _attributesTable = new Table(this.Script);
                _resultsTable    = new Table(this.Script);
            }

            var traversable = false;

            // build lua table.
            _attributesTable.Clear();
            foreach (var attribute in attributes)
            {
                _attributesTable.Set(attribute.Key, DynValue.NewString(attribute.Value));
            }

            // call each function once and build the list of attributes to keep.
            foreach (var function in this.ProfileFunctions)
            {
                // call factor_and_speed function.
                _resultsTable.Clear();
                this.Script.Call(function, _attributesTable, _resultsTable);

                float val;
                if (_resultsTable.TryGetFloat("speed", out val))
                {
                    if (val != 0)
                    {
                        traversable = true;
                    }
                }

                // get the result.
                var dynAttributesToKeep = _resultsTable.Get("attributes_to_keep");
                if (dynAttributesToKeep == null)
                {
                    continue;
                }
                foreach (var attribute in dynAttributesToKeep.Table.Keys.Select(x => x.String))
                {
                    whitelist.Add(attribute);
                }
            }
            return(traversable);
        }
Пример #2
0
        /// <summary>
        /// Adds a new collection to cache if appropriate.
        /// </summary>
        public bool Add(IAttributeCollection attributes, out Whitelist whitelist, out bool[] canTraverse, bool filter = true)
        {
            IAttributeCollection filtered = attributes;

            if (filter)
            {
                filtered = new AttributeCollection();

                foreach (var attribute in attributes)
                {
                    if (_vehicles.IsOnProfileWhiteList(attribute.Key))
                    {
                        filtered.AddOrReplace(attribute);
                    }
                }
            }

            if (filtered.Count == 0)
            {
                whitelist   = null;
                canTraverse = null;
                return(false);
            }
            var id = _edgeProfiles.Add(filtered);
            WhitelistAndFlags whitelistAndFlags;

            if (!_cache.TryGetValue(id, out whitelistAndFlags))
            {
                whitelist   = new Whitelist();
                canTraverse = new bool[_vehicles.Length];
                _vehicles.AddToWhiteList(filtered, whitelist, canTraverse);
                _cache[id] = new WhitelistAndFlags()
                {
                    CanTraverse = canTraverse,
                    Whitelist   = whitelist
                };
                return(true);
            }
            whitelist   = whitelistAndFlags.Whitelist;
            canTraverse = whitelistAndFlags.CanTraverse;
            return(true);
        }
Пример #3
0
        /// <summary>
        /// Adds to the whitelist.
        /// </summary>
        public bool AddToWhiteList(IAttributeCollection attributes, Whitelist whitelist, bool filter = true)
        {
            IAttributeCollection filtered = attributes;

            if (filter)
            {
                filtered = new AttributeCollection();

                foreach (var attribute in attributes)
                {
                    if (_vehicles.IsOnProfileWhiteList(attribute.Key))
                    {
                        filtered.AddOrReplace(attribute);
                    }
                }
            }

            Whitelist cachedWhitelist;

            if (this.TryGetCached(filtered, out cachedWhitelist, false))
            {
                foreach (var key in cachedWhitelist)
                {
                    whitelist.Add(key);
                }
                return(cachedWhitelist.Count > 0);
            }
            bool[] canTraverse;
            if (this.Add(filtered, out cachedWhitelist, out canTraverse, false))
            {
                foreach (var key in cachedWhitelist)
                {
                    whitelist.Add(key);
                }
                return(cachedWhitelist.Count > 0);
            }

            return(false);
        }
Пример #4
0
 /// <summary>
 /// Tries to get cached whitelist.
 /// </summary>
 public bool TryGetCached(IAttributeCollection attributes, out Whitelist whitelist, bool filter = true)
 {
     bool[] canTraverse;
     return(this.TryGetCached(attributes, out whitelist, out canTraverse, filter));
 }
Пример #5
0
 /// <summary>
 /// Pushes the attributes through this profiles and adds used keys in the given whitelist.
 /// </summary>
 public override FactorAndSpeed FactorAndSpeed(IAttributeCollection attributes, Whitelist whiteList)
 {
     throw new NotImplementedException("Not used and unavailable with dynamic vehicles.");
 }
Пример #6
0
 /// <summary>
 /// Calculates a factor and speed and adds a keys to the given whitelist that are relevant.
 /// </summary>
 /// <returns>True if the edge with the given attributes is usefull for this vehicle.</returns>
 public abstract FactorAndSpeed FactorAndSpeed(IAttributeCollection attributes, Whitelist whitelist);
Пример #7
0
 /// <summary>
 /// Adds a number of keys to the given whitelist when they are relevant for this vehicle.
 /// </summary>
 /// <returns>True if the edge with the given attributes is usefull for this vehicle.</returns>
 public virtual bool AddToWhiteList(IAttributeCollection attributes, Whitelist whitelist)
 {
     return(this.FactorAndSpeed(attributes, whitelist).Value > 0);
 }
Пример #8
0
        /// <summary>
        /// Adds all the keys to the whitelist if they are relevante for the profiles.
        /// </summary>
        public static bool AddToWhiteList(this Vehicle[] vehicles, IAttributeCollection attributes, Whitelist whiteList, bool[] canTraverse)
        {
            var traversable = false;

            for (var i = 0; i < vehicles.Length; i++)
            {
                canTraverse[i] = false;
                if (vehicles[i].AddToWhiteList(attributes, whiteList))
                {
                    traversable    = true;
                    canTraverse[i] = true;
                }
            }
            return(traversable);
        }