Title: | eulerian: A package to find eulerian paths from graphs |
---|---|
Description: | An eulerian path is a path in a graph which visits every edge exactly once. This package provides methods to handle eulerian paths or cycles. |
Authors: | Ashis Saha, with contribution from Jaewoo Kang |
Maintainer: | Ashis Saha <[email protected]> |
License: | GPL-2 |
Version: | 1.0 |
Built: | 2024-11-15 03:35:15 UTC |
Source: | https://github.com/cran/eulerian |
An eulerian path is a path in a graph which visits every edge exactly once. This package provides methods to handle eulerian paths or cycles.
require(graph) require(eulerian) g <- new("graphNEL", nodes=LETTERS[1:4], edgemode="directed") g <- addEdge(graph=g, from=LETTERS[1:4], to=LETTERS[c(2:4,1)]) if(hasEulerianCycle(g)){ ecycle <- eulerian(g) writeLines(paste(ecycle, collapse=" -> ")) }
require(graph) require(eulerian) g <- new("graphNEL", nodes=LETTERS[1:4], edgemode="directed") g <- addEdge(graph=g, from=LETTERS[1:4], to=LETTERS[c(2:4,1)]) if(hasEulerianCycle(g)){ ecycle <- eulerian(g) writeLines(paste(ecycle, collapse=" -> ")) }
An eulerian path is a path in a graph which visits every edge exactly once. This function returns an eulerian path from a graph (if there is any). It works for both directed and undirected graphs.
eulerian(graph, start = NULL)
eulerian(graph, start = NULL)
graph |
a |
start |
|
If start
is not NULL
, then eulerian returns a path starting from it. Otherwise, the start node is automatically selected.
A character vector representing an eulerian path/cycle in graph
. Each entry in the vector represents the name of a node in the graph.
Ashis Saha
require(graph) require(eulerian) g <- new("graphNEL", nodes=LETTERS[1:4], edgemode="uirected") g <- addEdge(graph=g, from=LETTERS[1:3], to=LETTERS[2:4]) ep <- eulerian(g) g <- new("graphNEL", nodes=as.character(1:10), edgemode="directed") g <- addEdge(graph=g, from=c("1","2","2","3","4","5","6","6","7","8","9","10"), to=c("10","1","6","2","2","4","5","8","9","7","6","3")) ep <- eulerian(g, "6")
require(graph) require(eulerian) g <- new("graphNEL", nodes=LETTERS[1:4], edgemode="uirected") g <- addEdge(graph=g, from=LETTERS[1:3], to=LETTERS[2:4]) ep <- eulerian(g) g <- new("graphNEL", nodes=as.character(1:10), edgemode="directed") g <- addEdge(graph=g, from=c("1","2","2","3","4","5","6","6","7","8","9","10"), to=c("10","1","6","2","2","4","5","8","9","7","6","3")) ep <- eulerian(g, "6")
An eulerian cycle is a path in a graph which visits every edge exactly once, and starts and ends at the same node.
hasEulerianCycle(graph)
hasEulerianCycle(graph)
graph |
a |
A graph will have an euler cycle if and only if every node has same number of edges entering into and going out of it.
TRUE
, if graph has an auler cycle. FALSE
, otherwise.
Ashis Saha
require(graph) require(eulerian) g <- new("graphNEL", nodes=LETTERS[1:4], edgemode="directed") g <- addEdge(graph=g, from=LETTERS[1:4], to=LETTERS[c(2:4,1)]) hasEulerianCycle(g)
require(graph) require(eulerian) g <- new("graphNEL", nodes=LETTERS[1:4], edgemode="directed") g <- addEdge(graph=g, from=LETTERS[1:4], to=LETTERS[c(2:4,1)]) hasEulerianCycle(g)
An eulerian path is a path in a graph which visits every edge exactly once.
hasEulerianPath(graph, start = NULL)
hasEulerianPath(graph, start = NULL)
graph |
a |
start |
|
If start
is NULL
, this function returns whether there exists any eulerian path in graph
. If start
is not NULL
, the function determines if there exists an eulerian path starting from start
.
TRUE
, if there is an eulerian path. FALSE
, otherwise.
Ashis Saha
require(graph) require(eulerian) g <- new("graphNEL", nodes=LETTERS[1:4], edgemode="undirected") g <- addEdge(graph=g, from=LETTERS[c(1:4)], to=LETTERS[c(2:4,4)]) hasEulerianPath(g) #TRUE hasEulerianPath(g, "B") #FALSE
require(graph) require(eulerian) g <- new("graphNEL", nodes=LETTERS[1:4], edgemode="undirected") g <- addEdge(graph=g, from=LETTERS[c(1:4)], to=LETTERS[c(2:4,4)]) hasEulerianPath(g) #TRUE hasEulerianPath(g, "B") #FALSE