• Aucun résultat trouvé

k-Shortest Path Algorithms

Dans le document [ Team LiB ] (Page 187-192)

Figure 4-13. Why regular Dijkstra fails with negative edges and how Bhandari's modification overcomes this

4.5 k-Shortest Path Algorithms

It is easy to see that if one can find the shortest route through a graph one could also build up a succession of routes with increasing length. By removing or disqualifying the edges of the shortest path and repeating the process one would find the next-shortest path that does not use any edges of the first path, and so on. The family of successively longer paths thereby obtained is an example of one notion of k-shortest paths (ksp).

There is an extensive literature on slightly different notions of k-shortest paths, each of which relates to different problems. Topkis, for instance, is interested in a set of k-shortest paths through a network of trunk groups [Topk88] . Sheir gives an algorithm for k-shortest paths where paths may contain loops as a means of enumerating a succession of increasing path lengths through a graph, for applications in project scheduling etc. [Shei76]. Other variants of k-shortest paths derive their differences from issues such as whether they pertain to simple graphs or multigraphs and whether the k-successive paths are disjoint in certain ways or simply distinct. A classification system and notes on dozens of different k-shortest path algorithms is contained in [Grov89]. Our purpose now is not to survey that whole domain, but to flag for readers that the simple phrase "k-shortest paths" is by no means a unique specification. There are, however, three particular classes of ksp algorithm that are of interest here:

k-shortest link-disjoint paths: This is the set of k-successively longer paths in a multigraph where paths may share spans among the set of routes they take, but are disjoint at the link level (i.e., any one link on a span is an element of only one path at most), and the set of paths as a whole respects the finite capacity on every span of the network.

1.

k-shortest distinct routes: This is the set of routes over the spans of a network where each is merely distinct from the others and they can be ranked in increasing order of either geographical or logical (hop count) distance.

2.

k-shortest span-disjoint routes: This is the set of routes over the spans of a network where each is span-disjoint from the others and they can be ranked in increasing order of either geographical or logical (hop-count) distance.

3.

In all cases we are interested only in non-looping paths so for simplicity this is not included in each of the criteria stated, nor do we restate this in the subsequent discussion of ksp. As an example to work with in developing these ksp concepts let us reconsider Figure 4-11 as a simple graph where the edge weights given are now interpreted as distances. In this case ksp criteria 1 produces:

Shortest path: A-B-C-G-H (distance = 14)

Second path: A-D-F-H (distance = 25)

Third path: infeasible: graph is disconnected through cut {(A-B), (B-C), (D-F), (G-H)}.

But because we are working with a simple graph in this case there is no distinction between a route and a path. If we interpret the simple graph as representing a transport network with non-zero link quantities on every span, then this result is also an instance of the

k-successive span-disjoint routes. Not surprisingly the graph becomes disconnected quickly due to insisting on span disjointness among the succession of routes. One use for this set of routes is as a simple (but non-optimal) way of finding a span-disjoint route pair for a 1+1 APS setup or more generally to arrange a k-way split of the demand flow between a pair of nodes over mutually span disjoint routes.

Let us next consider the set of k-shortest link-disjoint paths in a multigraph (criteria 1 above). This path-set is one that can be efficiently used in mesh-restorable networks or for closely modeling the behavior of a distributed span-restoration algorithm. To provide an example of this type of ksp we now let the edge weights in Figure 4-11 become the span capacities; that is, the number of unit-capacity links in parallel on each span. At the same time, for simplicity we will shift our measure of path length to that of logical hop count so that shortest and next shortest routes will be more apparent by inspection. (Note, however, that with hop length there can be more than one

equal-length route existing at each increasing hop length.)

Figure 4-14 steps through the process of developing this particular ksp path-set. In (a) we note that the shortest route is of length 3 and that there are actually five different 3-hop routes from A to H in the graph. In such cases one can apply an arbitrary rule or simply leave it up to the internal order of execution of a program (such as follows) to determine the order of claiming paths off of the equal length routes.

Let us consider capacity on the route A-C-G-H first. On this route we find span capacities of 6, 3, 6 respectively so the feasible number of paths to follow this route is min(6, 3, 6) = 3 and span C-G is effectively removed from the graph at this point since all of its capacity is used.

The updated remaining capacities on other spans are marked by *. Next, in (b) seven paths are realized over route A-D-F-H, seven being the limit set by the capacity of span A-D. The process goes on until no more paths are feasible on any route. The graph of remaining capacity is always disconnected at this stopping state. In practice it is often one of the end nodes that is simply isolated, as is the case here (node A), when all of its local egress capacity is consumed.

Figure 4-14. Illustrating the concept of k-shortest link-disjoint paths in a capacitated graph.

As mentioned, when working with hop count as the measure of length, there may not be a single unique route of each successive length, so the ksp outcome is dependent on the internal program details of choosing over equal-hop-length routes. To illustrate, on Figure 4-14 we also show the outcome of another of the possible sequences that could be followed. In this case it makes no difference to the total path count, but the path details differ. A detailed study has shown in fact that although the path construction details vary with the order taken, it is quite rare for this process to yield a total number of paths that is less than the theoretical maximum number of such paths (the

"max-flow" measure below) as a result of the order-dependency in the relatively low average degree that characterizes transport networks [DuGr94].

This dependency of the path-set details only arises from the use of logical hop count as a distance measure. With unit-hop totals as the cost measure, different routes can often have exactly the same total costs, so which is chosen then depends only on the execution order or other particulars of the program implementation. In practice, if span distances are real-valued (or, say, integer but resolved to within 1 km lengths), then every path length usually has a unique distance total of its own and the "successive length" hierarchy defined by ksp becomes uniquely defined. Highly symmetric networks or contrived assignments of real-valued distances to edges can, of course, be devised as counter-examples to this—where two paths will also have the same real-valued length—but in practice which typical variations in span lengths drawn from the real-world, or if a small random value is added to each spans's distance, the ksp flow and detailed path-set construction become uniquely defined and repeatable.

We summarize with the following pseudo-code of the k-shortest link-disjoint paths algorithm. The approach is to run a single-shortest path algorithm in a simple graph abstraction of the multigraph at each stage. As long as a span in the multigraph has unused capacity remaining (edge weight not zero) then an edge is retained in the simple graph to represent the possibility of a route that traverses that span.

procedure ksp(capacitated graph G, sources,targett) {

The complexity of this procedure can be stated initially as O(kn2

) where k is the number of distinct routes in the resultant path-set and n2 arises from each call to the basic shortest path algorithm. But k is really an output, not an input to the problem. So to make a proper statement of computational complexity one needs to somehow bound k. One approach is to say k is at most the number of distinct routes between source and target. That however is an extremely loose bound as there are O(2S

) distinct routes in the worst case. S is the number of spans, hence this is also the same as O(2N

). If an explicit hop limit, H, is applied to limit the length of any route considered this improves the bound on k to O(2H

) but this is still very high. The reason these are wildly high bounds for k is they do not reflect the elimination of remaining distinct route possibilities as spans are exhausted at each iteration. A better bound for k is based on recognizing that at termination of this procedure the network is always disconnected. In fact, the process usually discovers a minimal-capacity cut-set of the graph. Since there can be at most S spans in any cut-set, it follows that k is O(S): that is, that in the worst case k=S iterations would be required to disconnect the graph, reaching the stopping condition. Thus the procedure above has a theoretical time complexity of O(Sn2

) which is also equivalent to O(n3

) because S is related to n through the network average node degree. Additional optimizations can, however, lead to an extremely fast ksp algorithm that is theoretically and experimentally O(nlogn) [MaGr94].

Let us now consider ksp criterion 2 on the list above—that is; k-shortest distinct routes. First let us illustrate the set of such routes on our example network, so as to contrast this criterion with that of disjoint routes and k-shortest paths. Figure 4-15 again uses the network of Figure 4-11 and A, H as the end-nodes. In Figure 4-15(a) the complete set of (fully) disjoint routes at all lengths is shown. In (b) the set of distinct routes that exist only at hop lengths of 3 and 4 are shown. Figure 4-15(c) shows the additional distinct routes that exist at 5 and 6 hops. The main point is that there are vastly more distinct routes than there are disjoint routes. A distinct route only has to differ in one span from previously enumerated routes, whereas each disjoint route differs from others in its set on every span on its route. One approach to an algorithm for finding the set of simply distinct paths is to extend the ksp-like aspect of iteration of a single shortest route finding routine on a simple graph, with appropriate span exclusions on each entry. For example if, on the first iteration, the shortest route found is {S1-S2 ... Sm} then subsequent iterations would find the remaining shortest route first with S1 excluded, then with S2 excluded, and so on. But it can be seen then that each of the latter paths is itself then a template for a series of further exclusions and shortest route finding calls. In other words, it leads to a search tree for all distinct routes that is effectively a depth-first search (DFS) rooted on each span of the initial shortest route. As a practical matter, therefore, it is easier to obtain the k-shortest distinct routes by length sorting the outcome from an all-distinct routes routine, which is based on a general DFS, and is a separately required capability in any case. In other words, rather than develop an extension to ksp to find the k-shortest distinct routes, we will move on to a DFS for all distinct routes. With only a length sort to be added this will also provide the k-shortest distinct routes.

Figure 4-15. k-shortest disjoint and distinct routes (up to six hops) in the example network.

4.5.1 All Distinct Routes

The set of all distinct routes on a graph up to a certain hop (or distance) limit, H, is needed in certain problem formulations for mesh network capacity design. As with ksp, our interest is only in non-looping routes. Finding all distinct routes can be a challenging task, however, simply because there are O(2n

) such routes possible between node pairs in a graph of n nodes (and Q(2n

) in a fully connected mesh on n

nodes). More specifically, if we have a network of S spans and are using a hop limit H < S we could expect a bound of .In many planning problems, however, the set of such routes needs to be computed only once for a given topology and may then be stored and used as a sort of database for different optimization studies that need various subsets or filtered selections of routes from the set of all distinct routes for their formulation.

The algorithm for all-distinct routes (equivalently all distinct paths in a simple graph) is a type of depth-first search (DFS) algorithm. This algorithm thus also serves as an example to introduce DFS as a basic method underlying other algorithms to follow. In DFS in general, one starts at a source or root node that is problem-specific. Here, it is one of the end nodes of the node pair between which all distinct paths are desired. From this node one takes an excursion out on any span incident at the source, marking that span as having been visited. At the node thus reached, this is repeated. At each node the rule is to take an unmarked span, mark it, and head further down to a next node if possible. For all distinct routes, whenever the target node is discovered, the process records a route and backs up to the penultimate node in the route. If all spans are marked at that node, it backs up again. At the first such node found during this backtracking, where there is an unmarked span, the DFS search branches down that span and continues as above. Any time the search depth reaches H hops (or an accumulated distance limit) without discovery of the source, or if a loop is discovered in the route, the process also backs up. A potential loop is discovered when the unmarked span currently branched upon leads to a node that is already a parent of the node from which branching just occurred. In this case the span is marked and the branch is not taken. An important detail is that as the process backs up from any node, all spans at the node that it is leaving, except the one to the parent to which it is returning, are unmarked upon departure from the node. This is necessary so that spans that are part of an early route discovery are left free to be incorporated in distinct routes later discovered from different approaches. But the current search path will not be explored any further in that direction. Thus, when a whole region of the search tree is completed, all spans are left unmarked except the one incident on the source from this region. A pseudo-code version of the algorithm follows.

procedure AllDistinctRoutes(graph G, source node, target node) { node := source

} Until node = source and unmarked_spans(source) = null}

procedure StepAhead(done_at_this_node) { done_at_this_node := false

span := next([unmarked_spans(node)]) if span = null {

done_at_this_node := true return

} else {

node :=neighbor(node, span) mark(span)

depth := depth + 1 [route] := [route] + [node]}

return}

procedure Backup { find_parent([route])

unmark([spans(node)] - [(node,parent)]) [route] := [route] - [(node,parent)]

depth := depth - 1 node := parent return}

Figure 4-16 illustrates the DFS operation on the example network of Figure 4-11 (Section 4.3.2) for a hop limit of H = 3. The graph structure of Figure 4-11 is reflected in the DFS search tree structure in that each node (other than the source node) appears at each level

sub-tended by the other nodes reachable from it. The blown up region with numbered arrows shows the sequence of "StepAhead" and

"Backup" operations that explore the branch from the source A having first span (A-B).

Figure 4-16. Operation of the depth-first search to find all distinct routes.

[ Team LiB ]

[ Team LiB ]

Dans le document [ Team LiB ] (Page 187-192)

Documents relatifs