Learn R Programming

cppRouting (version 3.1)

cpp_simplify: Reduce the number of edges by removing non-intersection nodes, duplicated edges and isolated loops in the graph.

Description

Reduce the number of edges by removing non-intersection nodes, duplicated edges and isolated loops in the graph.

Usage

cpp_simplify(
  Graph,
  keep = NULL,
  rm_loop = TRUE,
  iterate = FALSE,
  silent = TRUE
)

Value

The simplified cppRouting graph

Arguments

Graph

An object generated by makegraph function.

keep

Character or integer vector. Nodes of interest that will not be removed. Default to NULL

rm_loop

Logical. if TRUE, isolated loops as removed. Default to TRUE

iterate

Logical. If TRUE, process is repeated until only intersection nodes remain in the graph. Default to FALSE

silent

Logical. If TRUE and iterate set to TRUE, number of iteration and number of removed nodes are printed to the console.

Details

To understand why process can be iterated, see the package description : https://github.com/vlarmet/cppRouting/blob/master/README.md

Examples

Run this code
#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)
}

Run the code above in your browser using DataLab