Repository navigation
Conversation
Serve single_source_dijkstra_path_length, multi_source_dijkstra_path_length and dijkstra_path_length with one vector of lengths relaxed from every source at once, as the all-pairs kernel relaxes a row; a walk to a target goes no farther than its length. Each dict holds the sources as given, at the integer 0, and then the other nodes by increasing length. NetworkX's checks come in its order and with its messages. Negative and NaN weights are left to NetworkX, as for all pairs, and that check is kept with the converted graph, since NetworkX's own loops ask for one source at a time. A target that is not hashable is declined. On the automatic path should_run leaves the three to NetworkX. Its walk reads each edge about once, as a conversion does, and with the conversion counted NetworkX was faster on graphs of 1e5 edges and on most of 1e6. Called with this backend, or on its graphs, they are served. When NetworkX runs shortest_path_length, its weighted forms call them by name and so go where they go; shortest_path_length itself is not served here.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 30-dijkstra #153 +/- ##
===============================================
+ Coverage 93.08% 93.27% +0.18%
===============================================
Files 183 183
Lines 11525 11892 +367
Branches 1310 1354 +44
===============================================
+ Hits 10728 11092 +364
- Misses 545 547 +2
- Partials 252 253 +1 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
single_source_dijkstra_path_length,multi_source_dijkstra_path_lengthanddijkstra_path_length. Each gives NetworkX's nodes, integer lengths exactly and float lengths within rounding, or NetworkX's error with its message. On the automatic pathshould_runleaves them to NetworkX, which was faster on most graphs once the conversion is counted; called withbackend="graphblas", or on this backend's graphs, they are served. There they are much faster on random graphs once the conversion is cached, and slower on grids: 2 to 4 times NetworkX's time from one source or for a pair, even with the conversion cached.dijkstra_path_length, a walk longer than the length found to the target is dropped, so the rounds stop there.1.0for the node1stays1.0, as in NetworkX. NetworkX orders equal lengths by its heap, which is not reproduced.sourcesraiseValueError("sources must not be empty"); a source not in the graph raisesNodeNotFound("Node 7 not found in graph"), for the first one given; a missing or unreachable target raisesNetworkXNoPath("Node 7 not reachable from 0"). A source that is its target gives 0 before anything is walked, whatever the weights.single_source_dijkstra_path_lengthpasses{source}on, as NetworkX does, so a source that is not hashable raises NetworkX'sTypeError. A generator of sources is spent by the check and gives{}, as in NetworkX.NotImplementedErrorafter converting, and NetworkX answers them underbackend_priority. The check is kept with the converted graph, since NetworkX's own loops, such as itsall_pairs_dijkstra_path_length, ask for one source at a time. A self-loop of +inf on an undirected graph is declined too, since NetworkX's matrix holds NaN there; on a directed graph it is served._adj, and a cutoff that does not compare as a float does. Also a target that is not hashable: NetworkX compares it with each node it reaches before its lookup raises.np.float32; the values are equal.gnm_random_graph(1e5, 1e6)it took 0.55 s against NetworkX's 0.86 s with float weights, 0.65 s against 0.68 s with integer weights 1 to 10, and 0.71 s against 0.39 s with no weight attribute; on a 707 by 707 grid with float weights, 2.4 s against 0.64 s. The conversion is most of that: with it cached, the random graph took 0.055, 0.037 and 0.014 s, 4 to 6 percent of NetworkX's time, but the grid still took 1.85 s, about three times NetworkX's 0.64 s; on a 224 by 224 grid it was about twice NetworkX's time. The backend is slower on grids, cached or not. It takes a round per edge of the paths it relaxes, and on that grid the least path to the far corner has at least 1412 edges. Ten sources at once cost what one does, here as in NetworkX (0.69 s against 1.09 s on the random graph, 1.14 s against 0.91 s on the grid), so serving onlymulti_source_dijkstra_path_lengthwould not help. A pair stops at its target in both: on the random graph 0.53 to 0.78 s converted and 0.004 to 0.043 s cached, against NetworkX's 0.10 to 0.51 s. A second run, at load 11 to 14, agreed but for random float weights on 1e5 edges, which came out even there (0.87 to 0.97 of NetworkX's time).should_runleaves the three to NetworkX whenever it would convert a NetworkX graph, which is the only time NetworkX asks it; nothing cheap at that point tells a random graph from a grid. Called withbackend="graphblas", on this backend's graphs, or in NetworkX's test mode, they are served.shortest_path_length: its weighted forms withmethod="dijkstra"callsingle_source_dijkstra_path_length(from a source, or to a target, on the reversed graph if it is directed) anddijkstra_path_lengthby their dispatched names, so it goes where they go. On the automatic path that is NetworkX, byshould_run; a test setsshould_runaside and shows the inner calls served. Called withbackend="graphblas"or on this backend's graphs,shortest_path_lengthitself raises NotImplementedError, as does any name this backend does not serve.Dispatcher.should_runand thenxapi._utils.should_rundecorator are line for line the ones 50-spanning-trees adds, and the two branches merge without a conflict.Stacked on #133.