-
Notifications
You must be signed in to change notification settings - Fork 6
Hypergraphs
A hypergraph is a pair H=(V,E) where V is a (finite) set and E
is a set of subsets of V.
Create a new hypergraph with H = SimpleHypergraph{T}() where T
is the datatype of the vertices.
Given an n-by-m matrix A, use SimpleHypergraph(A) to create a
hypergraph with vertex set {1,2,...,n} with edges determined by the
nonzero entries in the columns of A. This acts like an inverse operation to incidence.
Warning: Do not use SimpleHypergraph{Any} because a
Set of objects also matches Any; there would be no clear way
to distinguish vertices from edges.
The convenience function IntHypergraph() is a synonym for SimpleHypergraph{Int}(). Also: IntHypergraph(n) creates a new
SimpleHypergraph{Int} with vertex set {1,2,...,n} and no edges.
Similarly, StringHypergraph() is a synonym for SimpleHypergraph{String}().
-
To add a vertex to a hypergraph use
add!(H,v)where the type ofvneeds to be of the appropriate type. -
Edges are sets of vertices and they are added by
add!(H,e)whereeis either aSetor a one-dimensional array of elements of the appropriate type. Note that if some elements ofeare not already vertices ofHthey are added toH's vertex set. -
An edge with at least two elements may also be added by listing its vertices as arguments. The following are all equivalent:
add!(H,Set(1:3))
add!(H,[1,2,3])
add!(H,1,2,3)
These functions return true if successful in adding a new elementsto the hypergraph and false if the vertex/edge already exists.
-
To delete a vertex from a hypergraph use
delete!(H,v)wherevmust be of the appropriate type. When a vertex is deleted, so are all edges that contain it. -
To delete an edge from a hypergraph use
delete!(H,e)whereeis aSetor a one-dimensional array of elements of the appropriate type. One may also specifyeby a list of arguments. The following are all equivalent:
delete!(H,Set(1:3))
delete!(H,[1,2,3])
delete!(H,1,2,3)
-
Use
NE(H)andNV(H)to determine the number vertices and edges, respectively, inH. -
The functions
vlist(H)andelist(H)return the vertices and edges, respectively, as lists (one-dimensional arrays). -
Use
vertex_type(H)to check the datatype of the vertices. -
For a vertex
v, useH[v]to return the set of edges that containv. -
Use
deg(H,v)to determine the number of edges that containv, i.e., its degree. -
Use
has(H,v)orhas(H,e)to determine ifHcontains vertexvor edgee, respectively. For edge queries,eis a set, a list, or a sequence of two or more arguments. Warning: The following are not the same:has(G,1)andhas(G,[1]). The first checks if1is a vertex and the second checkes if{1}is an edge. -
The function
is_uniform(H)determines ifHis a uniform hypergraph. That is, if all edges have the same size. -
incidence(A)returns ann-by-mincidence matrix ofA. The rows correspond to the vertices and the columns to the edges. There is a1in positioni,jprecisely when vertexiis an element of edgej. Other entries are0.
Use G = SimpleGraph(H) to convert H to a SimpleGraph. The vertex
set of G is the same as the vertex set of H. Two vertices of G
are adjacent if and only if they are elements of a common edge of H.
In other words, each edge of H becomes a clique of G.
Note that a SimpleGraph does not contain loops; singleton edges of
H make no contribution to the edge set of G.
Conversely, if G is a SimpleGraph, then use SimpleHypergraph(G)
to convert to a hypergraph.