This file defines maximum matching algorithm functions.
More...
#include <algorithm>
#include <vector>
#include "match.h"
Go to the source code of this file.
|
bool | dfs (const Graph &graph, int rnode, std::vector< bool > &seen, std::vector< int > &match) |
| Depth first search recursive function which returns true if a matching for right node / rnode is possible. More...
|
|
bool | match_exists (const Graph &graph) |
| Check if there exists a matching for all cards. More...
|
|
std::vector< int > | match_find (const Graph &graph) |
| Find a match of the given graph. More...
|
|
This file defines maximum matching algorithm functions.
Definition in file match.cpp.
◆ dfs()
bool dfs |
( |
const Graph & |
graph, |
|
|
int |
rnode, |
|
|
std::vector< bool > & |
seen, |
|
|
std::vector< int > & |
match |
|
) |
| |
Depth first search recursive function which returns true if a matching for right node / rnode
is possible.
Definition at line 16 of file match.cpp.
18 for (
size_t lnode = 0; lnode < graph.size(); lnode++) {
19 if (graph[lnode][rnode] && !seen[lnode]) {
21 if (match[lnode] < 0 ||
dfs(graph, match[lnode], seen, match)) {
bool dfs(const Graph &graph, int rnode, std::vector< bool > &seen, std::vector< int > &match)
Depth first search recursive function which returns true if a matching for right node / rnode is poss...
◆ match_exists()
bool match_exists |
( |
const Graph & |
graph | ) |
|
Check if there exists a matching for all cards.
- See also
- match_find
Definition at line 35 of file match.cpp.
38 return std::find(match.begin(), match.end(), -1) == match.end();
std::vector< int > match_find(const Graph &graph)
Find a match of the given graph.
◆ match_find()
std::vector<int> match_find |
( |
const Graph & |
graph | ) |
|
Find a match of the given graph.
- Returns
- A vector list with integers representing to which rnode the lnode at the given index is connected, -1 indicates a connection to none.
Definition at line 47 of file match.cpp.
49 std::vector<int> match(graph.size(), -1);
50 for (
int rnode = 0; rnode < (int)graph.size(); rnode++) {
51 std::vector<bool> seen(graph.size(),
false);
52 dfs(graph, rnode, seen, match);