27 #ifndef INCLUDE_MAX_FLOW_PGR_MAXIMUMCARDINALITYMATCHING_HPP_
28 #define INCLUDE_MAX_FLOW_PGR_MAXIMUMCARDINALITYMATCHING_HPP_
32 #include <boost/config.hpp>
33 #include <boost/graph/adjacency_list.hpp>
34 #include <boost/graph/max_cardinality_matching.hpp>
47 typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS>
49 typedef boost::adjacency_list<boost::listS, boost::vecS, boost::directedS>
59 typedef typename boost::graph_traits<G>::vertex_descriptor
V;
60 typedef typename boost::graph_traits<G>::edge_descriptor
E;
61 typedef typename boost::graph_traits<G>::vertex_iterator
V_it;
62 typedef typename boost::graph_traits<G>::edge_iterator
E_it;
81 std::set<int64_t> vertices;
82 for (
size_t i = 0; i < total_tuples; ++i) {
83 vertices.insert(data_edges[i].source);
84 vertices.insert(data_edges[i].target);
86 for (int64_t
id : vertices) {
88 id_to_V.insert(std::pair<int64_t, V>(
id, v));
89 V_to_id.insert(std::pair<V, int64_t>(v,
id));
93 for (
size_t i = 0; i < total_tuples; ++i) {
98 if (data_edges[i].going) {
99 boost::tie(e1, added) = boost::add_edge(v1, v2,
boost_graph);
100 E_to_id.insert(std::pair<E, int64_t>(e1, data_edges[i].
id));
102 if (data_edges[i].coming) {
103 boost::tie(e2, added) = boost::add_edge(v2, v1,
boost_graph);
104 E_to_id.insert(std::pair<E, int64_t>(e2, data_edges[i].
id));
109 std::vector<pgr_basic_edge_t>
111 std::vector<V> mate_map(boost::num_vertices(
boost_graph));
112 std::vector<pgr_basic_edge_t> matched_vertices;
119 std::vector<bool> already_matched(num_vertices(
boost_graph),
false);
120 for (boost::tie(vi, vi_end) = boost::vertices(
boost_graph);
131 boost::tie(e, exists) = boost::edge(*vi, mate_map[*vi],
boost_graph);
132 if (((uint64_t)mate_map[*vi]
133 != boost::graph_traits<G>::null_vertex())
134 && exists && !already_matched[*vi]
135 && !already_matched[mate_map[*vi]]) {
136 already_matched[*vi] =
true;
137 already_matched[mate_map[*vi]] =
true;
142 matched_vertices.push_back(matched_couple);
146 for (boost::tie(vi, vi_end) = boost::vertices(
boost_graph);
149 boost::tie(e, exists) =
151 if (((uint64_t)mate_map[*vi]
152 != boost::graph_traits<G>::null_vertex())
153 && (*vi < (uint64_t)mate_map[*vi])) {
158 matched_vertices.push_back(matched_couple);
162 return matched_vertices;
174 #endif // INCLUDE_MAX_FLOW_PGR_MAXIMUMCARDINALITYMATCHING_HPP_