Operators

Erdos.jl implements the following graph operators:

# Base.SparseArrays.blkdiagMethod.

blkdiag(g, h)

Produces a graph with $|V(g)| + |V(h)|$ vertices and $|E(g)| + |E(h)|$ edges.

Put simply, the vertices and edges from graph h are appended to graph g.

source

# Base.intersectMethod.

intersect(g, h)

Produces a graph with edges that are only in both graph g and graph h.

Note that this function may produce a graph with 0-degree vertices.

source

# Base.joinMethod.

join(g, h)

Merges graphs g and h using blkdiag and then adds all the edges between the vertices in g and those in h.

source

# Base.unionMethod.

union(g, h)

Merges graphs g and h by taking the set union of all vertices and edges.

source

# Erdos.cartesian_productMethod.

cartesian_product(g, h)

Returns the (cartesian product)[https://en.wikipedia.org/wiki/Cartesian_product_of_graphs] of g and h

source

# Erdos.complementMethod.

complement(g)

Produces the graph complement of a graph.

source

# Erdos.complete!Method.

complete!(g::ADiGraph)

For each edge (u, v) in g, adds to g its reverse, i.e. (v, u).

source

# Erdos.completeMethod.

complete(g::ADiGraph)

Returns a digraph containing both the edges (u, v) of g and their reverse (v, u). See also complete!.

source

# Erdos.contract!Method.

contract!(g, vs)
contract!(g, v1, v2, ....)

Merge the vertices in vs into a unique vertex.

source

# Erdos.crosspathMethod.

crosspath(g::AGraph, n::Integer)

Replicate n times g and connect each vertex with its copies in a path.

source

# Erdos.differenceMethod.

difference(g, h)

Produces a graph with edges in graph g that are not in graph h.

Note that this function may produce a graph with 0-degree vertices.

source

# Erdos.egonetMethod.

egonet(g, v::Int, d::Int; dir=:out)

Returns the subgraph of g induced by the neighbors of v up to distance d. If g is a DiGraph the dir optional argument specifies the edge direction the edge direction with respect to v (i.e. :in or :out) to be considered. This is equivalent to subgraph(g, neighborhood(g, v, d, dir=dir))[1].

source

# Erdos.subgraphMethod.

subgraph(g, vlist) -> sg, vlist
subgraph(g, elist) -> sg, vlist

Returns the subgraph of g induced by the vertices in vlist or by the edges in elist, along with vlist itself (a newly created vector for the second method).

The returned graph has length(vlist) vertices, with the new vertex i corresponding to the vertex of the original graph in the i-th position of vlist.

For easy subgraph creation also g[vlist] or g[elist] can be used.

If g is a network, vector and edge properties won't be converved sg. You can preserve properties using the subnetwork method.

Usage Examples:

g = CompleteGraph(10)
sg, vlist = subgraph(g, 5:8)
@assert g[5:8] == sg
@assert nv(sg) == 4
@assert ne(sg) == 6
@assert vm[4] == 8

sg, vlist = subgraph(g, [2,8,3,4])
@asssert sg == g[[2,8,3,4]]

elist = [Edge(1,2), Edge(3,4), Edge(4,8)]
sg, vlist = subgraph(g, elist)
@asssert sg == g[elist]

source

# Erdos.subnetworkMethod.

subnetwork(g, vlist) -> sg, vlist
subnetwork(g, elist) -> sg, vlist

Equivalent to subgraph but preserves vertex and edge properties when g is a network.

source

# Erdos.symmetric_differenceMethod.

symmetric_difference(g, h)

Produces a graph with edges from graph g that do not exist in graph h, and vice versa.

Note that this function may produce a graph with 0-degree vertices.

source

# Erdos.tensor_productMethod.

tensor_product(g, h)

Returns the (tensor product)[https://en.wikipedia.org/wiki/Tensor_product_of_graphs] of g and h

source