Learn R Programming

mathgraph (version 0.9-14)

mathgraph: Create Mathematical Graph

Description

Create an object of class "mathgraph" which represents a mathematical graph.

Usage

mathgraph(formula, directed = FALSE, data = sys.parent())
# S3 method for mathgraph
length(x)
# S3 method for mathgraph
c(...)

is.mathgraph(x)

Arguments

formula

a formula containing just the right-side. Special operators in the formula are + which separates terms, / which puts an edge between corresponding elements of the two vectors on which it is operating, and * which puts an edge between every pair of elements in the two vectors on which it is operating.

directed

logical flag: if TRUE, then all edges that are created are directed, otherwise they are undirected.

data

the frame in which to find objects referenced in the formula. This can be either the number of a memory frame, or a list or data frame containing the data.

objects to be concatenated.

x

object of class "mathgraph".

Value

an object of class mathgraph which is a two-column matrix of nodes along with an additional attribute called "directed" which is a logical vector stating whether or not each edge is directed. An edge (row of the matrix) that is directed goes from the node in the first column to the node in the second column.

Details

Mathematical graphs consist of a set of nodes (vertices) and edges. Edges go between two nodes. An edge that is directed is often called an arc.

Terms in the formula (delimited by +) may be either calls to * or /, or objects that are already of class "mathgraph".

Two other representations of graphs are adjacency matrices and incidence matrices. The functions to convert "mathgraph" objects to these are adjamat and incidmat, respectively. Most algorithms for mathematical graphs are in terms of incidence matrices or adjacency matrices.

The generic functions that have a method for class "mathgraph" include: [, c, length, names, plot, print, unique.

is.mathgraph is the membership function for this class.

References

Chachra, V., Ghare, P. M. and Moore, J. M. (1979). Applications of Graph Theory Algorithms. Elvesier North Holland, New York.

See Also

adjamat, incidmat, getpath

Examples

Run this code
# NOT RUN {
mathgraph(~ 1:3 / 2:4) # graph with 3 edges
mathgraph(~ 1:3 * 2:4) # graph with 9 edges

mathgraph(~ 1:3 / 2:4, dir=TRUE) # directed graph with 3 edges

# graph with some edges directed, some not
c(mathgraph(~ 1:3 * 2:4), mathgraph(~ c(3,1) / c(2,4), dir=TRUE))

# }

Run the code above in your browser using DataLab