PGROUTING  2.5
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

void create_max_cardinality_graph (pgr_basic_edge_t *data_edges, size_t total_tuples)
 
V get_boost_vertex (int64_t id)
 
int64_t get_edge_id (E e)
 
void get_matched_vertices (std::vector< pgr_basic_edge_t > &matched_vertices, const std::vector< int64_t > &mate_map)
 
int64_t get_vertex_id (V v)
 
void maximum_cardinality_matching (std::vector< int64_t > &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

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

Definition at line 60 of file pgr_maximumcardinalitymatching.hpp.

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.

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

Definition at line 59 of file pgr_maximumcardinalitymatching.hpp.

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.

Member Function Documentation

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

Definition at line 80 of file pgr_maximumcardinalitymatching.hpp.

References pgrouting::flow::PgrCardinalityGraph< G >::get_boost_vertex().

Referenced by do_pgr_maximum_cardinality_matching().

81  {
82  std::set<int64_t> vertices;
83  for (size_t i = 0; i < total_tuples; ++i) {
84  vertices.insert(data_edges[i].source);
85  vertices.insert(data_edges[i].target);
86  }
87  for (int64_t id : vertices) {
88  V v = add_vertex(boost_graph);
89  id_to_V.insert(std::pair<int64_t, V>(id, v));
90  V_to_id.insert(std::pair<V, int64_t>(v, id));
91  }
92  bool added;
93 
94  for (size_t i = 0; i < total_tuples; ++i) {
95  V v1 = get_boost_vertex(data_edges[i].source);
96  V v2 = get_boost_vertex(data_edges[i].target);
97  E e1;
98  E e2;
99  if (data_edges[i].going) {
100  boost::tie(e1, added) = boost::add_edge(v1, v2, boost_graph);
101  E_to_id.insert(std::pair<E, int64_t>(e1, data_edges[i].id));
102  }
103  if (data_edges[i].coming) {
104  boost::tie(e2, added) = boost::add_edge(v2, v1, boost_graph);
105  E_to_id.insert(std::pair<E, int64_t>(e2, data_edges[i].id));
106  }
107  }
108  }
boost::graph_traits< G >::vertex_descriptor V
boost::graph_traits< G >::edge_descriptor E

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 68 of file pgr_maximumcardinalitymatching.hpp.

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

68  {
69  return id_to_V[id];
70  }

Here is the caller graph for this function:

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

Definition at line 76 of file pgr_maximumcardinalitymatching.hpp.

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

76  {
77  return E_to_id[e];
78  }

Here is the caller graph for this function:

template<class G >
void pgrouting::flow::PgrCardinalityGraph< G >::get_matched_vertices ( std::vector< pgr_basic_edge_t > &  matched_vertices,
const std::vector< int64_t > &  mate_map 
)
inline

Definition at line 110 of file pgr_maximumcardinalitymatching.hpp.

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

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

Here is the call graph for this function:

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

Definition at line 72 of file pgr_maximumcardinalitymatching.hpp.

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

72  {
73  return V_to_id[v];
74  }

Here is the caller graph for this function:

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

Definition at line 162 of file pgr_maximumcardinalitymatching.hpp.

162  {
163  edmonds_maximum_cardinality_matching(boost_graph,
164  &mate_map[0]);
165  }

Member Data Documentation

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

Definition at line 57 of file pgr_maximumcardinalitymatching.hpp.

template<class G >
std::map<E, int64_t> pgrouting::flow::PgrCardinalityGraph< G >::E_to_id

Definition at line 66 of file pgr_maximumcardinalitymatching.hpp.

template<class G >
std::map<int64_t, V> pgrouting::flow::PgrCardinalityGraph< G >::id_to_V

Definition at line 64 of file pgr_maximumcardinalitymatching.hpp.

template<class G >
std::map<V, int64_t> pgrouting::flow::PgrCardinalityGraph< G >::V_to_id

Definition at line 65 of file pgr_maximumcardinalitymatching.hpp.


The documentation for this class was generated from the following file: