Check if the network is connected

is_connected(x, rule = c("weak", "strong"))

Arguments

x

graph of type igraph or network

rule

character, either "strong" or "weak"

Value

logical

Details

The rule to determined if a graph is connected can be either "weak" or "strong". If "weak", vertex $i$ is connected to $j$ iff there exists a semi-path from $i$ to $j$ (i.e., a path in the weakly symmetrized graph). If "strong", vertex $i$ is connected to $j$ iff there exists a direct path from $i$ to $j$ OR a direct path from $j$ to $i$.

In other words: a graph is said to be "strongly connected" if every pair of vertices($i$, $j$) in the graph contains a path between each other following the directions of the edges. In an unweighted directed graph G, every pair of vertices $i$ and $j$ should have a path in each direction between them i.e., a bidirectional path. The elements of the path matrix of such a graph will contain all 1’s. A graph is "weakly connected" if when considering it as an $undirected$ graph it is connected, e.e., for every pair of distinct vertices $i$ and $j$ there exists an undirected path (potentially running opposite the direction of an edge) from $i$ to $j$.

A strongly connected graph is also weakly connected.

Note that the above rules are distinct for directed graphs only; if x is symmetric, the rule has no effect. An undirected graph ought not get the label of "strongly" or "weakly" connected, but it is connected or not.

Examples

strong_i <- igraph::graph_from_literal(a --+ b --+ c --+ a)
is_connected(strong_i, "weak")  # TRUE
#> [1] TRUE
is_connected(strong_i, "strong")  # TRUE
#> [1] TRUE
strong_n <- snafun::to_network(strong_i)
is_connected(strong_n, "weak")  # TRUE
#> [1] TRUE
is_connected(strong_n, "strong")  # TRUE
#> [1] TRUE

weak_i <- igraph::graph_from_literal(a --+ b +-- c)
is_connected(weak_i, "weak")  # TRUE
#> [1] TRUE
is_connected(weak_i, "strong")  # FALSE
#> [1] FALSE
weak_n <- snafun::to_network(weak_i)
is_connected(weak_n, "weak")  # TRUE
#> [1] TRUE
is_connected(weak_n, "strong")  # FALSE
#> [1] FALSE