示例#1
0
        /// <summary>
        /// Tests getting factor and speed.
        /// </summary>
        protected void TestFactorAndSpeed(Itinero.Profiles.Profile profile, short?direction, float?factor, float?speed, params string[] tags)
        {
            var attributesCollection = new AttributeCollection();

            for (int idx = 0; idx < tags.Length; idx = idx + 2)
            {
                attributesCollection.AddOrReplace(tags[idx], tags[idx + 1]);
            }

            var factorAndSpeed = profile.FactorAndSpeed(attributesCollection);

            if (direction != null)
            {
                Assert.AreEqual(direction.Value, factorAndSpeed.Direction);
            }
            if (factor != null)
            {
                Assert.AreEqual(factor.Value, factorAndSpeed.Value);
            }
            if (speed != null)
            {
                if (speed == 0)
                {
                    Assert.AreEqual(0, factorAndSpeed.SpeedFactor, 0.0001);
                }
                else
                {
                    Assert.AreEqual(1.0f / (speed.Value / 3.6), factorAndSpeed.SpeedFactor, 0.0001);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Creates a new contracted graph and adds it to the router db for the given profile.
        /// </summary>
        public static void AddContracted <T>(this RouterDb db, Profiles.Profile profile, WeightHandler <T> weightHandler, bool forceEdgeBased = false)
            where T : struct
        {
            // create the raw directed graph.
            ContractedDb contractedDb = null;

            lock (db)
            {
                if (forceEdgeBased)
                { // edge-based is needed when complex restrictions found.
                    var contracted           = new DirectedDynamicGraph(weightHandler.DynamicSize);
                    var directedGraphBuilder = new Itinero.Algorithms.Contracted.EdgeBased.DirectedGraphBuilder <T>(db.Network.GeometricGraph.Graph, contracted,
                                                                                                                    weightHandler);
                    directedGraphBuilder.Run();

                    // contract the graph.
                    var priorityCalculator = new Itinero.Algorithms.Contracted.EdgeBased.EdgeDifferencePriorityCalculator <T>(contracted, weightHandler,
                                                                                                                              new Itinero.Algorithms.Contracted.EdgeBased.Witness.DykstraWitnessCalculator <T>(weightHandler, int.MaxValue));
                    priorityCalculator.DifferenceFactor = 5;
                    priorityCalculator.DepthFactor      = 5;
                    priorityCalculator.ContractedFactor = 8;
                    var hierarchyBuilder = new Itinero.Algorithms.Contracted.EdgeBased.HierarchyBuilder <T>(contracted, priorityCalculator,
                                                                                                            new Itinero.Algorithms.Contracted.EdgeBased.Witness.DykstraWitnessCalculator <T>(weightHandler, int.MaxValue), weightHandler, db.GetGetRestrictions(profile, null));
                    hierarchyBuilder.Run();

                    contractedDb = new ContractedDb(contracted);
                }
                else
                { // vertex-based is ok when no complex restrictions found.
                    var contracted           = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size, weightHandler.MetaSize);
                    var directedGraphBuilder = new DirectedGraphBuilder <T>(db.Network.GeometricGraph.Graph, contracted, weightHandler);
                    directedGraphBuilder.Run();

                    // contract the graph.
                    var priorityCalculator = new EdgeDifferencePriorityCalculator(contracted,
                                                                                  new DykstraWitnessCalculator(int.MaxValue));
                    priorityCalculator.DifferenceFactor = 5;
                    priorityCalculator.DepthFactor      = 5;
                    priorityCalculator.ContractedFactor = 8;
                    var hierarchyBuilder = new HierarchyBuilder <T>(contracted, priorityCalculator,
                                                                    new DykstraWitnessCalculator(int.MaxValue), weightHandler);
                    hierarchyBuilder.Run();

                    contractedDb = new ContractedDb(contracted);
                }
            }

            // add the graph.
            lock (db)
            {
                db.AddContracted(profile, contractedDb);
            }
        }
示例#3
0
 /// <summary>
 /// Creates a new contracted graph and adds it to the router db for the given profile.
 /// </summary>
 public static void AddContracted(this RouterDb db, Profiles.Profile profile, bool forceEdgeBased = false)
 {
     db.AddContracted <float>(profile, profile.DefaultWeightHandlerCached(db), forceEdgeBased);
 }
示例#4
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.VehicleType);

            vehicleTypes.Insert(0, string.Empty);
            return((vertex) =>
            {
                var restrictionList = new List <uint[]>();
                for (var i = 0; i < vehicleTypes.Count; i++)
                {
                    RestrictionsDb restrictionsDb;
                    if (db.TryGetRestrictions(vehicleTypes[i], out restrictionsDb))
                    {
                        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;
            });
        }
示例#5
0
 /// <summary>
 /// Returns true if this db contains complex restrictions for the given profile.
 /// </summary>
 public static bool HasComplexRestrictions(this RouterDb db, Profiles.Profile profile)
 {
     return(db.HasComplexRestrictions(profile.VehicleType));
 }
示例#6
0
 /// <summary>
 /// Returns true if the given profile is supported.
 /// </summary>
 public static bool Supports(this RouterDb db, Profiles.Profile profile)
 {
     return(db.Supports(profile.Parent.Name));
 }
示例#7
0
 public override Result <EdgePath <T> > TryCalculateRaw <T>(Itinero.Profiles.Profile profile, WeightHandler <T> weightHandler, RouterPoint source, RouterPoint target, RoutingSettings <T> settings)
 {
     return(new Result <EdgePath <T> >(new EdgePath <T>()));
 }
示例#8
0
 public override Result <EdgePath <T>[][]> TryCalculateRaw <T>(Itinero.Profiles.Profile profile, WeightHandler <T> weightHandler, RouterPoint[] sources, RouterPoint[] targets,
                                                               ISet <int> invalidSources, ISet <int> invalidTargets, RoutingSettings <T> settings)
 {
     throw new System.NotImplementedException();
 }
示例#9
0
 /// <summary>
 /// Returns true if this routing db has a contracted version of the routing network for the given profile.
 /// </summary>
 public bool HasContractedFor(Profiles.Profile profile)
 {
     return(_contracted.ContainsKey(profile.FullName));
 }
示例#10
0
 /// <summary>
 /// Tries to get a contracted version of the routing network for the given profile.
 /// </summary>
 public bool TryGetContracted(Profiles.Profile profile, out ContractedDb contracted)
 {
     return(_contracted.TryGetValue(profile.FullName, out contracted));
 }
示例#11
0
 /// <summary>
 /// Adds a contracted version of the routing network for the given profile.
 /// </summary>
 public void AddContracted(Profiles.Profile profile, ContractedDb contracted)
 {
     _contracted[profile.FullName] = contracted;
 }
示例#12
0
 /// <summary>
 /// Adds a supported profile.
 /// </summary>
 public void AddSupportedProfile(Profiles.Profile profile)
 {
     _supportedProfiles.Add(profile.Name);
 }
示例#13
0
 /// <summary>
 /// Returns true if the given profile is supported.
 /// </summary>
 public bool Supports(Profiles.Profile profile)
 {
     return(_supportedProfiles.Contains(profile.Name));
 }
示例#14
0
 /// <summary>
 /// Calculates for all registered profiles.
 /// </summary>
 public void CalculateForAll()
 {
     this.CalculateFor(Profile.GetAllRegistered().ToArray());
 }