File: graph_types.R

package info (click to toggle)
r-cran-tidygraph 1.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 880 kB
  • sloc: cpp: 41; sh: 13; makefile: 2
file content (99 lines) | stat: -rw-r--r-- 3,005 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#' Querying graph types
#'
#' This set of functions lets the user query different aspects of the graph
#' itself. They are all concerned with wether the graph implements certain
#' properties and will all return a logical scalar.
#'
#' @param graph The graph to compare structure to
#' @param method The algorithm to use for comparison
#' @param cyclic should the eulerian path start and end at the same node
#'
#' @param ... Arguments passed on to the comparison methods. See
#' [igraph::is_isomorphic_to()] and [igraph::is_subgraph_isomorphic_to()]
#'
#' @return A logical scalar
#'
#' @name graph_types
#' @rdname graph_types
#'
#' @examples
#' gr <- create_tree(50, 4)
#'
#' with_graph(gr, graph_is_tree())
#'
NULL

#' @describeIn graph_types Is the graph simple (no parallel edges)
#' @importFrom igraph is_simple
#' @export
graph_is_simple <- function() {
  is_simple(.G())
}
#' @describeIn graph_types Is the graph directed
#' @importFrom igraph is_directed
#' @export
graph_is_directed <- function() {
  is_directed(.G())
}
#' @describeIn graph_types Is the graph bipartite
#' @importFrom igraph is_bipartite
#' @export
graph_is_bipartite <- function() {
  is_bipartite(.G())
}
#' @describeIn graph_types Is the graph connected
#' @importFrom igraph is_connected
#' @export
graph_is_connected <- function() {
  is_connected(.G())
}
#' @describeIn graph_types Is the graph a tree
#' @export
graph_is_tree <- function() {
  is_tree(.G())
}
#' @describeIn graph_types Is the graph an ensemble of multiple trees
#' @export
graph_is_forest <- function() {
  is_forest(.G())
}
#' @describeIn graph_types Is the graph a directed acyclic graph
#' @importFrom igraph is_dag
#' @export
graph_is_dag <- function() {
  is_dag(.G())
}
#' @describeIn graph_types Is the graph chordal
#' @importFrom igraph is_chordal
#' @export
graph_is_chordal <- function() {
  is_chordal(.G())$chordal
}
#' @describeIn graph_types Is the graph fully connected
#' @export
graph_is_complete <- function() {
  graph_is_simple() && all(centrality_degree(mode = 'all', loops = FALSE) == graph_order() - 1)
}
#' @describeIn graph_types Is the graph isomorphic to another graph. See [igraph::is_isomorphic_to()]
#' @importFrom igraph is_isomorphic_to
#' @export
graph_is_isomorphic_to <- function(graph, method = 'auto', ...) {
  is_isomorphic_to(.G(), graph, method, ...)
}
#' @describeIn graph_types Is the graph an isomorphic subgraph to another graph. see [igraph::is_subgraph_isomorphic_to()]
#' @importFrom igraph is_subgraph_isomorphic_to
#' @export
graph_is_subgraph_isomorphic_to <- function(graph, method = 'auto', ...) {
  is_subgraph_isomorphic_to(.G(), graph, method, ...)
}
#' @describeIn graph_types Can all the edges in the graph be reaches by a single
#' path or cycle that only goes through each edge once
#' @importFrom igraph has_eulerian_cycle has_eulerian_path
#' @export
graph_is_eulerian <- function(cyclic = FALSE) {
  if (cyclic) {
    has_eulerian_cycle(.G())
  } else {
    has_eulerian_path(.G())
  }
}