PGROUTING  3.2
pgrouting::flow::PgrCardinalityGraph< G > Class Template Reference

#include "pgr_maximumcardinalitymatching.hpp"

Collaboration diagram for pgrouting::flow::PgrCardinalityGraph< G >:

Public Types

typedef boost::graph_traits< G >::edge_descriptor E
 
typedef boost::graph_traits< G >::edge_iterator E_it
 
typedef boost::graph_traits< G >::vertex_descriptor V
 
typedef boost::graph_traits< G >::vertex_iterator V_it
 

Public Member Functions

 PgrCardinalityGraph (pgr_basic_edge_t *data_edges, size_t total_tuples)
 
V get_boost_vertex (int64_t id)
 
int64_t get_edge_id (E e)
 
std::vector< pgr_basic_edge_tget_matched_vertices ()
 
int64_t get_vertex_id (V v)
 
void maximum_cardinality_matching (std::vector< V > &mate_map)
 

Public Attributes

boost_graph
 
std::map< E, int64_t > E_to_id
 
std::map< int64_t, Vid_to_V
 
std::map< V, int64_t > V_to_id
 

Detailed Description

template<class G>
class pgrouting::flow::PgrCardinalityGraph< G >

Definition at line 55 of file pgr_maximumcardinalitymatching.hpp.

Member Typedef Documentation

◆ E

template<class G >
typedef boost::graph_traits<G>::edge_descriptor pgrouting::flow::PgrCardinalityGraph< G >::E

Definition at line 60 of file pgr_maximumcardinalitymatching.hpp.

◆ E_it

template<class G >
typedef boost::graph_traits<G>::edge_iterator pgrouting::flow::PgrCardinalityGraph< G >::E_it

Definition at line 62 of file pgr_maximumcardinalitymatching.hpp.

◆ V

template<class G >
typedef boost::graph_traits<G>::vertex_descriptor pgrouting::flow::PgrCardinalityGraph< G >::V

Definition at line 59 of file pgr_maximumcardinalitymatching.hpp.

◆ V_it

template<class G >
typedef boost::graph_traits<G>::vertex_iterator pgrouting::flow::PgrCardinalityGraph< G >::V_it

Definition at line 61 of file pgr_maximumcardinalitymatching.hpp.

Constructor & Destructor Documentation

◆ PgrCardinalityGraph()

template<class G >
pgrouting::flow::PgrCardinalityGraph< G >::PgrCardinalityGraph ( pgr_basic_edge_t data_edges,
size_t  total_tuples 
)
inline

Definition at line 80 of file pgr_maximumcardinalitymatching.hpp.

80  {
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);
85  }
86  for (int64_t id : vertices) {
87  V v = add_vertex(boost_graph);
88  id_to_V.insert(std::pair<int64_t, V>(id, v));
89  V_to_id.insert(std::pair<V, int64_t>(v, id));
90  }
91  bool added;
92 
93  for (size_t i = 0; i < total_tuples; ++i) {
94  V v1 = get_boost_vertex(data_edges[i].source);
95  V v2 = get_boost_vertex(data_edges[i].target);
96  E e1;
97  E e2;
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));
101  }
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));
105  }
106  }
107  }

References pgrouting::flow::PgrCardinalityGraph< G >::boost_graph, pgrouting::flow::PgrCardinalityGraph< G >::E_to_id, pgrouting::flow::PgrCardinalityGraph< G >::get_boost_vertex(), pgrouting::flow::PgrCardinalityGraph< G >::id_to_V, and pgrouting::flow::PgrCardinalityGraph< G >::V_to_id.

Member Function Documentation

◆ get_boost_vertex()

template<class G >
V pgrouting::flow::PgrCardinalityGraph< G >::get_boost_vertex ( int64_t  id)
inline

◆ get_edge_id()

template<class G >
int64_t pgrouting::flow::PgrCardinalityGraph< G >::get_edge_id ( E  e)
inline

◆ get_matched_vertices()

template<class G >
std::vector<pgr_basic_edge_t> pgrouting::flow::PgrCardinalityGraph< G >::get_matched_vertices ( )
inline

Definition at line 110 of file pgr_maximumcardinalitymatching.hpp.

110  {
111  std::vector<V> mate_map(boost::num_vertices(boost_graph));
112  std::vector<pgr_basic_edge_t> matched_vertices;
114 
115  V_it vi, vi_end;
116  E e;
117  bool exists;
118  if (boost::is_directed(boost_graph)) {
119  std::vector<bool> already_matched(num_vertices(boost_graph), false);
120  for (boost::tie(vi, vi_end) = boost::vertices(boost_graph);
121  vi != vi_end;
122  ++vi) {
123  /*
124  * For each vertex I check:
125  * 1) It is matched with a non-null vertex
126  * 2) An edge exists from this vertex to his mate
127  * 3) The vertices have not been matched already
128  * (this last point prevents having double output with reversed
129  * source and target)
130  */
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;
138  pgr_basic_edge_t matched_couple;
139  matched_couple.source = get_vertex_id(*vi);
140  matched_couple.target = get_vertex_id(mate_map[*vi]);
141  matched_couple.edge_id = get_edge_id(e);
142  matched_vertices.push_back(matched_couple);
143  }
144  }
145  } else {
146  for (boost::tie(vi, vi_end) = boost::vertices(boost_graph);
147  vi != vi_end;
148  ++vi) {
149  boost::tie(e, exists) =
150  boost::edge(*vi, mate_map[*vi], boost_graph);
151  if (((uint64_t)mate_map[*vi]
152  != boost::graph_traits<G>::null_vertex())
153  && (*vi < (uint64_t)mate_map[*vi])) {
154  pgr_basic_edge_t matched_couple;
155  matched_couple.source = get_vertex_id(*vi);
156  matched_couple.target = get_vertex_id(mate_map[*vi]);
157  matched_couple.edge_id = get_edge_id(e);
158  matched_vertices.push_back(matched_couple);
159  }
160  }
161  }
162  return matched_vertices;
163  }

References pgrouting::flow::PgrCardinalityGraph< G >::boost_graph, pgr_basic_edge_t::edge_id, pgrouting::flow::PgrCardinalityGraph< G >::get_edge_id(), pgrouting::flow::PgrCardinalityGraph< G >::get_vertex_id(), pgrouting::flow::PgrCardinalityGraph< G >::maximum_cardinality_matching(), pgr_basic_edge_t::source, and pgr_basic_edge_t::target.

◆ get_vertex_id()

template<class G >
int64_t pgrouting::flow::PgrCardinalityGraph< G >::get_vertex_id ( V  v)
inline

◆ maximum_cardinality_matching()

template<class G >
void pgrouting::flow::PgrCardinalityGraph< G >::maximum_cardinality_matching ( std::vector< V > &  mate_map)
inline

Definition at line 165 of file pgr_maximumcardinalitymatching.hpp.

165  {
166  edmonds_maximum_cardinality_matching(boost_graph,
167  &mate_map[0]);
168  }

References pgrouting::flow::PgrCardinalityGraph< G >::boost_graph.

Referenced by pgrouting::flow::PgrCardinalityGraph< G >::get_matched_vertices().

Member Data Documentation

◆ boost_graph

◆ E_to_id

◆ id_to_V

◆ V_to_id


The documentation for this class was generated from the following file:
pgrouting::flow::PgrCardinalityGraph::get_boost_vertex
V get_boost_vertex(int64_t id)
Definition: pgr_maximumcardinalitymatching.hpp:68
pgrouting::flow::PgrCardinalityGraph::maximum_cardinality_matching
void maximum_cardinality_matching(std::vector< V > &mate_map)
Definition: pgr_maximumcardinalitymatching.hpp:165
pgr_basic_edge_t::source
int64_t source
Definition: pgr_basic_edge_t.h:40
pgr_basic_edge_t::edge_id
int64_t edge_id
Definition: pgr_basic_edge_t.h:44
pgrouting::flow::PgrCardinalityGraph::E_to_id
std::map< E, int64_t > E_to_id
Definition: pgr_maximumcardinalitymatching.hpp:66
pgr_basic_edge_t::target
int64_t target
Definition: pgr_basic_edge_t.h:41
pgrouting::flow::PgrCardinalityGraph::E
boost::graph_traits< G >::edge_descriptor E
Definition: pgr_maximumcardinalitymatching.hpp:60
pgrouting::flow::PgrCardinalityGraph::boost_graph
G boost_graph
Definition: pgr_maximumcardinalitymatching.hpp:57
pgr_basic_edge_t
Definition: pgr_basic_edge_t.h:38
pgrouting::flow::PgrCardinalityGraph::get_vertex_id
int64_t get_vertex_id(V v)
Definition: pgr_maximumcardinalitymatching.hpp:72
pgrouting::flow::PgrCardinalityGraph::V_to_id
std::map< V, int64_t > V_to_id
Definition: pgr_maximumcardinalitymatching.hpp:65
pgrouting::flow::PgrCardinalityGraph::get_edge_id
int64_t get_edge_id(E e)
Definition: pgr_maximumcardinalitymatching.hpp:76
pgrouting::flow::PgrCardinalityGraph::V_it
boost::graph_traits< G >::vertex_iterator V_it
Definition: pgr_maximumcardinalitymatching.hpp:61
pgrouting::flow::PgrCardinalityGraph::V
boost::graph_traits< G >::vertex_descriptor V
Definition: pgr_maximumcardinalitymatching.hpp:59
pgrouting::flow::PgrCardinalityGraph::id_to_V
std::map< int64_t, V > id_to_V
Definition: pgr_maximumcardinalitymatching.hpp:64