Learn R Programming

rdecision (version 1.1.2)

Digraph: A directed graph

Description

An R6 class representing a digraph (a directed graph).

Arguments

Author

Andrew Sims andrew.sims@newcastle.ac.uk

Super class

rdecision::Graph -> Digraph

Methods

Inherited methods


Method new()

Create a new Digraph object from sets of nodes and edges.

Usage

Digraph$new(V, A)

Arguments

V

A list of Nodes.

A

A list of Arrows.

Returns

A Digraph object.


Method digraph_adjacency_matrix()

Compute the adjacency matrix for the digraph.

Usage

Digraph$digraph_adjacency_matrix(boolean = FALSE)

Arguments

boolean

If TRUE, the adjacency matrix is logical, each cell is {FALSE,TRUE}.

Details

Each cell contains the number of edges from the row vertex to the column vertex, with the convention of self loops being counted once, unless boolean is TRUE when cells are either FALSE (not adjacent) or TRUE (adjacent).

Returns

A square numeric matrix with the number of rows and columns equal to the order of the graph. The rows and columns are in the same order as V. If the nodes have defined and unique labels the dimnames of the matrix are the labels of the nodes.


Method digraph_incidence_matrix()

Compute the incidence matrix for the digraph.

Usage

Digraph$digraph_incidence_matrix()

Details

Each row is a vertex and each column is an edge. Edges leaving a vertex have value -1 and edges entering have value +1. By convention self loops have value 0 (1-1). If all vertexes have defined and unique labels and all edges have defined and unique labels, the dimnames of the matrix are the labels of the vertexes and edges.

Returns

The incidence matrix.


Method topological_sort()

Topologically sort the vertexes in the digraph.

Usage

Digraph$topological_sort()

Details

Uses Kahn's algorithm (Kahn, 1962).

Returns

A list of vertexes, topologically sorted. If the digraph has cycles, the returned ordered list will not contain all the vertexes in the graph, but no error will be raised.


Method is_connected()

Test whether the graph is connected.

Usage

Digraph$is_connected()

Details

For digraphs this will always return FALSE because connected is not defined. Function weakly_connected calculates whether the underlying graph is connected.

Returns

TRUE if connected, FALSE if not.


Method is_weakly_connected()

Test whether the digraph is weakly connected, i.e. if the underlying graph is connected.

Usage

Digraph$is_weakly_connected()

Returns

TRUE if connected, FALSE if not.


Method is_acyclic()

Checks for the presence of a cycle in the graph.

Usage

Digraph$is_acyclic()

Details

Attempts to do a topological sort. If the sort does not contain all vertexes, the digraph contains at least one cycle. This method overrides is_acyclic in Graph.

Returns

TRUE if no cycles detected.


Method is_tree()

Is the digraph's underlying graph a tree?

Usage

Digraph$is_tree()

Details

It is a tree if it is connected and acyclic.

Returns

TRUE if the underlying graph is a tree; FALSE if not.


Method is_polytree()

Is the digraph's underlying graph a polytree?

Usage

Digraph$is_polytree()

Details

It is a polytree if it is directed, connected and acyclic. Because the object is a digraph (directed), this is synonymous with tree.

Returns

TRUE if the underlying graph is a tree; FALSE if not.


Method is_arborescence()

Is the digraph an arborescence?

Usage

Digraph$is_arborescence()

Details

An arborescence is a tree with a single root and unique paths from the root.

Returns

TRUE if the digraph is an arborescence; FALSE if not.


Method direct_successors()

Find the direct successors of a node.

Usage

Digraph$direct_successors(v)

Arguments

v

The index vertex.

Returns

A list of nodes or an empty list if the specified node has no successors.


Method direct_predecessors()

Find the direct predecessors of a node.

Usage

Digraph$direct_predecessors(v)

Arguments

v

The index vertex.

Returns

A list of nodes or an empty list if the specified node has no predecessors.


Method paths()

Find all directed simple paths from source to target.

Usage

Digraph$paths(s, t)

Arguments

s

Source node.

t

Target node.

Details

In simple paths all vertexes are unique. Uses a recursive depth-first search algorithm.

Returns

A list of ordered node lists.


Method walk()

Sequence of edges which join the specified path.

Usage

Digraph$walk(P, what = "edge")

Arguments

P

A list of Nodes

what

One of "edge" or "index".

Returns

A list of Edges for what = "edge" or a list of Edge indices for what = "index".


Method as_DOT()

Exports the digraph in DOT notation.

Usage

Digraph$as_DOT()

Details

Writes a representation of the digraph in the graphviz DOT language (http://graphviz.org/doc/info/lang.html) for drawing with one of the graphviz tools, including dot (Gansner, 1993).

Returns

A character vector. Intended for passing to writeLines for saving as a text file.


Method clone()

The objects of this class are cloneable with this method.

Usage

Digraph$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Details

Encapsulates and provides methods for computation and checking of directed graphs (digraphs). Inherits from class Graph.

References

Gansner ER, Koutsofios E, North SC, Vo K-P. A technique for drawing directed graphs. IEEE Transactions on Software Engineering, 1993;19:214–30, tools:::Rd_expr_doi("10.1109/32.221135"). Gross JL, Yellen J, Zhang P. Handbook of Graph Theory. Second edition, Chapman and Hall/CRC.; 2013, tools:::Rd_expr_doi("10.1201/b16132"). Kahn AB, Topological Sorting of Large Networks, Communications of the ACM, 1962;5:558-562, tools:::Rd_expr_doi("10.1145/368996.369025").