Exemple #1
0
        public Result <Route> TryCalculate(Profile profile, RouterPoint source, RouterPoint target)
        {
            if (!this._db.Supports(profile))
            {
                return(new Result <Route>("Routing profile is not supported.", (Func <string, Exception>)(message => new Exception(message))));
            }
            Func <ushort, Factor> getFactor = this.GetGetFactor(profile);
            DirectedMetaGraph     contracted;
            float       weight;
            List <uint> path;

            if (this._db.TryGetContracted(profile, out contracted))
            {
                OsmSharp.Routing.Algorithms.Contracted.BidirectionalDykstra bidirectionalDykstra = new OsmSharp.Routing.Algorithms.Contracted.BidirectionalDykstra(contracted, (IEnumerable <Path>)source.ToPaths(this._db, getFactor, true), (IEnumerable <Path>)target.ToPaths(this._db, getFactor, false));
                bidirectionalDykstra.Run();
                if (!bidirectionalDykstra.HasSucceeded)
                {
                    return(new Result <Route>(bidirectionalDykstra.ErrorMessage, (Func <string, Exception>)(message => (Exception) new RouteNotFoundException(message))));
                }
                path = bidirectionalDykstra.GetPath(out weight);
            }
            else
            {
                OsmSharp.Routing.Algorithms.Default.BidirectionalDykstra bidirectionalDykstra = new OsmSharp.Routing.Algorithms.Default.BidirectionalDykstra(new OsmSharp.Routing.Algorithms.Default.Dykstra(this._db.Network.GeometricGraph.Graph, getFactor, (IEnumerable <Path>)source.ToPaths(this._db, getFactor, true), float.MaxValue, false), new OsmSharp.Routing.Algorithms.Default.Dykstra(this._db.Network.GeometricGraph.Graph, getFactor, (IEnumerable <Path>)target.ToPaths(this._db, profile, false), float.MaxValue, true));
                bidirectionalDykstra.Run();
                if (!bidirectionalDykstra.HasSucceeded)
                {
                    return(new Result <Route>(bidirectionalDykstra.ErrorMessage, (Func <string, Exception>)(message => (Exception) new RouteNotFoundException(message))));
                }
                path = bidirectionalDykstra.GetPath(out weight);
            }
            if ((int)source.EdgeId == (int)target.EdgeId)
            {
                Path from = source.PathTo(this._db, profile, target);
                if (from != null && (double)from.Weight < (double)weight)
                {
                    path = new List <uint>(2);
                    for (; from != null; from = from.From)
                    {
                        path.Insert(0, from.Vertex);
                    }
                }
            }
            return(this.BuildRoute(profile, source, target, path));
        }
Exemple #2
0
        public Result <bool> TryCheckConnectivity(Profile profile, RouterPoint point, float radiusInMeters)
        {
            if (!this._db.Supports(profile))
            {
                return(new Result <bool>("Routing profile is not supported.", (Func <string, Exception>)(message => new Exception(message))));
            }
            Func <ushort, Factor> getFactor = this.GetGetFactor(profile);

            OsmSharp.Routing.Algorithms.Default.Dykstra dykstra = new OsmSharp.Routing.Algorithms.Default.Dykstra(this._db.Network.GeometricGraph.Graph, getFactor, (IEnumerable <Path>)point.ToPaths(this._db, getFactor, true), radiusInMeters, false);
            dykstra.Run();
            if (!dykstra.HasSucceeded)
            {
                return(new Result <bool>(false));
            }
            return(new Result <bool>(dykstra.MaxReached));
        }
Exemple #3
0
 public static Path[] ToPaths(this RouterPoint point, RouterDb routerDb, Profile profile, bool asSource)
 {
     return(point.ToPaths(routerDb, (Func <ushort, Factor>)(p => profile.Factor(routerDb.EdgeProfiles.Get((uint)p))), asSource));
 }