Digraph | R Documentation |
An R6 class representing a digraph (a directed graph).
Encapsulates and provides methods for computation and checking of
directed graphs (digraphs). Inherits from class Graph
.
A GML stream as a character vector.
rdecision::Graph
-> Digraph
rdecision::Graph$degree()
rdecision::Graph$edge_along()
rdecision::Graph$edge_at()
rdecision::Graph$edge_index()
rdecision::Graph$edge_label()
rdecision::Graph$edges()
rdecision::Graph$graph_adjacency_matrix()
rdecision::Graph$has_edge()
rdecision::Graph$has_vertex()
rdecision::Graph$is_simple()
rdecision::Graph$neighbours()
rdecision::Graph$order()
rdecision::Graph$size()
rdecision::Graph$vertex_along()
rdecision::Graph$vertex_at()
rdecision::Graph$vertex_index()
rdecision::Graph$vertex_label()
rdecision::Graph$vertexes()
new()
Create a new Digraph
object from sets of nodes and
edges.
Digraph$new(V, A)
V
A list of Nodes.
A
A list of Arrows.
A Digraph object.
digraph_adjacency_matrix()
Compute the adjacency matrix for the digraph.
Digraph$digraph_adjacency_matrix(boolean = FALSE)
boolean
If TRUE
, the adjacency matrix is logical, each
cell is {FALSE,TRUE}
.
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).
A square integer 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.
digraph_incidence_matrix()
Compute the incidence matrix for the digraph.
Digraph$digraph_incidence_matrix()
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.
The incidence matrix of integers.
topological_sort()
Topologically sort the vertexes in the digraph.
Digraph$topological_sort()
Uses Kahn's algorithm (Kahn, 1962).
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.
is_connected()
Test whether the graph is connected.
Digraph$is_connected()
For digraphs this will always return FALSE
because
connected is not defined. Function weakly_connected
calculates whether the underlying graph is connected.
TRUE
if connected, FALSE
if not.
is_weakly_connected()
Test whether the digraph is weakly connected, i.e. if the underlying graph is connected.
Digraph$is_weakly_connected()
TRUE
if connected, FALSE
if not.
is_acyclic()
Checks for the presence of a cycle in the graph.
Digraph$is_acyclic()
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
.
TRUE
if no cycles detected.
is_tree()
Is the digraph's underlying graph a tree?
Digraph$is_tree()
It is a tree if it is connected and acyclic.
TRUE
if the underlying graph is a tree; FALSE
if not.
is_polytree()
Is the digraph's underlying graph a polytree?
Digraph$is_polytree()
It is a polytree if it is directed, connected and acyclic.
Because the object is a digraph (directed), this is synonymous with
tree
.
TRUE
if the underlying graph is a tree; FALSE
if not.
is_arborescence()
Is the digraph an arborescence?
Digraph$is_arborescence()
An arborescence is a tree with a single root and unique paths from the root.
TRUE
if the digraph is an arborescence; FALSE
if not.
direct_successors()
Find the direct successors of a node.
Digraph$direct_successors(v)
v
The index vertex (a scalar; does not accept a vector of nodes).
A list of Nodes or an empty list if the specified node has no successors.
direct_predecessors()
Find the direct predecessors of a node.
Digraph$direct_predecessors(v)
v
The index vertex (a scalar; does not accept an index of nodes).
A list of Nodes or an empty list if the specified node has no predecessors.
arrow_source()
Find the node that is the source of the given arrow.
Digraph$arrow_source(a)
a
An arrow (directed edge), which must be in the digraph.
The source node is a property of the arrow, not the digraph of
which it is part, hence the canonical method for establishing the source
node of an arrow is via method $source
of an Arrow
object.
This function is provided for convenience when iterating the arrows of a
digraph. It raises an error if the arrow is not in the graph. It
returns the index of the source node, which is a property of the graph;
the node object itself may be retrieved using the $vertex_at
method of the graph.
Index of the source node of the specified edge.
arrow_target()
Find the node that is the target of the given arrow.
Digraph$arrow_target(a)
a
An arrow (directed edge), which must be in the digraph.
The target node is a property of the arrow, not the digraph of
which it is part, hence the canonical method for establishing the target
node of an arrow is via method $target
of an $Arrow
object.
This function is provided for convenience when iterating the arrows of a
digraph. It raises an error if the arrow is not in the graph. It
returns the index of the target node, which is a property of the graph;
the node itself may be retrieved using the $vertex_at
method
of the graph.
Index of the target node of the specified edge.
paths()
Find all directed simple paths from source to target.
Digraph$paths(s, t)
s
Source node.
t
Target node.
In simple paths all vertexes are unique. Uses a recursive depth-first search algorithm.
A list of ordered node lists.
walk()
Sequence of edges which join the specified path.
Digraph$walk(P, what = "edge")
P
A list of Nodes
what
One of "edge" or "index".
A list of Edges for what = "edge"
or a list of Edge
indices for what = "index"
.
as_DOT()
Exports the digraph in DOT notation.
Digraph$as_DOT(rankdir = "LR", width = 7, height = 7)
rankdir
One of "LR" (default), "TB", "RL" or "BT".
width
of the drawing, in inches
height
of the drawing, in inches
Writes a representation of the digraph in the
graphviz
DOT language
(https://graphviz.org/doc/info/lang.html) for drawing with one
of the graphviz
tools, including dot
(Gansner, 1993).
This option is recommended if it is desired to rapidly plot a graph;
however it gives limited control over details of the appearance. In
addition, the appearance may vary between calls if the node order changes
(specifically, if there is no Hamiltonian path). For greater control over
the appearance of a graph, use the as_gml
function and manipulate
the graph using igraph or DiagrammeR; please refer to the vignettes for
examples.
A character vector. Intended for passing to writeLines
for saving as a text file.
as_gml()
Exports the digraph as a Graph Modelling Language (GML) stream.
Digraph$as_gml()
Intended to work with the igraph or DiagrammeR packages, which are able to import GML files.
clone()
The objects of this class are cloneable with this method.
Digraph$clone(deep = FALSE)
deep
Whether to make a deep clone.
Andrew Sims andrew.sims@newcastle.ac.uk
Gansner ER, Koutsofios E, North SC, Vo K-P. A technique for drawing directed graphs. IEEE Transactions on Software Engineering, 1993;19:214–30, \Sexpr[results=rd]{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, \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1201/b16132")}.
Kahn AB, Topological Sorting of Large Networks, Communications of the ACM, 1962;5:558-562, \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1145/368996.369025")}.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.