is_acyclic: Test whether an undirected graph is acyclic

Description Usage Arguments Details Value Author(s) Examples

View source: R/CL.R

Description

Test whether an undirected graph, represented by an adjacency matrix, is acyclic.

Usage

1
is_acyclic(adj_matrix)

Arguments

adj_matrix

The adjacency matrix representing the graph.

Details

Notice that the function cannot cope with loops. If the graph has loops, an error is returned.

Value

A logical value indicating whether the graph is acyclic.

Author(s)

Katrine Kirkeby, enir_tak@hotmail.com

Maria Knudsen, mariaknudsen@hotmail.dk

Ninna Vihrs, ninnavihrs@hotmail.dk

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
adj_matrix_cyclic <- matrix(c(0, 1, 1, 1,
                              1, 0, 0, 1,
                              1, 0, 0, 0,
                              1, 1, 0, 0),
                             nrow = 4)

is_acyclic(adj_matrix_cyclic)

adj_matrix_acyclic <- matrix(c(0, 0, 1, 1,
                               0, 0, 0, 1,
                               1, 0, 0, 0,
                               1, 1, 0, 0),
                              nrow = 4)

is_acyclic(adj_matrix_acyclic)

nvihrs14/tcherry documentation built on Aug. 1, 2020, 6:25 p.m.