| to_igraph | R Documentation |
Convert cppRouting graph to an igraph object
to_igraph(Graph, aux = FALSE, capacity = FALSE, alpha = FALSE, beta = FALSE)
Graph |
An object generated by cppRouting::makegraph() or cpp_simplify() function. |
aux |
logical. If |
capacity |
logical. If |
alpha |
logical. If |
beta |
logical. If |
Vertices are named after the graph's own node refs (Graph$dict$ref); if the graph has
coordinates, they are attached as vertex attributes x/y. Edge cost (dist) is exposed
as the edge attribute weight, matching igraph's own convention for its shortest-path functions
(igraph::distances(), igraph::shortest_paths(), etc. use weight by default) – so the
result is directly usable with igraph's own algorithms (centrality, community detection, plotting...)
without cppRouting needing to reimplement any of them.
An igraph object. Requires the igraph package.
#Simple directed graph
edges<-data.frame(from=c(1,2,3,4,5,6,7,8),
to=c(0,1,2,3,6,7,8,5),
dist=c(1,1,1,1,1,1,1,1))
#Construct cppRouting graph
graph<-makegraph(edges,directed=TRUE)
#Convert cppRouting graph to an igraph object
if (requireNamespace("igraph", quietly = TRUE)) {
ig <- to_igraph(graph)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.