コード例 #1
0
        /// <summary>
        /// Builds a route.
        /// </summary>
        public static Result <Route> TryBuild <T>(RouterDb db, Profile profile, RouterPoint source, RouterPoint target, EdgePath <T> path, CancellationToken cancellationToken)
        {
            var pathList = new List <uint>();

            path.AddToListAsVertices(pathList);
            return(CompleteRouteBuilder1.TryBuild(db, profile, source, target, pathList, cancellationToken));
        }
コード例 #2
0
        /// <summary>
        /// Builds a route.
        /// </summary>
        public static Result <Route> TryBuild(RouterDb db, Profile profile, RouterPoint source, RouterPoint target, List <uint> path, CancellationToken cancellationToken)
        {
            var routeBuilder = new CompleteRouteBuilder1(db, profile, source, target, path);

            routeBuilder.Run(cancellationToken);
            if (!routeBuilder.HasSucceeded)
            {
                return(new Result <Route>(
                           string.Format("Failed to build route: {0}", routeBuilder.ErrorMessage)));
            }
            return(new Result <Route>(routeBuilder.Route));
        }
コード例 #3
0
        /// <summary>
        /// Add shortcut if the current edge is one.
        /// </summary>
        private bool AddShortcut(RoutingEdge edge, CancellationToken cancellationToken)
        {
            // when both are just regular vertices, this could be a shortcut.
            var edgeProfile  = _routerDb.EdgeProfiles.Get(edge.Data.Profile);
            var shortcutName = string.Empty;

            if (edgeProfile.IsShortcut(out shortcutName))
            { // ok profile is a shortcut, get the actual path, expand and build route.
                ShortcutsDb shortcutsDb;
                if (_routerDb.TryGetShortcuts(shortcutName, out shortcutsDb))
                {
                    var shortcutProfile = _routerDb.GetSupportedProfile(shortcutsDb.ProfileName);
                    IAttributeCollection shortcutMeta;
                    var shortcut = shortcutsDb.Get(edge.From, edge.To, out shortcutMeta);
                    if (shortcut != null && shortcut.Length >= 2)
                    {
                        try
                        {
                            var route = CompleteRouteBuilder1.Build(_routerDb, shortcutProfile,
                                                                    _routerDb.CreateRouterPointForVertex(shortcut[0], shortcutProfile, _profile),
                                                                    _routerDb.CreateRouterPointForVertex(shortcut[shortcut.Length - 1], shortcutProfile,
                                                                                                         _profile),
                                                                    new List <uint>(shortcut), cancellationToken);
                            if (shortcutMeta == null)
                            {
                                shortcutMeta = new AttributeCollection();
                            }

                            shortcutMeta.AddOrReplace(ShortcutExtensions.SHORTCUT_KEY, shortcutName);

                            this.AppendRoute(route, shortcutMeta);
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("Could not build shortcut route.", ex);
                        }

                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #4
0
 public Result <Route> TryBuild <T>(RouterDb db, Profile profile, RouterPoint source, RouterPoint target, EdgePath <T> path)
 {
     return(CompleteRouteBuilder1.TryBuild <T>(db, profile, source, target, path));
 }
コード例 #5
0
 /// <summary>
 /// Builds a route.
 /// </summary>
 public static Result <Route> TryBuild(RouterDb db, Profile profile, RouterPoint source, RouterPoint target, List <uint> path)
 {
     return(CompleteRouteBuilder1.TryBuild(db, profile, source, target, path, CancellationToken.None));
 }
コード例 #6
0
 /// <summary>
 /// Builds a route.
 /// </summary>
 public static Route Build(RouterDb db, Profile profile, RouterPoint source, RouterPoint target, List <uint> path, CancellationToken cancellationToken)
 {
     return(CompleteRouteBuilder1.TryBuild(db, profile, source, target, path, cancellationToken).Value);
 }
コード例 #7
0
 /// <summary>
 /// Builds a route.
 /// </summary>
 public static Route Build(RouterDb db, Profile profile, RouterPoint source, RouterPoint target, EdgePath <float> path)
 {
     return(CompleteRouteBuilder1.Build(db, profile, source, target, path, CancellationToken.None));
 }