Package org.graph4j.util
Class Matching
java.lang.Object
org.graph4j.util.Matching
A matching or independent edge set is a set of edges
without common vertices.
- Author:
- Cristian Frăsinaru
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(int v, int u) booleancontains(int v, int u) booleancovers(int v) Returnstrueif there is an edge in the matching incident to the given vertex.edges()booleaninthashCode()booleanA perfect matching of a graph is a matching in which every vertex of the graph is incident to exactly one edge of the matching.booleanisValid()A matching is valid if each vertex of the graph appears in at most one edge of that matching.intmate(int v) The mate of a vertex v is a vertex u such that the edge vu belongs to the matching.protected booleanremove(int v, int u) intsize()Returns the number of edges in the matching.toString()doubleweight()Computes the sum of the weights associated with each edge in the matching.
-
Constructor Details
-
Matching
-
-
Method Details
-
add
public boolean add(int v, int u) -
remove
protected boolean remove(int v, int u) -
contains
public boolean contains(int v, int u) -
size
public int size()Returns the number of edges in the matching.- Returns:
- the number of edges in the matching.
-
edges
-
covers
public boolean covers(int v) Returnstrueif there is an edge in the matching incident to the given vertex.- Parameters:
v- a vertex number.- Returns:
trueif the matching covers the given vertex.
-
mate
public int mate(int v) The mate of a vertex v is a vertex u such that the edge vu belongs to the matching.- Parameters:
v- a vertex number.- Returns:
- the mate of v in the matching, or
-1if it has no mate.
-
isPerfect
public boolean isPerfect()A perfect matching of a graph is a matching in which every vertex of the graph is incident to exactly one edge of the matching.- Returns:
trueif the matching is perfect.
-
weight
public double weight()Computes the sum of the weights associated with each edge in the matching.- Returns:
- the sum of all weights of the edges in the collection, including duplicates.
-
isValid
public boolean isValid()A matching is valid if each vertex of the graph appears in at most one edge of that matching.- Returns:
trueif the matching is valid,falseotherwise.
-
hashCode
public int hashCode() -
equals
-
toString
-