bipartite_matching
A bipartite graph is a graph in which we can divide nodes into two independent sets, such that every relationship connects nodes between these sets. No connection can be established within the set. Matching in bipartite graphs (bipartite matching) is described as a set of relationships that are picked in a way to not share an endpoint. Furthermore, maximum matching is such matching of maximum cardinality of the chosen relationships set. The algorithm runs in O(|V|*|E|) time where V represents a set of vertices (nodes) and E represents a set of edges (relationships).
Trait | Value |
---|---|
Module type | algorithm |
Implementation | C++ |
Graph direction | undirected |
Edge weights | unweighted |
Parallelism | sequential |
Procedures
You can execute this algorithm on graph projections, subgraphs or portions of the graph.
max()
Output:
maximum_bipartite_matching: integer
➡ Maximum bipartite matching, the cardinality of maximum matching relationship subset. If graph is not bipartite, returned value is zero(0).
Usage:
CALL bipartite_matching.max()
YIELD maximum_bipartite_matching;
Example
Database state
The database contains the following data:
Add new data
New data is added to the database:
MERGE (a:Node {id: 0}) MERGE (b:Node {id: 3}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 0}) MERGE (b:Node {id: 5}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 1}) MERGE (b:Node {id: 3}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 1}) MERGE (b:Node {id: 4}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 2}) MERGE (b:Node {id: 4}) CREATE (a)-[:RELATION]->(b);
Get maximung biparte matching
Get the values using the following query:
CALL bipartite_matching.max()
YIELD maximum_bipartite_matching
RETURN maximum_bipartite_matching;
Results:
+----------------------------+
| maximum_bipartite_matching |
+----------------------------+
| 3 |
+----------------------------+