The SPPFP transformation functions only work with digraphs -i.e. directed graphs.
Because in a digraph arcs can only be traveled in one direction, from the origin node to the
destination arc, if undirected graphs are used as-is, the resultng G* will not be accurate.
Therefore, this functions translates an undirected graph to a
digraph by duplicating each arc and swapping the duplicate's from
and to
nodes.
direct_graph(graph, cores = 1L)
graph | An undirected graph written as a data frame, in which each rows represent an arc.
The columns must be named |
---|---|
cores | This algorithm can be run using R's parallel processing functions. This variable represents the number of processing cores you want to assign for the transformation. The default value is one single core. It is suggested to not assign all of your available cores to the function. |
A new graph, with the same columns and data types of the original graph. This new graph is twice as big as the original, as new arcs are added to represent that each arc can be traveled in both directions.
Other Parsers: get_all_nodes
,
parse_vpath
# Obtain the graph from any way graph <- data.frame(from = c("s", "s", "s", "u", "u", "w", "w", "x", "x", "v", "v", "y", "y"), to = c("u", "w", "x", "w", "v", "v", "y", "w", "y", "y", "t", "t", "u"), cost = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), stringsAsFactors = FALSE) graph#> from to cost #> 1 s u 1 #> 2 s w 1 #> 3 s x 1 #> 4 u w 1 #> 5 u v 1 #> 6 w v 1 #> 7 w y 1 #> 8 x w 1 #> 9 x y 1 #> 10 v y 1 #> 11 v t 1 #> 12 y t 1 #> 13 y u 1# Translate it digraph <- direct_graph(graph) digraph#> from to cost #> 1 s u 1 #> 2 s w 1 #> 3 s x 1 #> 4 u w 1 #> 5 u v 1 #> 6 w v 1 #> 7 w y 1 #> 8 x w 1 #> 9 x y 1 #> 10 v y 1 #> 11 v t 1 #> 12 y t 1 #> 13 y u 1 #> 14 u s 1 #> 15 w s 1 #> 16 x s 1 #> 17 w u 1 #> 18 v u 1 #> 19 v w 1 #> 20 y w 1 #> 21 w x 1 #> 22 y x 1 #> 23 y v 1 #> 24 t v 1 #> 25 t y 1 #> 26 u y 1