to_igraph: Convert cppRouting graph to an igraph object

View source: R/to_igraph.R

to_igraphR Documentation

Convert cppRouting graph to an igraph object

Description

Convert cppRouting graph to an igraph object

Usage

to_igraph(Graph, aux = FALSE, capacity = FALSE, alpha = FALSE, beta = FALSE)

Arguments

Graph

An object generated by cppRouting::makegraph() or cpp_simplify() function.

aux

logical. If TRUE, carry the graph's aux weight(s) over as edge attribute(s). See to_df.

capacity

logical. If TRUE, carry capacity over as an edge attribute.

alpha

logical. If TRUE, carry alpha over as an edge attribute.

beta

logical. If TRUE, carry beta over as an edge attribute.

Details

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.

Value

An igraph object. Requires the igraph package.

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

#Construct cppRouting graph
graph<-makegraph(edges,directed=TRUE)

#Convert cppRouting graph to an igraph object
if (requireNamespace("igraph", quietly = TRUE)) {
  ig <- to_igraph(graph)
}

cppRouting documentation built on Nov. 12, 2026, 5:11 p.m.