PGROUTING  3.2
Pgr_randomSpanningTree< G > Class Template Reference

#include "pgr_randomSpanningTree.hpp"

Collaboration diagram for Pgr_randomSpanningTree< G >:

Public Types

typedef G::E E
 
typedef G::V V
 

Public Member Functions

std::vector< pgr_randomSpanningTree_trandomSpanningTree (G &graph, int64_t root_vertex)
 

Private Member Functions

std::vector< pgr_randomSpanningTree_tundirectedGraph (const G &graph, int64_t root_vertex)
 

Private Attributes

std::vector< Vpredecessors
 

Detailed Description

template<class G>
class Pgr_randomSpanningTree< G >

Definition at line 47 of file pgr_randomSpanningTree.hpp.

Member Typedef Documentation

◆ E

template<class G >
typedef G::E Pgr_randomSpanningTree< G >::E

Definition at line 57 of file pgr_randomSpanningTree.hpp.

◆ V

template<class G >
typedef G::V Pgr_randomSpanningTree< G >::V

Definition at line 56 of file pgr_randomSpanningTree.hpp.

Member Function Documentation

◆ randomSpanningTree()

template<class G >
std::vector< pgr_randomSpanningTree_t > Pgr_randomSpanningTree< G >::randomSpanningTree ( G &  graph,
int64_t  root_vertex 
)

Definition at line 137 of file pgr_randomSpanningTree.hpp.

139  {
140  predecessors.clear();
141  // TODO(aps)
142  // Currently only running for undirected graph
143  return undirectedGraph(
144  graph,
145  root_vertex);
146 }

Referenced by pgr_randomSpanningTree().

◆ undirectedGraph()

template<class G >
std::vector< pgr_randomSpanningTree_t > Pgr_randomSpanningTree< G >::undirectedGraph ( const G &  graph,
int64_t  root_vertex 
)
inlineprivate

Definition at line 69 of file pgr_randomSpanningTree.hpp.

71  {
72  std::ostringstream log;
73  auto v_root(graph.get_V(root_vertex));
74 
75  std::minstd_rand rng;
76 
77  /* abort in case of an interruption occurs (e.g. the query is being cancelled) */
78  CHECK_FOR_INTERRUPTS();
79 
80  // TODO(aps)
81  // This function is running in infinite loop
82  try {
83  boost::random_spanning_tree(
84  graph.graph,
85  rng,
86  boost::root_vertex(v_root)
87  .predecessor_map(&predecessors[0])
88  .weight_map(get(&G::G_T_E::cost, graph.graph)));
89  } catch (std::exception const &ex) {
90  log << ex.what();
91  } catch (...) {
92  log << "Unknown exception caught";
93  }
94 
95  std::vector< pgr_randomSpanningTree_t > resul;
96  return resul;
97  std::vector< pgr_randomSpanningTree_t > results;
98  double totalcost = 0;
100 
101  tmp.root_vertex = root_vertex;
102  tmp.edge = -1;
103  tmp.cost = 0;
104  tmp.tree_cost = totalcost;
105 
106  results.push_back(tmp);
107 
108  for (size_t j = 0; j < predecessors.size(); j++) {
109  if (j != v_root) {
111 
112  auto start_node = graph.graph[predecessors[j]].id;
113  auto end_node = graph.graph[j].id; // node
114 
115  auto v_sn(graph.get_V(start_node));
116  auto v_en(graph.get_V(end_node));
117 
118  auto cost = graph[boost::edge(
119  predecessors[j], j, graph.graph).first].cost;
120  auto edge_id =
121  graph.get_edge_id(v_sn, v_en, cost);
122  totalcost += cost;
123 
124  tmp.root_vertex = root_vertex;
125  tmp.edge = edge_id; // edge_id
126  tmp.cost = cost; // cost
127  tmp.tree_cost = totalcost; // tree_cost
128  results.push_back(tmp);
129  }
130  }
131  return results;
132  }

References pgr_randomSpanningTree_t::cost, pgr_randomSpanningTree_t::edge, Pgr_randomSpanningTree< G >::predecessors, pgr_randomSpanningTree_t::root_vertex, and pgr_randomSpanningTree_t::tree_cost.

Member Data Documentation

◆ predecessors

template<class G >
std::vector< V > Pgr_randomSpanningTree< G >::predecessors
private

The documentation for this class was generated from the following file:
pgr_randomSpanningTree_t::root_vertex
int64_t root_vertex
Definition: pgr_randomSpanningTree_t.h:39
Pgr_randomSpanningTree::undirectedGraph
std::vector< pgr_randomSpanningTree_t > undirectedGraph(const G &graph, int64_t root_vertex)
Definition: pgr_randomSpanningTree.hpp:69
pgr_randomSpanningTree_t::cost
double cost
Definition: pgr_randomSpanningTree_t.h:41
pgr_randomSpanningTree_t
Definition: pgr_randomSpanningTree_t.h:37
pgr_randomSpanningTree_t::edge
int64_t edge
Definition: pgr_randomSpanningTree_t.h:40
Pgr_randomSpanningTree::predecessors
std::vector< V > predecessors
Definition: pgr_randomSpanningTree.hpp:65
pgr_randomSpanningTree_t::tree_cost
double tree_cost
Definition: pgr_randomSpanningTree_t.h:42