thomasp85 / tidygraph

A tidy API for graph manipulation
https://tidygraph.data-imaginist.com
Other
545 stars 61 forks source link

Support for multiple target nodes in to_shortest_path #83

Open krlmlr opened 5 years ago

krlmlr commented 5 years ago

This currently doesn't seem to work, see reprex. It looks like only a small change will be required, but I might be wrong. Would you support multiple target nodes (default: all nodes) in to_shortest_path()?

library(tidygraph)
#> 
#> Attaching package: 'tidygraph'
#> The following object is masked from 'package:stats':
#> 
#>     filter
play_geometry(10, 3) %>%
  morph(to_shortest_path, from = 1, to = 2:10) %>%
  crystallize() %>%
  pull()
#> [[1]]
#> # A tbl_graph: 2 nodes and 1 edges
#> #
#> # An undirected simple graph with 1 component
#> #
#> # Node Data: 2 x 3 (active)
#>        x     y .tidygraph_node_index
#>    <dbl> <dbl>                 <int>
#> 1 0.0952 0.307                     1
#> 2 0.146  0.651                     2
#> #
#> # Edge Data: 1 x 3
#>    from    to .tidygraph_edge_index
#>   <int> <int>                 <int>
#> 1     1     2                     1

Created on 2018-12-08 by the reprex package (v0.2.1.9000)

krlmlr commented 5 years ago

Also, can we get a to_distances() morpher that adds the distance as a node attribute?

All of this presumes that from is restricted to a single node.

thomasp85 commented 5 years ago

I'll look into this. I don't think a to_distances() morphed makes sense as it does not change the graph structure (which is the purpose of morphers)... You should be able to get what you want using mutate(dist = node_distance_to(...)) or something like that