cpp_simplify | R Documentation |
Reduce the number of edges by removing non-intersection nodes, duplicated edges and isolated loops in the graph.
cpp_simplify( Graph, keep = NULL, rm_loop = TRUE, iterate = FALSE, silent = TRUE )
Graph |
An object generated by makegraph function. |
keep |
Character or integer vector. Nodes of interest that will not be removed. Default to |
rm_loop |
Logical. if |
iterate |
Logical. If |
silent |
Logical. If |
To understand why process can be iterated, see the package description : https://github.com/vlarmet/cppRouting/blob/master/README.md
The simplified cppRouting graph
Additional edge attributes like aux
, alpha
, beta
and capacity
will be removed.
The first iteration usually eliminates the majority of non-intersection nodes and is therefore faster.
#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)) #Plot if(requireNamespace("igraph",quietly = TRUE)){ igr<-igraph::graph_from_data_frame(edges) plot(igr) } #Construct cppRouting graph graph<-makegraph(edges,directed=TRUE) #Simplify the graph, removing loop simp<-cpp_simplify(graph, rm_loop=TRUE) #Convert cppRouting graph to data frame simp<-to_df(simp) #Plot if(requireNamespace("igraph",quietly = TRUE)){ igr<-igraph::graph_from_data_frame(simp) plot(igr) } #Simplify the graph, keeping node 2 and keeping loop simp<-cpp_simplify(graph,keep=2 ,rm_loop=FALSE) #Convert cppRouting graph to data frame simp<-to_df(simp) #Plot if(requireNamespace("igraph",quietly = TRUE)){ igr<-igraph::graph_from_data_frame(simp) plot(igr) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.