given a starting node, return all reachable paths. Once visited, a node is marked as visited and will not take part in a future path.
Arguments
- x
data.frame containing hydroloom compatible network or list as returned by make_index_ids (for down) or make_fromids (for up). The list formats avoids recreating the index ids for every call to navigate network dfs in the case that it needs to be called many times.
- starts
vector with ids from x to start at.
- direction
character "up", "upmain", "down", or "downmain". If "upmain" or "downmain", x must contain sufficient information to construct an upmain and downmain network (see details).
- reset
logical if TRUE, reset graph for each start such that later paths will have overlapping results.
Details
navigate_network_dfs
offers two usage patterns. In the simple case,
you can provide an hy
in which case preprocessing is performed automatically,
or you can do the preprocessing ahead of time and provide index ids. The latter
is more complicated but can be much faster in certain circumstances.
hy
object:
If the function will only be called one or a few times, it can be called
with x containing (at a minimum) id
and toid
. For "upmain" and "downmain"
support, x also requires attributes for determination of the primary upstream
and downstream connection across every junction.
In this pattern, the hy
object will be passed to make_index_ids
called for every call to navigate_network_dfs
and the resulting index ids
will be used for network navigation.
Index ids:
If the function will be called repeatedly or index_ids are available for
other reasons, the index_id list as created by make_index_ids (for
downstream) or make_fromids (for upstream) can be used. For "upmain"
and "downmain" support, the main
element must be included.
Examples
x <- hy(sf::read_sf(system.file("extdata/new_hope.gpkg", package = "hydroloom")))
x <- add_toids(x, return_dendritic = FALSE)
navigate_network_dfs(x, 8893402)
#> [[1]]
#> [[1]]$`1`
#> [1] 8893402 8894170 8893724 8893730 8893736 8893744 8893752 8893766 8893772
#> [10] 8893786 8894304 8894318 8894324 8894332 8894344 8894352 8894354 8894356
#> [19] 8894360 8897784
#>
#> [[1]]$`2`
#> [1] 8893746 8893750
#>
#> [[1]]$`3`
#> [1] 8893748 8893770 8893776
#>
#> [[1]]$`4`
#> [1] 8893784 8893792 8893794 8894306 8893804 8894316 8894320 8893808 8894322
#>
#> [[1]]$`5`
#> [1] 8893788 8894302
#>
#> [[1]]$`6`
#> [1] 8893764
#>
#> [[1]]$`7`
#> [1] 8893742
#>
#>
navigate_network_dfs(x, 8897784, direction = "up")
#> [[1]]
#> [[1]]$`1`
#> [1] 8897784 8894360 8894356 8894354 8894350 8893884 8894204 8893898 8894202
#> [10] 8893894 8894352 8894342 8894338 8894340 8893872 8894456 8894336 8894490
#> [19] 8894494 8894492 8894334 8893864 8893860 8894194 8893858 8893862 8894200
#> [28] 8894454 8893866 8894196 8893870 8894198 8893888 8893874 8893890 8893878
#> [37] 8893876 8894452 8893882 8893880 8893886 8893850 8893844 8894192 8894310
#> [46] 8894312 8894314 8894190 8893828 8893806 8893832 8893840 8893854 8893868
#> [55] 8893846 8893856 8893830 8893826 8893816 8893812 8894444 8893814 8893798
#> [64] 8893820 8893838 8893834 8893836 8893852 8893848 8894308 8893810 8894182
#> [73] 8893778 8893790 8894300 8894298 8894180 8893672 8894442 8893670 8894438
#> [82] 8894296 8893782 8894178 8894294 8893630 8893528 8893774 8893758 8893762
#> [91] 8893760 8893754 8893738 8894174 8893690 8894440 8893608 8893688 8893676
#> [100] 8894436 8893674 8893626 8893574 8893512 8893522 8894432 8893714 8893700
#> [109] 8894172 8893644 8893632 8893602 8893566 8893548 8893544 8893478 8893462
#> [118] 8893424 8893420 8893376 8893362 8893378 8893374 8893352 8894426 8893348
#> [127] 8893330 8893328 8893302 8893372 8893356 8893358 8893322 8893320 8893312
#> [136] 8893294 8893310 8893304 8894284 8894416 8893306 8893296 8893476
#>
#> [[1]]$`2`
#> [1] 8893600 8893570
#>
#> [[1]]$`3`
#> [1] 8893568
#>
#> [[1]]$`4`
#> [1] 8893646 8893642 8893604 8893598 8893582 8893560 8893552 8893472
#>
#> [[1]]$`5`
#> [1] 8893470
#>
#> [[1]]$`6`
#> [1] 8893550
#>
#> [[1]]$`7`
#> [1] 8893580
#>
#> [[1]]$`8`
#> [1] 8893606
#>
#> [[1]]$`9`
#> [1] 8893640 8893634
#>
#> [[1]]$`10`
#> [1] 8893636
#>
#> [[1]]$`11`
#> [1] 8893740 8893732 8893718 8893706
#>
#> [[1]]$`12`
#> [1] 8893734 8893728
#>
#> [[1]]$`13`
#> [1] 8894176 8893710
#>
#> [[1]]$`14`
#> [1] 8893712
#>
#> [[1]]$`15`
#> [1] 8893756
#>
#> [[1]]$`16`
#> [1] 8893768
#>
#> [[1]]$`17`
#> [1] 8893842
#>
#> [[1]]$`18`
#> [1] 8894344 8894332 8894324 8894322 8893808 8894320 8894316 8893804 8894306
#> [10] 8893794 8893792 8893784 8893770 8893748 8893746 8893744 8893736 8893730
#> [19] 8893726 8893722 8893702 8893686 8893668 8893664 8893596 8893572 8893540
#> [28] 8893530 8893514 8893498 8893488 8893480 8893460 8893454 8893446 8893438
#> [37] 8893428 8893398 8894154 8894152 8894150 8893344 8893334 8893346 8893338
#> [46] 8893288 8893196 8893290 8893224 8893336 8893298 8894288 8894286 8893300
#> [55] 8894422 8894290 8893308 8894424 8893292 8893206 8893166 8893130 8893168
#> [64] 8893154 8893204 8893160 8893396 8893370 8893366 8893368 8893364 8894158
#> [73] 8894156 8893354 8893360 8894148 8894292 8893332 8894430 8893342 8894144
#> [82] 8893314 8893318 8894428 8893324 8894142 8893284 8893280 8893278 8893272
#> [91] 8893266 8893260 8893254 8893256 8893240 8893236 8893222 8893216 8893138
#> [100] 8893118 8888408 8893136 8893120 8893112 8893110 8893122 8888406 8888400
#> [109] 8888398 8893218 8893208 8893212 8893184 8893186 8893190 8895610 8893180
#> [118] 8895516 8895512 8895518 8895510 8893152 8895490 8895394 8891180 8891126
#> [127] 8895440 8895502 8895570 8895420 8895312 8895362 8895430 8895484 8895540
#> [136] 8898154 8895464 8895494 8895596 8895474 8895476 8898152 8895564 8895526
#> [145] 8895364 8898380 8895326 8895318 8897428 8895460 8895506 8895314 8898382
#> [154] 8891188 8895310 8891190 8891146 8891106 8891054 8891104 8891174 8891166
#> [163] 8891202 8895322 8895396 8895520 8895402 8895442 8895324 8891206 8891210
#> [172] 8895328 8891178 8891152 8893202 8893192 8893172 8893176 8893170 8893182
#>
#> [[1]]$`19`
#> [1] 8893174
#>
#> [[1]]$`20`
#> [1] 8893194 8893188 8893178
#>
#> [[1]]$`21`
#> [1] 8893200
#>
#> [[1]]$`22`
#> [1] 8893198
#>
#> [[1]]$`23`
#> [1] 8893228 8893232 8893234 8893210
#>
#> [[1]]$`24`
#> [1] 8893238 8895708 8895690 8897432 8897436 8895628 8898156 8895658 8895602
#> [10] 8893230 8893220
#>
#> [[1]]$`25`
#> [1] 8893226
#>
#> [[1]]$`26`
#> [1] 8893252 8893246
#>
#> [[1]]$`27`
#> [1] 8893258
#>
#> [[1]]$`28`
#> [1] 8893264 8893262 8893248 8893242 8893164 8894420 8893162 8893158 8893140
#> [10] 8893132 8893128 8893108 8893126 8893124 8893116 8893114 8893104 8893106
#> [19] 8888402 8893134 8888404 8888394 8888396 8893156 8893150 8893142
#>
#> [[1]]$`29`
#> [1] 8893144 8893146 8893148 8893244 8893214 8893250
#>
#> [[1]]$`30`
#> [1] 8893270 8893268
#>
#> [[1]]$`31`
#> [1] 8893276
#>
#> [[1]]$`32`
#> [1] 8893282 8893274
#>
#> [[1]]$`33`
#> [1] 8893286
#>
#> [[1]]$`34`
#> [1] 8894146 8893316 8893482
#>
#> [[1]]$`35`
#> [1] 8893490 8893464
#>
#> [[1]]$`36`
#> [1] 8893516 8893508
#>
#> [[1]]$`37`
#> [1] 8893510 8893502 8893492 8893452
#>
#> [[1]]$`38`
#> [1] 8893450 8893434
#>
#> [[1]]$`39`
#> [1] 8893440 8893442
#>
#> [[1]]$`40`
#> [1] 8893542 8893532 8893518
#>
#> [[1]]$`42`
#> [1] 8893520
#>
#> [[1]]$`43`
#> [1] 8893546 8893524
#>
#> [[1]]$`44`
#> [1] 8893526
#>
#> [[1]]$`45`
#> [1] 8893666 8893614 8893554 8893506 8893466
#>
#> [[1]]$`46`
#> [1] 8893458 8893436
#>
#> [[1]]$`47`
#> [1] 8893504 8893500
#>
#> [[1]]$`48`
#> [1] 8893556
#>
#> [[1]]$`49`
#> [1] 8893692 8893612
#>
#> [[1]]$`50`
#> [1] 8893610
#>
#> [[1]]$`51`
#> [1] 8893716 8893708 8893698 8893618 8893564 8893584 8893588 8893586
#>
#> [[1]]$`52`
#> [1] 8893620
#>
#> [[1]]$`53`
#> [1] 8893704 8893694 8893678
#>
#> [[1]]$`54`
#> [1] 8893684 8893658 8893562
#>
#> [[1]]$`55`
#> [1] 8893656 8893622 8893638 8893592
#>
#> [[1]]$`56`
#> [1] 8893590
#>
#> [[1]]$`57`
#> [1] 8893624
#>
#> [[1]]$`58`
#> [1] 8893616
#>
#> [[1]]$`59`
#> [1] 8893696
#>
#> [[1]]$`60`
#> [1] 8893724 8894170 8893402 8893720
#>
#> [[1]]$`61`
#> [1] 8893742
#>
#> [[1]]$`62`
#> [1] 8894184 8894448 8894318 8894304 8893786 8893776
#>
#> [[1]]$`63`
#> [1] 8893772 8893766 8893750
#>
#> [[1]]$`64`
#> [1] 8893752
#>
#> [[1]]$`65`
#> [1] 8893764
#>
#> [[1]]$`66`
#> [1] 8894302 8893788
#>
#> [[1]]$`67`
#> [1] 8894326 8893780 8893680 8893654 8893650 8893628 8893594 8893558 8893538
#> [10] 8893468 8893456 8893448 8893430 8893432 8893422 8893418 8893400 8893392
#> [19] 8893384 8893382 8894164 8894162 8897328 8896046 8895956 8896050 8896014
#> [28] 8897448 8897468 8895888 8895812 8897452 8897450 8895782 8895730 8895890
#> [37] 8895884 8897446 8895766 8895638 8896016 8896054 8896080 8896032 8895940
#> [46] 8895786 8895758 8895788 8895746 8895660 8895748 8895728 8895620 8895778
#> [55] 8897472 8895784 8897462 8895704 8895654 8895946 8895932 8893390 8893388
#>
#> [[1]]$`68`
#> [1] 8893386 8894168 8894434 8893380
#>
#> [[1]]$`69`
#> [1] 8893416
#>
#> [[1]]$`70`
#> [1] 8893426 8893414 8893404 8893394
#>
#> [[1]]$`71`
#> [1] 8894166
#>
#> [[1]]$`72`
#> [1] 8893412 8893410 8893408
#>
#> [[1]]$`73`
#> [1] 8893406
#>
#> [[1]]$`75`
#> [1] 8893444
#>
#> [[1]]$`76`
#> [1] 8893648
#>
#> [[1]]$`77`
#> [1] 8893652
#>
#> [[1]]$`78`
#> [1] 8893682 8893662 8893578 8893536 8893494 8893484 8893474
#>
#> [[1]]$`79`
#> [1] 8893486
#>
#> [[1]]$`80`
#> [1] 8893496
#>
#> [[1]]$`81`
#> [1] 8893534
#>
#> [[1]]$`82`
#> [1] 8893576
#>
#> [[1]]$`83`
#> [1] 8893660
#>
#> [[1]]$`84`
#> [1] 8894330 8894328 8894186 8893800 8894446 8894160 8893350
#> [8] 8894364 166755057 8893896 166755056 8893892 8894206 8894210
#> [15] 8894358 8894346 8897692 8897676 8898402 8894188 8897678
#> [22] 8897656 8897654 8896566 8896550 8893824 8896548 8893822
#> [29] 8893818 8897658 8896564 8896524 8903078 8893802 8893796
#> [36] 8894450 8896526 8897342 8896522 8897604 8897594 8897340
#> [43] 8897596 8897586 8896404 8897336 8896238 8896176 8896240
#> [50] 8896252 8896230 8896344 8896334 8896440 8896506 8896542
#> [57] 8896586 8896308 8896234 8896192 8896260 8896262 8896048
#> [64] 8896272 8897560 8897562 8897554 8896190 8896086 8896044
#> [71] 8896094 8895906 8898174 8895908 8895824 8895818 8895820
#> [78] 8895816 8897490 8895770 8895792 8895662 8895664 8895550
#> [85] 8895548 8898160 8895546 8898158 8897564 8897566 8896246
#> [92] 8896248 8896132 8896142 8896160 8896236 8896104 8896100
#> [99] 8896102 8896078 8896152 8896232 8896090 8897504 8895988
#> [106] 8895952 8896254 8896322 8896324 8896340 8896338 8896326
#> [113] 8898226 8896328 8896352 8896354 8896336 8896430 8897572
#> [120] 8896382 8897618 8897620 8896484 8896486 8898256 8896494
#> [127] 8896482 8897622 8896462 8896538 8896600 8898296 8896574
#> [134] 8896578 8898290 8896584 8897684 8896612 8897584 8896428
#>
#> [[1]]$`85`
#> [1] 8894348 8897704 8896696 8897696 8897694 8897344 8897660 8896518 8896516
#> [10] 8898258 8896534 8896536 8897646 8897644 8896510 8896570 8896572 8896624
#> [19] 8896664 8896656 8896658 8898302
#>
#>