Existing computer programs known as road-mapping programs provide digital maps, often complete with detailed road networks down to the city-street level. Typically, a user can input a location and the road-mapping program will display an on-screen map of the selected location. Several existing road-mapping products typically include the ability to calculate a best route between two locations. In other words, the user can input two locations, and the road-mapping program will compute the travel directions from the source location to the destination location. The directions are typically based on distance, travel time, and certain user preferences, such as a speed at which the user likes to drive, or the degree of scenery along the route. Computing the best route between locations may require significant computational time and resources.
Some road-mapping programs compute shortest paths using variants of a well known method attributed to Dijkstra. Note that in this sense “shortest” means “least cost” because each road segment is assigned a cost or weight not necessarily directly related to the road segment's length. By varying the way the cost is calculated for each road, shortest paths can be generated for the quickest, shortest, or preferred routes. Dijkstra's original method, however, is not always efficient in practice, due to the large number of locations and possible paths that are scanned. Instead, many known road-mapping programs use heuristic variations of Dijkstra's method.
More recent developments in road-mapping algorithms utilize a two-stage process comprising a preprocessing phase and a query phase. During the preprocessing phase, the graph or map is subject to an off-line processing such that later real time queries between any two destinations on the graph can be made more efficiently. Known examples of preprocessing algorithms use geometric information, hierarchical decomposition, and A* search combined with landmark distances.
The database community has studied shortest path and nearest neighbor problems in the context of road networks as well as more general spatial databases. Previous solutions in the database context used C++ extensions, could not handle large networks, and computed only approximate paths. More particularly, these previous approaches use preprocessing that scales poorly and is infeasible for large networks. Additionally, the distances used in the previous approaches are based on approximations, which lead to cases where the suggested driving route is at least a few percent longer than the optimal route, or where a query does not return the closest match.
Techniques using hub based labeling are provided that can answer spatial queries on road networks entirely within a database. Queries may be expressed in terms of a relational database, such as in standard SQL. Within the database, exact distance queries can be answered and full shortest path descriptions can be retrieved in real time, even on continental road networks with tens of millions of vertices. Moreover, the techniques can be extended in a natural way (e.g., still in pure SQL) to answer more sophisticated queries in real time, such as finding the ten closest fast food restaurants or minimizing the detour for stopping at a gas station on the way home.
A hub based labeling algorithm is described that is substantially faster than known techniques. Hub based labeling is used to determine a shortest path between two locations. The hub based labeling may be used in databases and may use relational database operators, such as those in SQL. A hub based labeling technique uses two stages: a preprocessing stage and a query stage. Finding the hubs is performed in the preprocessing stage, which is implemented outside of the database. Finding the intersecting hubs (i.e., the common hubs shared by the source and destination locations) is performed in the query stage, in the database, using relational database operators, such as SQL queries. During preprocessing, a forward label and a reverse label are computed for each vertex, and each vertex in a label acts as a hub. The labels are generated using contraction hierarchies augmented by other techniques. A query, such as an SQL query, is processed using the labels to determine the shortest path.
In an implementation, every point has a set of hubs: this is the label (along with the distance from the point to all those hubs). For example, for two points (a source and a destination), there are two labels. The hubs are determined that appear in both labels, and this information is used to find the shortest distance.
Implementations use a variety of enhancement techniques, such as label pruning, shortest path covers, label compression, and/or the use of a partition oracle. Label pruning involves using a fast heuristic modification to a contraction hierarchies (CH) search to identify vertices with incorrect distance bounds. Bootstrapping is used to identify more such vertices. Shortest path covers is an enhancement to the CH processing and may be used to determine which vertices are more important than other vertices, thus reducing the average label size. Label compression may be performed to reduce the amount of memory used. Long range queries may be accelerated by a partition oracle. Implementations may also speed up preprocessing by using faster shortest path covers and/or faster label generation.
This summary is provided to introduce a selection of concepts in a simplified form that are further described below in the detailed description. This summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used to limit the scope of the claimed subject matter.
The foregoing summary, as well as the following detailed description of illustrative embodiments, is better understood when read in conjunction with the appended drawings. For the purpose of illustrating the embodiments, there are shown in the drawings example constructions of the embodiments; however, the embodiments are not limited to the specific methods and instrumentalities disclosed. In the drawings:
The computing device 100 may communicate with a local area network 102 via a physical connection. Alternatively, the computing device 100 may communicate with the local area network 102 via a wireless wide area network or wireless local area network media, or via other communications media. Although shown as a local area network 102, the network may be a variety of network types including the public switched telephone network (PSTN), a cellular telephone network (e.g., 3G, 4G, CDMA, etc), and a packet switched network (e.g., the Internet). Any type of network and/or network interface may be used for the network.
The user of the computing device 100, as a result of the supported network medium, is able to access network resources, typically through the use of a browser application 104 running on the computing device 100. The browser application 104 facilitates communication with a remote network over, for example, the Internet 105. One exemplary network resource is a map routing service 106, running on a map routing server 108. The map routing server 108 hosts a database 110 of physical locations and street addresses, along with routing information such as adjacencies, distances, speed limits, and other relationships between the stored locations.
A user of the computing device 100 typically enters start and destination locations as a query request through the browser application 104. The map routing server 108 receives the request and produces a shortest path among the locations stored in the database 110 for reaching the destination location from the start location. The map routing server 108 then sends that shortest path back to the requesting computing device 100. Alternatively, the map routing service 106 is hosted on the computing device 100, and the computing device 100 need not communicate with a local area network 102.
In an implementation, the database 110 may comprise a relational database and may store relational database operators (such as in SQL) that can be used to efficiently find shortest paths and nearest neighbors on road networks, as described further herein. Alternately, a separate relational database 112 may store relational database operators 114 and use them as described further herein.
The point-to-point (P2P) shortest path problem is a classical problem with many applications. Given a graph G with non-negative arc lengths as well as a vertex pair (s,t), the goal is to find the distance from s to t. The graph may represent a road map, for example. For example, route planning in road networks solves the P2P shortest path problem. However, there are many uses for an algorithm that solves the P2P shortest path problem, and the techniques, processes, and systems described herein are not meant to be limited to maps.
Thus, a P2P algorithm that solves the P2P shortest path problem is directed to finding the shortest distance between any two points in a graph. Such a P2P algorithm may comprise several stages including a preprocessing stage and a query stage. The preprocessing phase may take as an input a directed graph. Such a graph may be represented by G=(V,A), where V represents the set of vertices in the graph and A represents the set of edges or arcs in the graph. The graph comprises several vertices (points), as well as several edges. The preprocessing phase may be used to improve the efficiency of a later query stage, for example.
During the query phase, a user may wish to find the shortest path between two particular nodes. The origination node may be known as the source vertex, labeled s, and the destination node may be known as the target vertex labeled t. For example, an application for the P2P algorithm may be to find the shortest distance between two locations on a road map. Each destination or intersection on the map may be represented by one of the nodes, while the particular roads and highways may be represented by an edge. The user may then specify their starting point s and their destination t.
Thus, to visualize and implement routing methods, it is helpful to represent locations and connecting segments as an abstract graph with vertices and directed edges. Vertices correspond to locations, and edges correspond to road segments between locations. The edges may be weighted according to the travel distance, transit time, and/or other criteria about the corresponding road segment. The general terms “length” and “distance” are used in context to encompass the metric by which an edge's weight or cost is measured. The length or distance of a path is the sum of the weights of the edges contained in the path. For manipulation by computing devices, graphs may be stored in a contiguous block of computer memory as a collection of records, each record representing a single graph node or edge along with associated data.
A labeling technique may be used in the determination of point-to-point shortest paths.
During the preprocessing stage, at 210, the labeling algorithm determines a forward label Lf(v) and a reverse label Lr(v) for each vertex v. Each label comprises a set of vertices w, together with their respective distances from the vertex v (in Lf(v)) or to the vertex v (in Lr(v)). Thus, the forward label comprises a set of vertices w, together with their respective distances d(v,w) from v. Similarly, the reverse label comprises a set of vertices u, each with its distance d(u,v) to v. A labeling is valid if it has the cover property that for every pair of vertices and t, Lf(s)∩Lr(t) contains a vertex u on a shortest path from s to t (i.e., for every pair of distinct vertices s and t, Lf(s) and Lr(t) contain a common vertex u on a shortest path from s to t).
At query time, at 220, a user enters start and destination locations, s and t, respectively (e.g., using the computing device 100), and the query (e.g., the information pertaining to the s and t vertices) is sent to a mapping service (e.g., the map routing service 106) at 230. The s-t query is processed at 240 by finding the vertex uεLf(s)∩Lr(t) that minimizes the distance (dist(s,u)+dist(u,t)). The corresponding path is outputted to the user at 250 as the shortest path.
In an implementation, a labeling technique may use hub based labeling. Recall the preprocessing stage of a P2P shortest path algorithm may take as input a graph G=(V,A), with |V|=n, |A|=m, and length l(a)>0 for each arc a. The length of a path P in G is the sum of its arc lengths. The query phase of the shortest path algorithm takes as input a source s and a target t and returns the distance dist(s,t) between them, i.e., the length of the shortest path between s and t in the graph G. As noted above, the standard solution to this problem is Dijkstra's algorithm, which processes vertices in increasing order of distance from s. For every vertex v, it maintains the length d(v) of the shortest s-v path found so far, as well as the predecessor p(v) of v on the path. Initially, d(s)=0, d(v)=∞ for all other vertices, and p(v)=null for all v. At each step, a vertex v with minimum d(v) value is extracted from a priority queue and scanned: for each arc (v,w)εA, if d(v)+l(v,w)<d(w), set d(w)=d(v)+l(v,w) and p(v)=w. The algorithm terminates when the target t is extracted.
Preprocessing enables much faster exact queries on road networks. The known contraction hierarchies (CH) algorithm, in particular, is based on the notion of shortcuts. The shortcut operation deletes (temporarily) a vertex v from the graph; then, for any neighbors u,w of v such that (u,v)·(v,w) is the only shortest path between u and w, CH adds a shortcut arc (u,w) with l(u,w)=l(u,v)+l(v,w), thus preserving the shortest path information.
The CH preprocessing routine defines a total order among the vertices and shortcuts them sequentially in this order, until a single vertex remains. It outputs a graph G+=(V,A∪A+) (where A+ is the set of shortcut arcs created), as well as the vertex order itself. The position of a vertex v in the order is denoted by rank(v). As used herein, G↑ refers to the graph containing only upward arcs and G↓ refers to the graph containing only downward arcs. Accordingly, G↑ may be defined =(V,A↑) by A↑={(v,w)εA∪A+:rank(v)<rank(w)}. Similarly, A↓ may be defined ={(v,w)εA∪A+:rank(v)>rank(w)} and G↓ defined =(V,A∪A↓).
During an s-t query, the forward CH search runs Dijkstra from s in G↓, and the reverse CH search runs reverse Dijkstra from t in G↓. These searches lead to upper bounds ds(v) and dt(v) on distances from s to v and from v to t for every vεV . For some vertices, these estimates may be greater than the actual distances (and even infinite for unvisited vertices). However, as is known, the maximum-rank vertex u on the shortest s-t path is guaranteed to be visited, and v=u will minimize the distance ds(v)+dt(v)=dist(s,t).
Queries are correct regardless of the contraction order, but query times and the number of shortcuts added may vary greatly. For example, in an implementation, the priority of a vertex u is set to 2ED(u)+CN(u)+H(u)+5L(u), where ED(u) is the difference between the number of arcs added and removed (if u were shortcut), CN(u) is the number of previously contracted neighbors, H(u) is the number of arcs represented by the shortcuts added, and L(u) is the level u would be assigned to. L(u) is defined as L(v)+1, where v is the highest-level vertex among all lower-ranked neighbors of u in G+; if there is no such v, L(u)=0.
A labeling algorithm uses the concept of labels. Every point has a set of hubs: this is the label (along with the distance from the point to all those hubs). For example, for two points (the source and the target), there are two labels. The hubs are determined that appear in both labels, and this information is used to find the shortest distance.
During the preprocessing stage, at 310, a graph is obtained, e.g., from storage or from a user. At 320, CH preprocessing is performed. At 330, for each node v of the graph, a search is run in the hierarchy, only looking upwards. The result is the set of nodes in the forward label. The same is done for reverse labels. For each vertex v define two labels: Lf(v) (forward) is the set of pairs (w, dist(v,w)) for all visited vertices w in the forward upward search, and Lr(v) (reverse) is the set of pairs (u, dist(u,v)) for all visited vertices u in the reverse upward search. Labels have the cover property that for every pair (s,t), there is a vertex v such that vεP(s,t) (v belongs to the shortest path), vεLf(s), and vεLr(t). Each vertex in the labels for v acts as a hub. At 340, labels may be pruned, and a partition oracle may be computed, as described further herein.
Thus, the technique builds labels from CH searches. The CH preprocessing is enhanced to make labels smaller. More particularly, with respect to building a label, in an implementation, given s and t, consider the sets of vertices visited by the forward CH search from s and the reverse CH search from t. CH works because the intersection of these sets contains the maximum-rank vertex u on the shortest s-t path. Therefore, a valid label may be obtained by defining for every v, Lf(v) and Lr(v) to be the sets of vertices visited by the forward and reverse CH searches from v.
In an implementation, to represent labels for allowing efficient queries, a forward label Lf(v) may comprise: (1) a 32-bit integer Nv representing the number of vertices in the label, (2) a zero-based array Iv with the (32-bit) IDs (identifiers) of all vertices in the label, in ascending order, and (3) an array Dv with the (32-bit) distances from v to each vertex in the label. Lr labels are symmetric to that described for Lf labels. Note that vertices appear in the same order in Iv and Dv:Dv[i]=dist(v,Iv[i]).
At query time, at 350, a user enters start and destination locations, s and t, respectively, and the query is sent to a mapping service. The s-t query is processed at 360, using s, t, the labels, and the results of the partition oracle (if any), by determining the vertex uεLf(s)∩Lr(t) (i.e., the vertex u in Lf(s) and Lf(t)) that minimizes the distance (dist(s,u)+dist(u,t)). The corresponding shortest path is outputted to the user at 370.
More particularly, given s and t, the hub based labeling technique picks, among all vertices wεLf(s)∩Lr(t), the one minimizing ds(w)+dt(w)=dist(s,w)+dist(w,t). Because the Iv arrays are sorted, this can be done with a single sweep through the labels. Arrays of indices is and it (initially zero) and a tentative distance μ (initially infinite) are maintained. At each step, Is[is] is compared with It[it]. If these IDs are equal, a new w has been found in the intersection of the labels, so a new tentative distance Ds[is]+Dt[it] is computed, μ is updated if necessary, and both is and it are incremented. If the IDs differ, either is is incremented (if Is[is]<It[it]) or it is incremented (if Is[is]>It[it]). The technique stops when either is=Ns or it=Nt, and then μ is returned.
The technique accesses each array sequentially, thus minimizing the number of cache misses. Avoiding cache misses is also a motivation for having Iv and Dv as separate arrays: while almost all IDs in a label are accessed, distances are only needed when IDs match. Each label is aligned to a cache line. Another improvement is to use the highest-ranked vertex as a sentinel by assigning ID n to it. Because this vertex belongs to all labels, it will lead to a match in every query; it therefore suffices to test for termination only after a match. In addition, the distance to the sentinel may be stored at the beginning of the label, which enables a quick upper bound on the s-t distance to be obtained.
The hub based labeling technique may be improved using a variety of techniques, such as label pruning, shortest path covers, label compression, and the use of a partition oracle.
Label pruning involves identifying vertices visited by the CH search with incorrect distance bounds.
Partial pruning can be accomplished, for example, using a fast heuristic modification to the CH search. More particularly, suppose a forward CH search is being performed (the reverse case is similar) from vertex v, and vertex w is about to be scanned, with distance bound d(w). All incoming arcs (u,w)εA↓, are examined. If d(w)>d(u)+l(u,w), then d(w) is provably incorrect. The vertex w can be removed from the label, and outgoing arcs are not scanned from it. This technique increases the preprocessing time and decreases the average label size and query time.
Bootstrapping may be used to prune the labels further. Labels are computed in descending level order. Suppose the partially pruned label Lf(v) has been computed. It is known that d(v)=0 and that all other vertices w in Lf(v) have higher level than v, which means Lr(w) has already been computed. Therefore, dist(v,w) can be computed by running a v-w query, using Lf(v) itself and the precomputed label Lr(w). The vertex w is removed from Lf(v) if d(w)>dist(v,w). Bootstrapping reduces the average label size and reduces average query times.
Shortest path covers is an enhancement to the CH processing and may be used to determine which vertices are more important than other vertices. Vertices that appear in many shortest paths may tend to be more important than vertices that appear in fewer shortest paths. More particularly, the CH preprocessing algorithm tends to contract the least important vertices (those on few shortest paths) first, and the more important vertices (those on a greater number of shortest paths) later. The heuristic used to choose the next vertex to contract works poorly near the end of preprocessing, when it orders important vertices relative to one another. Shortest path covers may be used to improve the ordering of important vertices. This may be performed near the end of CH preprocessing, when most vertices have been contracted and the graph is small.
The preprocessing techniques described above may be improved. Labels are computed by the preprocessing set forth above. From the point of view of the database programmer, label computation is a black-box: as long as the labels obey the cover property, it does not matter how they are computed. However, label size affects query performance and storage requirements, and preprocessing time is to be reasonable. Techniques may be used that reduce preprocessing time (e.g., by two orders of magnitude), and can produce slightly better (smaller) labels.
As described above, hub label preprocessing comprises building the contraction hierarchy, finding appropriate shortest path covers (SPCs), and building the labels. The first stage is already fast, but its performance can be improved by increasing the amount of parallelism: finding an independent set of high-priority vertices and contracting them in parallel.
Acceleration of the other two stages of hub label preprocessing is now described. Hub label preprocessing uses a greedy algorithm to compute an SPC C of a graph Gt with t vertices. Starting from an empty set, in each round it adds to C the vertex that hits the most (yet-uncovered) shortest paths. Each round computes all-pairs shortest paths on Gt (running Dijkstra's algorithm t times) in order to find out which vertex should be picked next. An alternative implementation of this algorithm is described that can produce the same results much faster. Its efficiency also allows larger values of t to be used, which may improve label quality.
Each round works as follows. At 630, find the vertex w that maximizes c(w) and add it to the cover. Any path now covered by w will no longer contribute to the counter of any vertex v. To update the counters accordingly, look at each tree explicitly. Consider the tree Tr rooted at some vertex r: it represents all uncovered shortest paths in Gt that start at r. Only paths in Tr containing w are relevant during this round. To process them, at 640 traverse the subtree of Tr rooted at w to compute, for each vertex v in the subtree (including w itself), its number cr(v) of descendents in Tr. (This can be done by scanning each vertex in that subtree once.) Note that cr(v) is exactly the number of previously uncovered paths that start at r and contain v.
Now cr(v) can be used to update the global counters at 650. For each ancestor v of w in Tr, set c(v)=c(v)-cr(w). Then, for each vertex v in the subtree of Tr rooted at w, set c(v)=c(v)-cr(v), since every path in Tr that v would hit is now already covered by w. Accordingly, all vertices in the subtree are removed from Tr by setting their parent pointers (within Tr) to null at 660.
In an implementation, a parallel version of this algorithm can be used, in which each tree is processed independently in each round.
In another implementation, multiple visits to the same ancestor during a round can be avoided. Consider the round that adds w to the SPC. As before, when processing each tree Tr, the amount cr(w) is determined by which the c counters on the r-w path should be decremented. The union of these paths (over all r) is a tree. By traversing this tree appropriately, the cr(w) values (for all r) can be used to update all c(v) counters in linear time.
In an implementation, CH searches are eliminated altogether. Additionally, in an implementation, labels may be determined in decreasing level order.
Once the initial Lf(v) label is built, bootstrapping may be used at 730 to remove hubs as described above. Note that bootstrapping is unnecessary for vertices that have exactly one neighbor. The labels of v's neighbors typically contain similar sets of hubs, which means their union is not much bigger than either of them. As an example, the average tentative label for the European road network has only two hubs removed by bootstrapping. For further speedups, this routine can be parallelized: all labels within a level can be computed independently.
Merging existing labels instead of running an upward CH search provides better locality and a smaller initial label (which speeds up bootstrapping). On continental road networks, the average time to generate initial labels is reduced by an order of magnitude, and the entire label generation procedure (including bootstrapping) becomes more than five times faster.
In an implementation, each label is maintained in RAM after it is computed, since the labels may be used for bootstrapping other labels. If memory is an issue, one can keep track of which labels are no longer needed, and output them to external memory sooner. To minimize the size of the working set in RAM, however, alternative label processing orders (instead of top-down by level) may be used. For example, the graph may be partitioned into compact regions, and each region is then processed in turn. If, when processing a vertex v, one of its upward neighbors w is in an unprocessed region, w is processed out of order.
Label compression may be performed to reduce the memory used by the technique. For example, if each vertex ID and distance is to be stored as a separate 32-bit integer, for low-ID vertices, an 8/24 compression scheme may be used: each of the first 256 vertices may be represented as a single 32-bit word, with 8 bits allocated to the ID and 24 bits to the distance. This technique may be generalized for different numbers of bits. For effectiveness, the vertices may be reordered so that the important ones (which appear in most labels) have the lowest IDs. (The new IDs, after reordering, are referred to as internal IDs.) This reduces the memory usage, and query times improve because of better locality.
Another compression technique exploits the fact that the forward (or reverse) CH trees of two nearby vertices in a road network are different near the roots, but are often the same when sufficiently away from them, where the most important vertices appear. By reordering vertices in reverse rank order, for example, the labels of nearby vertices will often share long common prefixes, with the same sets of vertices (but usually different distances). In an implementation, the compression technique may compute a dictionary of the common label prefixes and reuse them.
More particularly, given a parameter k, the k-prefix compression scheme decomposes each forward label Lf(v) (reverse labels are similar) into a prefix Pk(v) (with the vertices with internal ID lower than k) and a suffix Sk(v) (with the remaining vertices). Take the forward (pruned) CH search tree Ty from v: Sk(v) induces a subtree containing v (unless Sk(v) is empty), and Pk(v) induces a forest F. The base b(w) of a vertex wεPk(v) is the parent of the root of w's tree in F; by definition, b(w)εSk(v). If Sk(v) is empty, let b(v)=v. Each prefix Pk(v) is represented as a list of triples (w,δ(w),π(w)), where δ(w) is the distance between b(w) and w, and π(w) is the position of b(w) in Sk(v). Two prefixes are equal only if they comprise the exact same triples. A dictionary (an array) may be built that comprises the distinct prefixes. Each triple may use 64 consecutive bits: 32 for the ID, 24 for δ(•), and 8 for π(•). A forward label Lf (v) comprises the position of its prefix Pk(v) in the dictionary, the number of vertices in the suffix Sk(v), and Sk(v) itself (represented as before). To save space, labels are not cache-aligned.
During a query from v, suppose w is in Pk(v). The distance dist(b(w),w)=δ(w) and the position π(w) of b(w) in Sk(v) is known, where dist(v,b(w)) is stored explicitly. The dist(v,w) may therefore be computed as =dist(v,b(w))+dist(b(w),w).
In an implementation, a flexible prefix compression scheme may be used. Instead of using the same threshold for all labels, it may split each label L in two arbitrarily. As before, common prefixes are represented once and shared among labels. To minimize the total space usage, including all n suffixes and the (up to n) prefixes that are kept, model this as a facility location problem. Each label is a customer that is represented (served) by a suitable prefix (facility). The opening cost of a facility is the size of the corresponding prefix. The cost of serving a customer L by a prefix P is the size of the corresponding suffix (|L|-|P|). Each label L is served by the available prefix that minimizes the service cost. Local search may be used to find a good heuristic solution.
Long range queries may be accelerated by a partition oracle. If the source and the target are far apart, the hub labeling technique searches tend to meet at very important (i.e., high rank) vertices. If the labels are rearranged such that more important vertices appear before less important ones, long-range queries can stop traversing the labels when sufficiently unimportant vertices are reached.
At 920, CH preprocessing is performed as usual, but the contraction of boundary vertices is delayed until the contracted graph has at most 2b vertices. Let B+ be the set of all vertices with rank at least as high as that of the lowest-ranked boundary vertex. This set includes all boundary vertices and has size |B+|≦2b. At 930, labels are computed as set forth above, except the ID of the cell v belongs to is stored at the beginning of a label for v.
At 940, for every pair (Ci,Cj) of cells, queries are run between each vertex in B+∩Ci and each vertex in B+∩Cj, and the internal ID of their meeting vertex is maintained. Let mij be the maximum such ID over all queries made for this pair of cells. At 950, a matrix may be generated, with entry (i,j) corresponding to mij and represented with 32 bits in an implementation. The matrix has size k×k, where k is the number of cells. Building the matrix requires up to 4b2 queries and concludes the preprocessing stage.
At 960, an s-t query (with sεCa and tεCb) looks at vertices in increasing order of internal ID, but it stops as soon as it reaches (in either label) a vertex with internal ID higher than mab, because no query from Ca to Cb meets at a vertex higher than mab. Although this strategy needs one extra memory access to retrieve mab, long-range queries only look at a fraction of each label.
The techniques described above can be implemented using a database (such as the database 110 or the database 112 of
Hub based labeling techniques use queries that are independent from preprocessing, and the queries can be stated in terms of set operations. In some implementations, hub based labeling queries use only relational database operators. A query comprises a set operation (pick the minimum element in the intersection of two sets), and can be naturally expressed in SQL. Techniques described herein can compute in real time not only exact distances, but also full descriptions of shortest paths. By storing the labels in a database, pure SQL code can be executed to obtain the distance between any two points, and to obtain a description of the corresponding shortest path. Such hub based labeling techniques can be extended to perform more sophisticated queries (such as nearest neighbors), taking advantage of the expressive power of relational databases. Additionally, a database implementation gives an external memory implementation of the underlying algorithm, enabling applications that use more information than fits in RAM.
During the preprocessing stage, at 1010, a graph is obtained, e.g., from storage or from a user. At 1020, CH preprocessing is performed, and at 1030 the ordering may be improved using shortest path covers. Forward and reverse labels may then be determined at 1040, using techniques similar to those described above for example.
At 1050, the forward labels and the reverse labels may be stored in a database, such as the database 110 and/or the database 112. At query time, at 1060, queries, such as SQL queries, may be run to compute shortest path distances between user entered start and destination locations, for example. Then, at 1070, SQL queries may be run to compute a path description. The corresponding shortest path is outputted to the user at 1080.
In an implementation, the labels may be stored in the database in two tables, denoted herein the “forward” and “backward” tables. Each table contains all the labels of the corresponding direction, and has three columns: “node”, “hub”, and “dist”. Thus, for each vertex v, each pair (u, dist(v,u))εLf(v) is stored as a triple (v, u, dist(v,u)) in the forward table. Similarly, the backward table stores a triple (v, u, dist(u,v)) for each (u, dist(u,v))εLb(v).
In order to determine the distance between a source s and a target t, the shared hub of the source's entries in the forward table and the target's entries in the backward table are determined that minimizes the sum of the forward and backward distances.
The corresponding SQL statement may be added as a stored procedure to the database. The statement is a program that is run (i.e., executed) on the database. An example is provided as Algorithm 1:
Algorithm 1:
Since the number of rows in the forward table and the backward table is huge (e.g., about 1.5 billion per table on the European road network), the tables should be indexed properly. Algorithm 1 needs fast access to the rows of source and target (lines 5 and 6), followed by fast access to specific hub entries (line 7) within these rows. Therefore, a composite clustered index may be built on node (primary) and hub (secondary). Note that all rows forming the label of a vertex should be stored together to reduce the number of random accesses to the database.
Algorithm 1 computes the distance between any two vertices s and t in the network. The actual list of arcs on the shortest s-t path P may be retrieved. The algorithms can be easily adapted to return the list of vertices as well.
For methods that use the notion of shortcuts, path retrieval works in two stages. First, the shortest s-t path P+ in G+ is obtained; each segment of P+ is either an original arc or a shortcut. This may be performed by maintaining parent pointers in G+ for each hub in each label. The number of such segments in P+ is usually very small—e.g., a few dozen on continental road networks. The second stage is path unpacking: find P by translating each shortcut in P+ into its constituent original arcs.
An approach is to use preassembled subpaths. During preprocessing, the entire sequence of arcs for each shortcut in the graph may be stored. Queries then are processed in two stages: first find the shortest s-t path P+ in G+, then translate each shortcut in P+ into the corresponding arcs. Unlike the recursive approach, the second step retrieves each shortcut path at once, reducing the total number of random accesses e.g., from thousands to dozens. This approach uses additional data proportional to the combined size of all shortcuts in the graph. Fortunately, on road networks each original arc belongs to only three to four shortcuts on average, so the space overhead is moderate.
The preassembled subpath approach may be extended by storing full descriptions of the paths between each vertex v and each of its hubs. If an s-t query meets at a hub v, concatenate the precomputed s-v and v-t paths to obtain the shortest path. The space requirements may become prohibitive, however (e.g., on the European road network, these paths have close to one trillion arcs in total). A more practical alternative would be an intermediate version that preassembles more than just shortcuts, but less than full paths. For example, paths from sufficiently important vertices to their hubs may be stored. As described further herein, the preassembled subpath approach (which precomputes all shortcuts descriptions) can be implemented within a relational database (e.g., using only SQL operations).
To support path retrieval, additional information may be precomputed and added to the database: assign a unique arc ID to every original arc, and a unique shortcut ID to every arc of A+ (which includes original arcs and shortcuts). Note that each original arc has both an arc ID and a shortcut ID, and they are not necessarily the same.
To translate individual shortcuts into their constituent arcs, a table “shortcuts” may be used that has three columns (sid, aid, aseq), where “aid” is the “aseq”-th arc on shortcut “sid”. A shortcut has one row in the shortcuts table for each arc it contains.
Additional fields may be used in each label. Extra columns are added to the forward table (in addition to node, hub, and dist): phub represents the parent hub (the predecessor of hub on the path from node in G+), and sid represents the ID of shortcut (or arc) from phub to hub. The backward table may be augmented in a similar way: phub represents the successor of hub on the path to node in G+, and sid represents the shortcut (or arc) from hub to phub. In both tables, phub and hub are undefined for rows where hub=node.
With these tables in place, an s-t query can be implemented in three stages, as described with respect to
At 1210, a query is run similar to Algorithm 1. Instead of finding just the meeting hub of the s-t path, however, it also returns the phub and sid fields in the corresponding rows of the forward table and the backward table.
At 1220, a temporary table “spath” is built with the sequence of shortcuts on the s-t path P+. Each row has two columns: sid represents a shortcut, and sseq is an integer indicating the relative order of this shortcut within P+. If shortcut sa appears before sb in P+, the row representing sa has a lower sseq than the row representing sb.
The spath table may be built one row at a time. Suppose x is the hub responsible for the s-t path. First, add to the spath table the shortcuts in the subpath of P+ between s and x by following parent pointers in Lf(v), represented by phub and sid in the forward table. This can be done in SQL with a WHILE loop. Since this will give shortcuts in reverse order, assign decreasing sseq values to them: −1, −2, −3, . . . . Then do the same for the shortcuts in the subpath of P+ between x and t. In this direction, following parent pointers provides the shortcuts in the right order, so increasing sseq values (e.g., 1, 2, 3, . . . ) are assigned to the shortcuts. Note that the shortcuts in the x-t subpath have higher sseq than the shortcuts in the s-x subpath.
At 1230, each individual shortcut in P+ is expanded into the corresponding sequence of arcs. This may be performed by joining spath (which was just computed) and shortcuts on column sid, ordering the resulting rows by sseq and aseq. The final table will contain the IDs of the arcs on the shortest s-t path in order. At 1240, the shortest path may be determined from the final table and outputted.
The label-based approach can be extended to enable a rich set of spatial queries. It can handle standard nearest neighbor queries (such as finding the closest gas station), as well as more sophisticated ones (such as finding the ten closest fast food restaurants that accept credit cards). Information describing potentially sophisticated subsets can be precomputed using the full expressiveness of SQL and stored in the database like regular labels. This enables efficient SQL implementations of both straightforward and sophisticated queries related to these precomputed subsets.
Embedding distance oracles within a database enables a rich set of features. Distances between any two vertices can be used within arbitrary SQL queries to filter or rank the output. In particular, with distance oracles points of interest (POI) (also known as nearest neighbor) queries can be implemented to find the k closest locations that satisfy a certain constraint. For example, one might want to find the k closest fast food restaurants that accept credit cards. Hub labels can be used as a black-box distance oracle, with the added benefit of being exact and more efficient.
The POI problem can be formulated as a variant of the one-to-many problem: find the shortest path between a source s and a preselected target set T (the POIs). It has been shown that, on road networks, one can do better than repeatedly calling a distance oracle for each element of T. The known bucket-based approach can quickly extract and rearrange information about T from the CH preprocessing data, leading to much faster queries.
It may be shown that the bucket-based approach, combined with hub labels, leads to faster algorithms. Furthermore, these algorithms can be implemented with relational database operators (e.g., SQL). An implementation using points of interest is provided herein as an example, along with two other applications: via points and ride sharing. More elaborate queries may also be implemented with the relational database operators.
Consider the scenario where a large number of queries (from different sources) is to be made using the same set of points of interest. This is the common “store locator” feature of many web sites (e.g., users need the closest branch of a coffee shop or the three closest ATMs of a particular bank). In such cases, extract from the backward table a table “poilab” containing only the relevant rows—those where node contains the POIs that are of interest. This can be done using a standard JOIN with the table representing the POIs, for example. Queries can now be run using the poilab table instead of the backward table, as shown in Algorithm 2:
Algorithm 2:
There are only minor differences relative to Algorithm 1, besides the use of the poilab table. The technique returns k distances, each with the POI responsible for it. The GROUP BY operator is used to make sure only the best hub is considered for each potential POI. Without it, multiple paths to the same POI may be returned using different hubs.
Because the poilab table is much smaller than the backward table, better locality is obtained. More locality may be obtained by indexing the poilab table by hub: this allows the query engine to skip rows containing hubs that do not appear in Lf(s) (the forward label of the source s).
The bucket-based approach does (outside databases) create a separate bucket for each hub in the (potentially large) target set, but queries only need to access buckets that represent hubs in the (much smaller) forward label. This approach was originally developed to solve the one-to-many problem: computing the shortest path from s to all points of interest in poilab. It can be solved with a variant of Algorithm 2 without the TOP k operator.
Having this algorithm within a database allows it to be modified to answer more involved queries. One can include more conditions in the WHERE operator of Algorithm 2, for example. For example, if poilab represents all restaurants, one can add a restriction that only those serving Italian food should be considered.
If the poilab table represents all acceptable points of interest with no additional constraints, queries can be accelerated further when k (the maximum number of points of interest a user may ask for) is known in advance. When building the poilab table, keep only the k rows with the smallest distance (“dist”) values for each distinct hub h. Additional rows cannot possibly be part of the final solution for any source s: among paths that use h, the first k entries dominate the others. If k is small relative to the number of POIs, removing the unnecessary rows speeds up the queries not only because it saves comparisons (for a given hub, fewer rows must be tested), but also by improving the locality of queries.
Additional improvements are possible for k=1, when it is desired to find the closest POI. Because each hub appears at most once in poilab, it may be made a primary key, eliminating the need for a clustered index and for the GROUP BY operator. In this case, one can think of poilab as a superlabel: this is a label one would obtain if all points of interest were conflated into a single vertex.
The POI queries can be extended to another problem involving via points, such as the best via point problem. In the best via point problem, one wants to go from s to t but wants to stop at another location (e.g., a post office) on the way from s to t. It is not mandatory that a stop is made at a particular location (e.g., which particular post office), but the overall travel time is to be minimized. So a determination is to be made which candidate location x minimizes dist(s,x)+dist(x,t). The best via point problem has numerous applications and can be solved using the techniques described herein.
At 1330, Algorithm 3 (below) is run, which is similar to a standard POI query, but considers two paths at once for each potential via vertex (POI) x: from the source to x and from x to the target. Algorithm 3 returns the best via vertex together with the total travel time. At 1340, the best via vertex and the total travel time may be outputted, e.g. to the user. To retrieve the best k via points, replace SELECT TOP 1 by SELECT TOP k, and add a GROUP BY vialabF.node statement.
Algorithm 3:
The techniques described herein can be used to solve the ride sharing problem which tries to match queries (people looking for a ride from an origin s to a destination t) to offers (drivers offering rides with origin s′ and destination t′). Given a new query, the goal is to find the offer that minimizes the (absolute) detour, given by dist(s′,s)+dist(s,t)+dist(t,t′)−dist(s′,t′).
Similar to the via point application, at 1420, all rows are extracted from the forward table where forward.node equals offers.source into a table “offlabF”. However, the column node is replaced by id and filled with the corresponding identifier from offers. A table “offlabB” corresponding to the backward table and backward.node is built analogously at 1430. These tables may be used to determine the best offer for any ride (s,t) at 1440, e.g., using Algorithm 4 below. This approach can be extended to include additional constraints, such as departure time, number of passengers, or amount of cargo.
Algorithm 4:
Numerous other general purpose or special purpose computing system environments or configurations may be used. Examples of well known computing systems, environments, and/or configurations that may be suitable for use include, but are not limited to, PCs, server computers, handheld or laptop devices, multiprocessor systems, microprocessor-based systems, network PCs, minicomputers, mainframe computers, embedded systems, distributed computing environments that include any of the above systems or devices, and the like.
Computer-executable instructions, such as program modules, being executed by a computer may be used. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. Distributed computing environments may be used where tasks are performed by remote processing devices that are linked through a communications network or other data transmission medium. In a distributed computing environment, program modules and other data may be located in both local and remote computer storage media including memory storage devices.
With reference to
Computing device 1500 may have additional features/functionality. For example, computing device 1500 may include additional storage (removable and/or non-removable) including, but not limited to, magnetic or optical disks or tape. Such additional storage is illustrated in
Computing device 1500 typically includes a variety of computer readable media. Computer readable media can be any available media that can be accessed by computing device 1500 and include both volatile and non-volatile media, and removable and non-removable media.
Computer storage media include volatile and non-volatile, and removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data. Memory 1504, removable storage 1508, and non-removable storage 1510 are all examples of computer storage media. Computer storage media include, but are not limited to, RAM, ROM, electrically erasable program read-only memory (EEPROM), flash memory or other memory technology, CD-ROM, digital versatile disks (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other medium which can be used to store the desired information and which can be accessed by computing device 1500. Any such computer storage media may be part of computing device 1500.
Computing device 1500 may contain communications connection(s) 1512 that allow the device to communicate with other devices. Computing device 1500 may also have input device(s) 1514 such as a keyboard, mouse, pen, voice input device, touch input device, etc. Output device(s) 1516 such as a display, speakers, printer, etc. may also be included. All these devices are well known in the art and need not be discussed at length here.
It should be understood that the various techniques described herein may be implemented in connection with hardware or software or, where appropriate, with a combination of both. Thus, the processes and apparatus of the presently disclosed subject matter, or certain aspects or portions thereof, may take the form of program code (i.e., instructions) embodied in tangible media, such as floppy diskettes, CD-ROMs, hard drives, or any other machine-readable storage medium where, when the program code is loaded into and executed by a machine, such as a computer, the machine becomes an apparatus for practicing the presently disclosed subject matter.
Although exemplary implementations may refer to utilizing aspects of the presently disclosed subject matter in the context of one or more stand-alone computer systems, the subject matter is not so limited, but rather may be implemented in connection with any computing environment, such as a network or distributed computing environment. Still further, aspects of the presently disclosed subject matter may be implemented in or across a plurality of processing chips or devices, and storage may similarly be effected across a plurality of devices. Such devices might include PCs, network servers, and handheld devices, for example.
Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are disclosed as example forms of implementing the claims.
This application is a continuation-in-part of pending U.S. patent application Ser. No. 13/076,456, “HUB LABEL BASED ROUTING IN SHORTEST PATH DETERMINATION,” filed Mar. 31, 2011, the entire content of which is hereby incorporated by reference.
Number | Date | Country | |
---|---|---|---|
Parent | 13076456 | Mar 2011 | US |
Child | 13287154 | US |