cpp_simplify: Reduce the number of edges by removing non-intersection...

View source: R/simplify.R

cpp_simplifyR Documentation

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
)

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

Value

The simplified cppRouting graph

Note

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.

Examples

#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)
}


cppRouting documentation built on Dec. 1, 2022, 5:08 p.m.