API Reference

Bipartite Graphs

BipartiteGraphs.SRCConstant
SRC

The source-side VertType selector for a BipartiteGraph.

Use SRC as the VertType argument to methods that operate on one side of the graph, such as Graphs.add_vertex!(g, SRC) to add a source vertex.

source
BipartiteGraphs.DSTConstant
DST

The destination-side VertType selector for a BipartiteGraph.

Use DST as the VertType argument to methods that operate on one side of the graph, such as Graphs.add_vertex!(g, DST) to add a destination vertex.

source
BipartiteGraphs.BipartiteGraphType
mutable struct BipartiteGraph{I<:Integer, M} <: Graphs.AbstractGraph{I<:Integer}

A bipartite graph representation between two, possibly distinct, sets of vertices (source and dependencies). Maps source vertices, labelled 1:N₁, to vertices on which they depend (labelled 1:N₂).

Fields

  • ne

  • fadjlist

  • badjlist

  • metadata

Example

using BipartiteGraphs

# six source vertices
fadjlist = [[1],[1],[2],[2],[1],[1,2]]

# two vertices they depend on
badjlist = [[1,2,5,6],[3,4,6]]

bg = BipartiteGraph(7, fadjlist, badjlist)
source
BipartiteGraphs.invviewMethod
invview(
    g::BipartiteGraph
) -> BipartiteGraph{I, Nothing} where I<:Integer

Return a BipartiteGraph with the source and destination vertices swapped. Note that the returned graph aliases g. Requires that g is complete.

source
BipartiteGraphs.completeMethod
complete(g::BipartiteGraph{I}) -> BipartiteGraph{I} where I

Populate the backward adjacency list of g, if it is not already stored.

source
Base.empty!Method
empty!(g::BipartiteGraph) -> BipartiteGraph

Remove all edges from the graph, retaining the source and destination vertices.

source
BipartiteGraphs.𝑠neighborsFunction
𝑠neighbors(
    g::BipartiteGraph,
    i::Integer
) -> Vector{I} where I<:Integer
𝑠neighbors(
    g::BipartiteGraph,
    i::Integer,
    with_metadata::Val{M}
) -> Any

Obtain the neighbors of source vertex i in graph g.

source
BipartiteGraphs.𝑑neighborsFunction
𝑑neighbors(g::BipartiteGraph, j::Integer) -> Vector{Int64}
𝑑neighbors(
    g::BipartiteGraph,
    j::Integer,
    with_metadata::Val{M}
) -> Union{Base.Iterators.Zip{Is} where Is<:Tuple{Vector{Int64}, Base.Generator{Vector{Int64}, F} where F<:(BipartiteGraphs.var"#10#11"{BipartiteGraph{I, M}, <:Integer} where {I<:Integer, M})}, Vector{Int64}}

Obtain the neighbors of destination vertex i in graph g.

source
BipartiteGraphs.𝑠edgesFunction
𝑠edges(
    g::BipartiteGraph
) -> BipartiteGraphs.BipartiteEdgeIter{SRC, G} where G<:BipartiteGraph

Iterate over all edges in the graph, ordered by source vertices.

source
BipartiteGraphs.𝑑edgesFunction
𝑑edges(
    g::BipartiteGraph
) -> BipartiteGraphs.BipartiteEdgeIter{DST, G} where G<:BipartiteGraph

Iterate over all edges in the graph, ordered by destination vertices.

source
Graphs.edgesMethod
edges(
    g::BipartiteGraph
) -> BipartiteGraphs.BipartiteEdgeIter{SRC, G} where G<:BipartiteGraph

Iterate over all edges in the graph, ordered by source vertices.

source
Graphs.nvMethod
nv(g::BipartiteGraph) -> Any

Get the total number of vertices (source and destination) in the graph.

source
Graphs.verticesMethod
vertices(
    g::BipartiteGraph
) -> Tuple{Base.OneTo{Int64}, Base.OneTo}

Obtain both source and destination vertices of the graph as a tuple.

source
Graphs.SimpleGraphs.add_edge!Method
add_edge!(g::BipartiteGraph, i::Integer, j::Integer) -> Bool
add_edge!(
    g::BipartiteGraph,
    i::Integer,
    j::Integer,
    md
) -> Bool

Add an edge from source i to destination j in graph g.

source
Graphs.SimpleGraphs.add_edge!Method
add_edge!(g::BipartiteGraph, edge::BipartiteEdge) -> Bool
add_edge!(
    g::BipartiteGraph,
    edge::BipartiteEdge,
    md
) -> Bool

Add edge to graph g.

source
BipartiteGraphs.set_neighbors!Function
set_neighbors!(
    g::BipartiteGraph,
    i::Integer,
    new_neighbors
) -> Any

In graph g, set the neighbors of source vertex i to new_neighbors.

source
BipartiteGraphs.delete_srcs!Function
delete_srcs!(
    g::BipartiteGraph{I},
    srcs;
    rm_verts
) -> BipartiteGraph{I} where I

In graph g, remove all edges incident on source vertices in srcs. If rm_verts is true, also remove the vertices from the graph. Note that this will cause renumbering of source vertices.

source
BipartiteGraphs.delete_dsts!Function
delete_dsts!(
    g::BipartiteGraph,
    srcs;
    rm_verts
) -> BipartiteGraph{I, Nothing} where I<:Integer

In graph g, remove all edges incident on destination vertices in srcs. If rm_verts is true, also remove the vertices from the graph. Note that this will cause renumbering of destination vertices.

source
Graphs.LinAlg.incidence_matrixMethod
incidence_matrix(
    g::BipartiteGraph
) -> SparseArrays.SparseMatrixCSC{Bool, Int64}
incidence_matrix(
    g::BipartiteGraph,
    val
) -> SparseArrays.SparseMatrixCSC{Tv, Int64} where Tv

Obtain the incidence matrix for the BipartiteGraphg. val indicates the value to be used in non-zero entries of the returned sparse matrix.

source

Maximal matching

BipartiteGraphs.maximal_matchingFunction
maximal_matching(g::BipartiteGraph, [srcfilter], [dstfilter])

For a bipartite graph g, construct a maximal matching of destination to source vertices, subject to the constraint that vertices for which srcfilter or dstfilter, return false may not be matched.

source
BipartiteGraphs.construct_augmenting_path!Function
construct_augmenting_path!(m::Matching, g::BipartiteGraph, vsrc, dstfilter, vcolor = falses(ndsts(g)), ecolor = nothing) -> path_found::Bool

Try to construct an augmenting path in matching and if such a path is found, update the matching accordingly.

source
BipartiteGraphs.MatchingType

A matching between two sets of vertices in a bipartite graph. Maps destination vertices to their matched source vertices. U denotes the type that unmatched variables can take. Typically, this will be Unassigned but other types can be used for more complicated matchings.

source
Base.setindex!Method
setindex!(
    m::Matching{U},
    v::Union{Integer, U} where U,
    i::Integer
) -> Union{Integer, U} where U

Update i to match to v in matching m. Also updates the inverse matching, if present.

source
Base.push!Method
push!(m::Matching, v) -> Any

Append an element to the source vertices of the matching m, and match it to v.

source
BipartiteGraphs.completeMethod
complete(m::Matching{U}) -> Matching
complete(m::Matching{U}, N) -> Matching

Populate the inverse matching if it is not already computed. The optional parameter N specifies the size of the inverse matching vector.

source
BipartiteGraphs.invviewMethod
invview(m::Matching{U, V}) -> Matching

Return a view of the matching with the forward and inverse matchings swapped. Requires that the matching is complete.

source
invview(
    g::DiCMOBiGraph{Transposed, I} where I
) -> DiCMOBiGraph{_A, I, G} where {_A, I<:Integer, G<:BipartiteGraph{I, Nothing}}

Return a DiCMOBiGraph with the source and destination vertices swapped. The returned graph aliases g.

source

DiCMOBiGraph

BipartiteGraphs.DiCMOBiGraphType
struct DiCMOBiGraph

This data structure implements a "directed, contracted, matching-oriented" view of an original (undirected) bipartite graph. It has two modes, depending on the Transposed flag, which switches the direction of the induced matching.

Essentially the graph adapter performs two largely orthogonal functions [Transposed == true differences are indicated in square brackets]:

  1. It pairs an undirected bipartite graph with a matching of the destination vertex.

    This matching is used to induce an orientation on the otherwise undirected graph: Matched edges pass from destination to source [source to destination], all other edges pass in the opposite direction.

  2. It exposes the graph view obtained by contracting the destination [source] vertices along the matched edges.

The result of this operation is an induced, directed graph on the source [destination] vertices. The resulting graph has a few desirable properties. In particular, this graph is acyclic if and only if the induced directed graph on the original bipartite graph is acyclic.

Hypergraph interpretation

Consider the bipartite graph B as the incidence graph of some hypergraph H. Note that a matching M on B in the above sense is equivalent to determining an (1,n)-orientation on the hypergraph (i.e. each directed hyperedge has exactly one head, but any arbitrary number of tails). In this setting, this is simply the graph formed by expanding each directed hyperedge into n ordinary edges between the same vertices.

source
BipartiteGraphs.invviewMethod
invview(m::Matching{U, V}) -> Matching

Return a view of the matching with the forward and inverse matchings swapped. Requires that the matching is complete.

source
invview(
    g::DiCMOBiGraph{Transposed, I} where I
) -> DiCMOBiGraph{_A, I, G} where {_A, I<:Integer, G<:BipartiteGraph{I, Nothing}}

Return a DiCMOBiGraph with the source and destination vertices swapped. The returned graph aliases g.

source

Condensation graphs

Graphs.nvMethod
nv(icg::BipartiteGraphs.AbstractCondensationGraph) -> Any

Get the number of vertices (strongly connected components) in the condensation graph.

source
BipartiteGraphs.InducedCondensationGraphType
struct InducedCondensationGraph{G<:BipartiteGraph} <: BipartiteGraphs.AbstractCondensationGraph

For some bipartite-graph and a topologicall sorted list of connected components, represents the condensation DAG of the digraph formed by the orientation. I.e. this is a DAG of connected components formed by the destination vertices of some underlying bipartite graph. N.B.: This graph does not store explicit neighbor relations of the sccs. Therefor, the edge multiplicity is derived from the underlying bipartite graph, i.e. this graph is not strict.

source
BipartiteGraphs.MatchedCondensationGraphType
struct MatchedCondensationGraph{G<:DiCMOBiGraph} <: BipartiteGraphs.AbstractCondensationGraph

For some bipartite-graph and an orientation induced on its destination contraction, records the condensation DAG of the digraph formed by the orientation. I.e. this is a DAG of connected components formed by the destination vertices of some underlying bipartite graph. N.B.: This graph does not store explicit neighbor relations of the sccs. Therefor, the edge multiplicity is derived from the underlying bipartite graph, i.e. this graph is not strict.

source

Hyper-graphs

BipartiteGraphs.HyperGraphType
struct HyperGraph{V}

A hypergraph represented using a BipartiteGraph. Vertices of this graph are of type V.

Fields

  • labels::Dict{V, Int64} where V: Mapping from vertices to their integer ID.
  • invmap::Vector: Reverse mapping from integer ID to vertices.
  • graph::BipartiteGraph{Int64, Nothing}: Core data structure for storing the hypergraph. Each hyperedge is a source vertex and has bipartite edges to the connection vertices it is incident on.
source
Graphs.SimpleGraphs.add_vertex!Method
add_vertex!(graph::HyperGraph{V}, dst) -> Int64

Add the given vertex to the connection graph. Return the integer ID of the added vertex. No-op if the vertex already exists.

source
Graphs.SimpleGraphs.add_edge!Method
add_edge!(
    graph::HyperGraph{V},
    src::Union{Set{V}, Array{V, 1}, Tuple{Vararg{V}}}
) -> Union{Int64, Vector{Vector{Int64}}}

Add the given hyperedge to the connection graph. Adds all vertices in the given edge if they do not exist. Returns the integer ID of the added edge.

source
Graphs.nvMethod
nv(g::HyperGraph) -> Int64

Get the number of vertices in the hypergraph.

source
Graphs.has_vertexMethod
has_vertex(g::HyperGraph{V}, v) -> Bool

Check if vertex v exists in the hypergraph.

source
Graphs.neMethod
ne(g::HyperGraph) -> Any

Get the number of hyperedges in the hypergraph. Only counts non-empty hyperedges.

source
Graphs.has_edgeMethod
has_edge(g::HyperGraph{V}, edge::HyperEdge{V}) -> Bool

Check if a hyperedge exists in the hypergraph. The edge can be specified as a HyperEdge or as a collection of vertices.

source
Graphs.SimpleGraphs.rem_edge!Method
rem_edge!(g::HyperGraph, edge::HyperEdge) -> Bool

Remove a hyperedge from the hypergraph. The edge can be specified as a HyperEdge or as a collection of vertices. Returns true if the edge was removed, false if it did not exist.

source
Graphs.edgesMethod
edges(g::HyperGraph{V}) -> BipartiteGraphs.HyperEdgeIter

Iterate over all hyperedges in the hypergraph.

source
Base.empty!Method
empty!(g::HyperGraph) -> HyperGraph

Remove all hyperedges and vertices from the hypergraph.

source
Graphs.connected_componentsMethod
connected_components(
    graph::HyperGraph{V}
) -> Vector{T} where T<:(Vector)

Find the connected components of the given hypergraph.

source
BipartiteGraphs.neighborsFunction
neighbors(g::HyperGraph, edge_id::Int64) -> Vector

Get the vertices in a hyperedge (specified by its integer ID).

source
neighbors(g::HyperGraph, edge::HyperEdge) -> Vector

Get the vertices in a hyperedge.

source