Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
Matching.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/Graph.h>
35
36namespace ogdf {
37
39namespace Matching {
40
43template<typename EdgeContainer>
44inline bool isMatching(const Graph& graph, const EdgeContainer& matching) {
45 NodeArray<bool> covered {graph, false};
46
47 for (edge e : matching) {
48 for (node v : e->nodes()) {
49 if (covered[v]) {
50 return false;
51 }
52 covered[v] = true;
53 if (e->isSelfLoop()) {
54 break;
55 }
56 }
57 }
58
59 return true;
60}
61
64template<typename EdgeContainer>
65bool isMaximal(const Graph& graph, const EdgeContainer& matching, edge& addable) {
66 addable = nullptr;
67
68 EdgeArray<bool> covered {graph, false};
69
70 for (edge e : matching) {
71 for (node v : e->nodes()) {
72 for (adjEntry adj : v->adjEntries) {
73 covered[adj->theEdge()] = true;
74 }
75 }
76 }
77
78 for (edge e : graph.edges) {
79 if (!covered[e]) {
80 addable = e;
81 return false;
82 }
83 }
84
85 return true;
86}
87
90template<typename EdgeContainer>
91inline bool isMaximal(const Graph& graph, const EdgeContainer& matching) {
93 return isMaximal(graph, matching, ignored);
94}
95
98template<typename EdgeContainer>
99inline bool isMaximalMatching(const Graph& graph, const EdgeContainer& matching) {
100 return isMatching(graph, matching) && isMaximal(graph, matching);
101}
102
105template<typename EdgeContainer>
106inline bool isPerfect(const Graph& graph, const EdgeContainer& matching) {
107 return 2 * int(matching.size()) == graph.numberOfNodes();
108}
109
112template<typename EdgeContainer>
113inline bool isPerfectMatching(const Graph& graph, const EdgeContainer& matching) {
114 return isMatching(graph, matching) && isPerfect(graph, matching);
115}
116
120
134
135}
136}
Includes declaration of graph class.
Class for adjacency list elements.
Definition Graph_d.h:79
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
Definition ArrayBuffer.h:56
Dynamic arrays indexed with edges.
Definition EdgeArray.h:125
Class for the representation of edges.
Definition Graph_d.h:300
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:521
int numberOfNodes() const
Returns the number of nodes in the graph.
Definition Graph_d.h:622
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition Graph_d.h:592
Doubly linked lists (maintaining the length of the list).
Definition List.h:1435
Dynamic arrays indexed with nodes.
Definition NodeArray.h:125
Class for the representation of nodes.
Definition Graph_d.h:177
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition config.h:101
bool isPerfectMatching(const Graph &graph, const EdgeContainer &matching)
Checks in O(|V| + size of matching) if matching is a perfect matching.
Definition Matching.h:113
int findMaximumCardinalityMatching(const Graph &G, const List< node > &U, const List< node > &V, EdgeArray< bool > &matching)
Finds a maximum cardinality matching in the bipartite graph G = (U+V, E) in O(sqrt(|U+V|) * |E|) time...
void findMaximalMatching(const Graph &graph, ArrayBuffer< edge > &matching)
Obtains a maximal matching in O(|E|) time.
bool isMatching(const Graph &graph, const EdgeContainer &matching)
Checks in time O(|V| + size of matching) if the given set of edges represents a matching.
Definition Matching.h:44
bool isMaximalMatching(const Graph &graph, const EdgeContainer &matching)
Checks in O(|V| + |E|) time if matching is a maximal matching.
Definition Matching.h:99
bool isPerfect(const Graph &graph, const EdgeContainer &matching)
Checks in O(1) if matching (assuming it is a matching and the graph is simple and connected) is perfe...
Definition Matching.h:106
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
bool isMaximal(const Graph &graph, const EdgeContainer &matching, edge &addable)
Checks in time O(|E|) if there are edges that could be added to matching.
Definition Matching.h:65
The namespace for all OGDF objects.