Operators
Erdos.jl implements the following graph operators:
Base.intersect
Base.join
Base.union
Erdos.cartesian_product
Erdos.complement
Erdos.complete
Erdos.complete!
Erdos.contract!
Erdos.crosspath
Erdos.difference
Erdos.egonet
Erdos.subgraph
Erdos.subnetwork
Erdos.symmetric_difference
Erdos.tensor_product
Base.intersect
— Methodintersect(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.
Base.join
— Methodjoin(g, h)
Merges graphs g
and h
using blockdiag
and then adds all the edges between the vertices in g
and those in h
.
Base.union
— Methodunion(g, h)
Merges graphs g
and h
by taking the set union of all vertices and edges.
Erdos.cartesian_product
— Methodcartesian_product(g, h)
Returns the (cartesian product)[https://en.wikipedia.org/wiki/Cartesianproductof_graphs] of g
and h
Erdos.complement
— Methodcomplement(g)
Produces the graph complement of a graph.
Erdos.complete!
— Methodcomplete!(g::ADiGraph)
For each edge (u, v)
in g
, adds to g
its reverse, i.e. (v, u)
.
Erdos.complete
— Methodcomplete(g::ADiGraph)
Returns a digraph containing both the edges (u, v)
of g
and their reverse (v, u)
. See also complete!
.
Erdos.contract!
— Methodcontract!(g, vs)
contract!(g, v1, v2, ....)
Merge the vertices in vs
into a unique vertex.
Erdos.crosspath
— Methodcrosspath(g::AGraph, n::Integer)
Replicate n
times g
and connect each vertex with its copies in a path.
Erdos.difference
— Methoddifference(g, h)
Produces a graph with all the edges in graph g
that are not in graph h
.
Note that this function may produce a graph with 0-degree vertices.
Erdos.egonet
— Methodegonet(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].
Erdos.subgraph
— Methodsubgraph(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]
Erdos.subnetwork
— Methodsubnetwork(g, vlist) -> sg, vlist
subnetwork(g, elist) -> sg, vlist
Equivalent to subgraph
but preserves vertex and edge properties when g
is a network.
Erdos.symmetric_difference
— Methodsymmetric_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.
Erdos.tensor_product
— Methodtensor_product(g, h)
Returns the (tensor product)[https://en.wikipedia.org/wiki/Tensorproductof_graphs] of g
and h