0% found this document useful (0 votes)
41 views10 pages

Paper 1

Algoritmo recorridos mínimos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
41 views10 pages

Paper 1

Algoritmo recorridos mínimos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 10
Journal of Discrete Algorithms 42 (2017) 35-44 Contents lists available at ScienceDirect Journal of Discrete Algorithms www elsevier.comilocataljda Hybrid Bellman-Ford-Dijkstra algorithm. Dover Yefim Dinitz*, Rotem Itzhak Deparment of Computer Scene, Ben-Gurion University ofthe Negev, PB 653, Beer-Sheva 84105, Israel ARTICLE INFO ABSTRACT ‘ay We conse the single-source short paths problem ina aap th paste edge costs eee eae allowed. A hybrid of the Bellman-Ford and Dijkstra algorithms is suggested, improving the Received in revised form 30 October 2016 funning time bound of Bellman-Ford for graphs with a sparse distribution of negative cost ree ages The igor iterstes Dia teves ines witout rental the tentative alu u() a erties. Ak ost 2 erations solve the prob foray vertex reacabe KowousTSCS*CStm the source, there exists a shortest path to it with at most k negative cost edges. Algorithm In addition, a new, straightforward proof is suggested that the Bellman-Ford algorithm rah produces @ shortest paths tree Sportest path © 2017 Elsovier BY. All rights reserved Negative edge 1. Introduction Several basic graph algorithms are widely known from the 1950s~1960s. Although those algorithms have being massively taught at all CS departments all over the world since then, it turns out that new aspects of them can still be revealed. We present two such results on shortest paths algorithms: a new, combined algorithm and a new correctness proof for building the shortest paths tree. In what follows, we say “graph” meaning a digraph with edge costs. The input graph is denoted either by G-=(V.E,) or by G=(V, E.c.3) if the source vertex s is fixed. An edge or cycle of a negative cost are called “negative”. When relating to classic results, we usually do not provide references; the reader can refer to any textbook on algorithms, eg. [5]. In this paper, the main goal is theoretic: finding algorithms with better worst case running time bounds, ‘A special kind of innovation is hybrid algorithms: a combination of known algorithms for either solving a new problem or decreasing the time bound for an old one. For example, Dijkstra’s algorithm solves the single-source shortest paths problem, ‘The PERT chart algorithm finds the early time-schedule in a DAG (directed acyclic graph), whose nodes are events and the edges represent the precedence relation between them, via finding longest paths in it 15] (see also (5, Chapter 24.2), The algorithm of [109] combines the PERT and Dijkstra algorithms for finding the early time-schedule in a general graph with precedence relations of AND or OR type at nodes: the PERT chart and the single-source shortest paths problems are boundary cases of this problem. Surprisingly, though these algorithms seem quite different, the hybrid algorithm combining them is natural, and its running time is the sum of running times of PERT and Dijkstra." This paper presents a new, hybrid algorithm for finding shortest paths from a source 5 in a graph G with general edge costs. It combines Bellman-Ford and Dijkstra algorithms, and will be called Bellman-Ford-Dijkstra (BFD). Recall that both original algorithms traverse the graph edges, executing the update (called also “relaxation” or “relabeling”) of the tentative * Corresponding author. E-mai ataresses: dni og.acil(¥ Din), ocem thakeeymaicom (R. Hanak) "A similar algoritnm, formulated inthe language of some grammar problem, was sy pf‘ orgy 101016), 54a201701.001 1570-8667/© 2017 Eisevier BY. Al rights reserved 6 Diniz R ito /Joural of Discrete Algorithms 42 (2017) 35-44 distance function d on vertices. Dijkstra works for the non-negative edge costs case. It is a search type algorithm: it makes just a single traversal on all vertices and edges reachable from s, in a greedy order. For graphs with negative edges, the Bellman-Ford algorithm is used. The basic Bellman-Ford works in rounds, each being a simple loop of relaxations on the graph edges, in any order. It finds the shortest path costs to the vertices and a shortest paths tree in at most r+ 1 rounds, where ris the minimal integer such that for any vertex reachable from s, there exists a shortest path from s to i¢ containing at most r edges (in other words, r is the minimal possible depth of the shortest paths tree). If the input graph contains a negative cycle reachable from s, shortest paths to some vertices do not exist, and Bellman-Ford detects that in |V| rounds. Otherwise, r as above is at most [V| — 1. Since a single round cost is Q({E|). the implied running time bound is O(\V||E)). Notice that it is higher by an order of magnitude than the Dijkstra time bound O(\E| + IV Hlogiv p? Our goal is decreasing the (worst case) round number bound of Bellman-Ford. We achieve that at BFD by running Dijkstra at each Bellman-Ford round, without re-initializing values of d at vertices. This is a legal implementation of Bellman-Ford, since Dijkstra is just a smart loop of relaxations. We show that this hybrid works, despite the common know!- ‘edge: "Dikstra’s algorithm cannot handle graphs with negative edge costs".’ Our bound for the number of BFD rounds is K+ 2, where k isthe minimal integer such that for any vertex reachable from s, there exists @ shortest path from s to it containing ‘at most k negative edges. This is a substantial improvement over the Bellman-Ford bound for graphs with a sparse disper- sion of negative edges. (It should be mentioned that the running time of a BFD round slightly increases from O(\E|) to O(/E| +1V ogiV).) That is. the time bound of BED improves upon that of Bellman-Ford in the in-between cases when negative edges exist, but are sparsely dispersed in the graph. A motivation of such input graphs comes naturally from classic, seemingly purely non-negative problem settings, where there are a few special edges in the network. For example, consider the navigation problem of finding a shortest route in a road map. Suppose that a driver chooses a few objects of interest, such as a beautiful view or a good restaurant, and assigns a route cost reduction to visiting each of them. Then, the updated road map can acquire a few negative edges. It should be mentioned that there is a wide experimental study on practical shortest paths algorithms, whose running time for reasonable benchmarks is drastically lower than that defined by the known worst case bounds. For example, see [1.3] and references therein. In (3, Section 5.3] a variant of the Bellman-Ford algorithm is mentioned, where at each round the edges are traversed in the order of the values of function dat their initial vertices, which is the same order as that of BFD. However. that variant was rejected there from consideration, for practical running time reasons. The correctness proof of BFD is a generalization of a widely known correctness proof for Bellman-Ford. In an auxiliary statement (Lemma 2.2), we analyze the general behavior of Dikstva algorithm in graphs with negative edges, Hence, BED with its proof may become an instructive supplement to a university course in algorithms. Remark. After becoming acquainted with the Bellman-Ford-Dijkstra algorithm, Allan Borodin noted that BFD iterates the greedy Dijkstra algorithm in order to extend its applicability. Generalizing the situation, he asked what can we prove for 2 general iterated greedy algorithm? For greedy algorithms, some general lower bounds were proved in (2.6). For iterated greedy algorithms, he conjectured that even the analysis of the two iterations case would be difficult:* The paper is composed as follows. Section 2 describes the Bellman-Ford-Dijkstra algorithm. Section 3 analyzes BFD. In Section 4, we discuss the robustness of BFD to some known implementations of BF. Section 5 describes and analyzes versions of BFD adjusted to some variants of the Dijkstra’s algorithm implementing its rounds. In Section 6, we show the tightness of the bounds developed for BFD, and discuss a speeding up idea. In Appendix A, We suggest an improvement of the classic analysis of relaxation-based algorithms. A new, straight forward proof is presented that any such algorithm running on any graph produces a shortest paths tree. The simpli- fication is achieved by considering the set of back-pointers only from the vertices, for which the tentative distance is already equal to the true one. It is shown directly that the shortest paths tree propagates together with the true dis- tances, 2. Hybrid Bellman-Ford-Dijkstra algorithm, Recall the basic Bellman-Ford (BF) and Dijkstra algorithms, working on a directed weighted single-terminal graph (V, E,c,3), Recall that d(v) denotes the tentative distance from s to v, and 77(v) denotes the vertex that gave to d(v) its current value via edge (77(v). ¥). 2 With the additional assumption thatthe edge lengths are Integers bounded below by —N < —2, Goldberg [11] suggests an algorithm with the (00g N/IVIIE) time bound, or this problem, 9 Johnson in (12| suggested a astral generalization of Dikstas algorithm fora graph with negative edge cots, which however was shown aot to run in polynomial time *" Personal communication. "Dine Beak Journal of Discrete Algrtns 422017) 35-44 Initiatization div) —00, for all ve V (Vv) nil, for all ve V dis) <0 Relax(uy) if d(u) +ctu, v) opt(u) for dll u eV. Let P= (5, .., Vo, ..-.¥'.¥) be a shortest path tov. such that its segment P from vq to v' contains no negative edge. If (vo) already equals opt (vo) at the moment of scanning vo, then div) will equal opt(v) af the end of Dijkstra_scan. “2. nthe case when vo = and the initial function d is as after Initialization, the statement of item 1 holds even i he fist edge of Pisnegative. Proof. Let P =(vo. v1 v). For illustration, see Fig. 1 For providing an intuitive understanding to the reader, we first prove for the restricted case. when all edges of P have positive costs. Let us prove by induction the following statement (*): The vertices v; « P are scanned with d(v1) = opt(v,) in the Increasing order of z As the basis, we prove that vo, with dv) = opr(vo), is scanned first on P. In the case of item 2, vo is scanned first, since d(s) =0 is the single finite value of d. Consider now the case of item 1. Since any prefix of P is an optimal path to its end-vertex, function opt strictly grows along P, by the assumption on positive edge costs. Therefore, by Fact 3.1(1), for any Vi.vj, F< J, always holds opt(vi) < opt(w) 1, d(v;) = opt(v)) also holds, since vj has already been scanned with d(v;-1) = opt(vi-1) (by the induction assumption). Note that d(v;) =opt(vi) 1, let e” be the last negative edge along P distinct from e, We denote by P the part of P between e” and e, excluding &” and e. Denote the first vertex on P by vo. (For illustration, see Fig. 1.) Observe that neg(va) =k — 1. Hence, dvo) = opt(vo) after k rounds, by the induction assumption. Otherwise (k= 0), we define P to be P. Then, vo=s, and d(vg) = opt(vo) before the first round, by initialization. Consider the first round k’ =k-+ 1, where vo is scanned with d(vo) =ope(vo). By Lemma 3.2, dv} of that round. Hence, d(v) = opt(v) at the end of round k-+ 1, as required. opt(v) at the end Theorem 3.4. If there is no negative cycle reachable from s in G, BFD correctly computes the shortest path costs forall v € V and the shortest paths tree nat most neg(G) + 2 rounds. Otherwise, it reports that such a negative cycle exists. Proof. By Proposition 3.3, if there is no negative cycle reachable from 5, d values equal opt values at all vertices after neg(G) + 1 rounds of BFD. By Fact 3.1(2), at the round numbered at most neg(G) +2, there is no change of d values, and BED stops. Since neg(G) <|V| — 3, this should happen not later than after round || — 1 Since Dijstra_scan executes Relax on all edges reachable from s, it may be considered a specific implementation of Plain_scan. Therefore, BFD may be considered a specific implementation of the generic BF. Since BF is known to produce the shortest paths tree from s, this holds for BFD as well. If there exists a negative cycle reachable from 5, then by Fact 3.1(3), even at round |V|—1 there would exist an edge (u,v) reachable from § with d(u) + c(u,v) . |V|—1> of BED may be AA trivial such bound is the total number of negative edges in G (however, it might exceed |V| —1). Let us show some additional bounds, which may be easily computed at the preprocessing stage. Let #neg(H) denote the minimum of the number of vertices with outgoing negative edges (excluding s) and the number of vertices with incoming negative edges, in a graph H. By definition, we have neg(H) < #neg(H). Corollary 3.7. The stopping condition < V| — 1 > of BED may be replaced by . Remark: The arc-fixing algorithm suggested in (3, Section 5.5] iterates Dijkstra executions on modified versions of G. It is stated there (with no proof) that it solves the problem in at most #neg(G) Dijkstra runs. A wide analysis of practical negative cycle detection may be Found in [3 ey Diniz R ito /Joural of Discrete Algorithms 42 (2017) 35-44 For a graph G which is not strongly connected, let us generalize the above bound to the following bound BS°°(G) for neg(G), which can be computed by a linear time preprocessing. We begin with computing DAG G*°° of the strongly connected components (SCCs) of G (e.g., by the Kosaraju-Sharir algorithm); the edge between two SCCs is called negative if there exists a negative edge between their vertices in G. We give to each SCC C weight #neg(G(C)), where G(C) is the sub-graph induced by C. We define the weight of a path in GC to be the sum of the weights of its vertices plus the number of negative edges in it. We compute the maximal weight of a path from the SCC of s in GS¢° (it is well known. how to do this using a topological sort). We denote that weight by BS“ (G). It is easy to see that neg(G) <= BS°°(G), thus implying: Corollary 3.8. For any graph G, the value of 85C°(G) can be computed in a linear time. Then, the stopping condition < Of BED may be replaced by < i= BS"(G) +2 >. y|—1> Comment: The results of this subsection are slightly improved in part 2 of Section 5. 4, Robustness of BED to implementations of BF 1. In practice, it may be reasonable to check the existence of a negative cycle during the BF run, and stop if one is detected, One such checking method is “subtree disassembly” [17] (see also (3). Any time when Refaxiw, v) decreases the value of d(v), subtree disassembly traverses the subtree of the back-pointers tree rooted at v, looking for u. During this traversal, it removes all vertices x4 v in this subtree, by setting 77(x) —nil, as if x has not been reached yer. Note that any such removed vertex x currently has a non-optimal value of d(x) > opti) Let us show that the basic version of subtree disassembly may be incorporated into BFD as itis, Removal of back-pointers is safe for BFD, since Dijkstru_scan does not depend on back-pointers. Removal of certain vertices from the consideration (which fastens BF in practice) might be unsafe for the correctness of BFD, in general. Pay attention that the correctness of all results of Section 3 is based on Lemma 3.2. The proof of that lemma deals with scanning of vertices x with the optimal values of d(x) = opt(x) only. Therefore, removal of vertices with non-optimal values of d(x) made by subtree disassembly does not contradict the correctness of Lemma 3.2, and thus of all the results of Section 3. The additional property of the advanced versions of subtree disassembly and of other negative cycle detecting methods considered in [3] is that they change the order of scanning vertices “on-fly", using concrete states of the execution of the used negative cycle detecting method. Since the arising scanning order ought not to be by non-decreasing values of d, thus contradicting Dijkstra_scan, they are incompatible with BED. 2. The following basic speedup modification is widely used in practical implementations of BF. It groups Relax(u, v) executions to bunches with the same vertex u, called “scanning wu". When scanning u, it stores the value of du). At each round of BF, not all vertices are scanned. Scanning of vertex w is skipped if its current d value equals its d value stored at the last time (in such a case, scanning w is useless). Although the worst case bound of this modification is the same as that of the basic BF, it is known that in practice, this modification significantly decreases the running time. Since grouping Relax’s as above is built-in in Dijkstra_scan, it is straightforward to modify Dijkstra_scan and BFD accord- ingly. Since each skipped vertex scanning causes no change in the data, each round of the BED modified as above produces the same result as that of the basic BFD. Therefore, all the correctness and running time statements proved for BFD remain valid for this modified version. However, the advanced versions of the considered modification changing the order of scanning vertices (see €. [3]} ate incompatible with BFD. in general, by the reason as in part 1 of this section. 5, Adjusting BFD to variants of Dijkstra Let us study how certain implementations and variants of Dijkstra may be used for implementing a BFD round in order to accelerate it, Accordingly, the factor |F| +|V|log|V| in the time bound of Theorem 3.5 could be changed to the time bounds of those implementations/variants. 1. Note that some implementations of Dijkstra rely on non-negativity of edge costs, either explicitly or implicitly, and hhence might work improperly if there are negative edges in G. In particular, those are implementations using monotone priority queues (see, eg, [4l). For example, consider the basic Dial's implementation [7] (see also [20.8], reinventing it), It uses buckets, achieving the running time bound O(|E| + max{opt(v)} + Cmax). Where Cnax is the maximal edge cost. It is useful if max(ope(V)} and Crux are low. Note that Dial’s implementation traverses the buckets in the increasing order of the key, relying on the known property of Dijkstra to never decrease a vertex key below the value af the key of the currently scanned vertex. However, if edge (u, v), v€V\S, ¢(u. v) <0, is scanned, Relax(u, v) decreases d(v) below d(u). Then, Dial's implementation will simply skip scanning v, thus giving an incorrect implementation of procedure Dijkstra_scan as applied by BrD. Let us suggest an equivalent version BFD-r of BFD, robust to using monotone priority queues in Dijkstra_scan, It runs Dijkstra_scan_on graphs with non-negative edges only. The changes in BFD-r wart. BFD as described in Section 2 are as follows. Denote the set of negative edges in G by E ‘Dine ehakjJoural of Discrete Algorton 422017) 35-44 a ‘© Routines Dijkstra_scan and Plain_scan acquire an additional parameter E, thus getting the edge set to scan via this parameter, instead of using the globally defined set E. 4 The call to Dijkstra_scan, in the do <---> until loop, is replaced by two consequent calls: Distra_scan(E \ E~) and Plain_scan(E~), Theorem 5.1. The BED-r version of BFD is correct, Keeping the round number bounds of Theorem 3.4, whichever implementation of Dijkstra on a graph with non-negative edge costs is used in Dijkstra_scan. Proof. Let us show that the proof of Lemma 3.2 (and thus of Proposition 3.3 and Theorem 3.4) remains valid for BFD-r. It is easy to check that the proof part analyzing the insertion of vertices in P into $ remains fully valid, being now related to the execution of Dijkstra_scan(E \ E-). Consider now the concluding remark on ensuring the equality d(v) = opr(v) via executing Relax(vg, v) after inserting vg into S. It remains valid either by executing it in Dijkstra_scan, if c(vg, v) 2 0, or by executing it in Plain_scan(E~), otherwise. © 2. An anonymous referee suggested an observation leading to an improvement of BFD-r and of Theorems 3.4 and 5.1. Let us change BFD-r to BFD-rs as follows. At a preliminary phase, BFD-rs checks whether there exists a cycle in graph (V. E~), If so, it reports on existence of a negative cycle in G. Otherwise, it computes a topological ordering in graph (V., E~). BFD-rs specifies that executions of Plain_scan traverse the edges in E~ in the topological ordering of their initial vertices. Let us define negs(P) < neg(P) as the number of intervals of consecutive negative edges in P, excluding the first edge of P and the interval including the last edge of P, if any: we define negs(G)

You might also like