-
Notifications
You must be signed in to change notification settings - Fork 4
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 = HyperGraph{T}() where T
is the datatype of the vertices, or HG{T}().
Given an n-by-m matrix A, use HyperGraph(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
HyperGraph{Any}because aSetof objects also matchesAny; there would be no clear way to distinguish vertices from edges.
The convenience function IntHypergraph() is a synonym for HyperGraph{Int}(). Also: IntHypergraph(n) creates a new
HyperGraph{Int} with vertex set {1,2,...,n} and no edges.
Similarly, StringHypergraph() is a synonym for HyperGraph{String}().
The function CompleteHypergraph(n,k) creates a hypergraph with vertex set {1,2,...,n} whose edges
are all k-element subsets of the vertex set.
In addition, RandomHypergraph(n,k,p) creates a random k-uniform hypergraph with n vertices. A given k-element
subset of {1,2,...,n} is an edge with probability p (independently).
The points and lines of a finite projective plane are a natural example of a hypergraph. Using the BalancedIncompleteBlockDesigns
module, we can create such a hypergraph for a plane of prime order like this:
HyperGraph(prime_plane(n))
-
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(H)returns ann-by-mincidence matrix of the hypergraphH. 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 = UndirectedGraph(H) or simplify(H) to convert H to an UndirectedGraph. 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 UndirectedGraph does not contain loops; singleton edges of
H make no contribution to the edge set of G.
Conversely, if G is a UndirectedGraph, then use HyperGraph(G) (or HG(G))
to convert to a hypergraph.