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>
36#include <ogdf/basic/basic.h>
37
38#include <array>
39
40namespace ogdf {
41template<class E, class INDEX>
42class ArrayBuffer;
43template<class E>
44class List;
45
47namespace Matching {
48
51template<typename EdgeContainer>
52inline bool isMatching(const Graph& graph, const EdgeContainer& matching) {
53 NodeArray<bool> covered {graph, false};
54
55 for (edge e : matching) {
56 for (node v : e->nodes()) {
57 if (covered[v]) {
58 return false;
59 }
60 covered[v] = true;
61 if (e->isSelfLoop()) {
62 break;
63 }
64 }
65 }
66
67 return true;
68}
69
72template<typename EdgeContainer>
73bool isMaximal(const Graph& graph, const EdgeContainer& matching, edge& addable) {
74 addable = nullptr;
75
76 EdgeArray<bool> covered {graph, false};
77
78 for (edge e : matching) {
79 for (node v : e->nodes()) {
80 for (adjEntry adj : v->adjEntries) {
81 covered[adj->theEdge()] = true;
82 }
83 }
84 }
85
86 for (edge e : graph.edges) {
87 if (!covered[e]) {
88 addable = e;
89 return false;
90 }
91 }
92
93 return true;
94}
95
98template<typename EdgeContainer>
99inline bool isMaximal(const Graph& graph, const EdgeContainer& matching) {
100 edge ignored;
101 return isMaximal(graph, matching, ignored);
102}
103
106template<typename EdgeContainer>
107inline bool isMaximalMatching(const Graph& graph, const EdgeContainer& matching) {
108 return isMatching(graph, matching) && isMaximal(graph, matching);
109}
110
113template<typename EdgeContainer>
114inline bool isPerfect(const Graph& graph, const EdgeContainer& matching) {
115 return 2 * int(matching.size()) == graph.numberOfNodes();
116}
117
120template<typename EdgeContainer>
121inline bool isPerfectMatching(const Graph& graph, const EdgeContainer& matching) {
122 return isMatching(graph, matching) && isPerfect(graph, matching);
123}
124
128
141 const List<node>& V, EdgeArray<bool>& matching);
142
143}
144}
Includes declaration of graph class.
Decralation of GraphElement and GraphList classes.
Basic declarations, included by all source files.
Class for adjacency list elements.
Definition Graph_d.h:143
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
Definition ArrayBuffer.h:64
Class for the representation of edges.
Definition Graph_d.h:364
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
int numberOfNodes() const
Returns the number of nodes in the graph.
Definition Graph_d.h:979
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition Graph_d.h:932
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
Class for the representation of nodes.
Definition Graph_d.h:241
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition Graph_d.h:717
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
Definition config.h:117
bool isPerfectMatching(const Graph &graph, const EdgeContainer &matching)
Checks in O(|V| + size of matching) if matching is a perfect matching.
Definition Matching.h:121
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:52
bool isMaximalMatching(const Graph &graph, const EdgeContainer &matching)
Checks in O(|V| + |E|) time if matching is a maximal matching.
Definition Matching.h:107
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:114
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:73
The namespace for all OGDF objects.