Quaternity
Functions
match.h File Reference

This file defines maximum matching algorithm function headers. More...

#include <vector>
#include "graph.h"

Go to the source code of this file.

Functions

std::vector< int > match_find (const Graph &graph)
 Find a match of the given graph. More...
 
bool match_exists (const Graph &graph)
 Check if there exists a matching for all cards. More...
 

Detailed Description

This file defines maximum matching algorithm function headers.

Definition in file match.h.

Function Documentation

◆ 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.

36 {
37  std::vector<int> match = match_find(graph);
38  return std::find(match.begin(), match.end(), -1) == match.end();
39 }
std::vector< int > match_find(const Graph &graph)
Find a match of the given graph.
Definition: match.cpp:47

◆ 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.

48 {
49  std::vector<int> match(graph.size(), -1); // FIXME Make match for left node, not for right.
50  for (int rnode = 0; rnode < (int)graph.size(); rnode++) {
51  std::vector<bool> seen(graph.size(), false);
52  dfs(graph, rnode, seen, match);
53  }
54  return match;
55 }
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...
Definition: match.cpp:16