Package org.graph4j.matching
Class MaximalCardinalityMatching
java.lang.Object
org.graph4j.GraphAlgorithm
org.graph4j.matching.MaximalCardinalityMatching
- All Implemented Interfaces:
MatchingAlgorithm
Creates a maximal cardinality matching either randomly or using a
simple heuristic.
A maximal cardinality matching has the property that no other edge can be
added to it. A maximum cardinality matching is the largest possible matching.
In any graph, any maximal matching has size at least 1/2 of the maximum
matching.
- Author:
- Cristian Frăsinaru
-
Field Summary
Fields inherited from class org.graph4j.GraphAlgorithm
directed, graph -
Constructor Summary
ConstructorsConstructorDescriptionMaximalCardinalityMatching(Graph graph) Creates a maximal matching algorithm that iterates over the edges of the graph in the order given by the sum of degrees of the edges endpoints.This method has O(m + m log n) time complexity and produces, in general, better results than the random version.MaximalCardinalityMatching(Graph graph, boolean random) Creates a maximal matching algorithm that iterates over the edges of the graph in a random order(random=true)or in the order in which the edges are internally stored(random=false).This method has O(m) time complexity.MaximalCardinalityMatching(Graph graph, Comparator<Edge> comparator) Creates a maximal matching algorithm that iterates over the edges of the graph in the order given by a specified comparator.This method has O(m + m log n) time complexity. -
Method Summary
Methods inherited from class org.graph4j.GraphAlgorithm
getGraphMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.graph4j.matching.MatchingAlgorithm
getGraph
-
Constructor Details
-
MaximalCardinalityMatching
Creates a maximal matching algorithm that iterates over the edges of the graph in the order given by the sum of degrees of the edges endpoints.This method has O(m + m log n) time complexity and produces, in general, better results than the random version.- Parameters:
graph- the input graph.
-
MaximalCardinalityMatching
Creates a maximal matching algorithm that iterates over the edges of the graph in a random order(random=true)or in the order in which the edges are internally stored(random=false).This method has O(m) time complexity.- Parameters:
graph- the input graph.random- iftruecreates a random matching.
-
MaximalCardinalityMatching
Creates a maximal matching algorithm that iterates over the edges of the graph in the order given by a specified comparator.This method has O(m + m log n) time complexity.- Parameters:
graph- the input graph.comparator- a comparator for sorting the edges.
-
-
Method Details
-
getMatching
Returns a maximal matching.- Specified by:
getMatchingin interfaceMatchingAlgorithm- Returns:
- a maximal matching.
-