alglib::graph Namespace Reference

Namespaces

 models
 

Classes

class  directed_graph
 
class  directed_graph< vertex_t, void, model >
 
class  edge_property
 
struct  edge_t
 
struct  edge_t< vertex_t, void >
 
class  undirected_graph
 
class  undirected_graph< vertex_t, void, model >
 
class  vertex_property
 

Functions

template<typename GraphType >
vertex_property< GraphType, typename GraphType::edge_type::attr_t > bellman_ford (const GraphType &G, const typename GraphType::vertex_type source)
 
template<typename GraphType , typename OutputIter >
OutputIter _single_bfs (const GraphType &G, const typename GraphType::vertex_type &start, vertex_property< GraphType, bool > &visited, OutputIter dest)
 
template<typename GraphType , typename OutputIter >
OutputIter single_bfs (const GraphType &G, const typename GraphType::vertex_type &start, OutputIter dest)
 
template<typename GraphType , typename OutputIter >
OutputIter bfs (const GraphType &G, const typename GraphType::vertex_type &start, OutputIter dest)
 
template<typename GraphType , typename OutputIter >
OutputIter bfs (const GraphType &G, OutputIter dest)
 
template<typename GraphType >
vertex_property< GraphType, int > connected_components (const GraphType &G)
 
template<typename GraphType , typename OutputIter >
OutputIter _single_preorder_dfs (const GraphType &G, const typename GraphType::vertex_type &start, vertex_property< GraphType, bool > &visited, OutputIter dest)
 
template<typename GraphType , typename OutputIter >
OutputIter single_preorder_dfs (const GraphType &G, const typename GraphType::vertex_type &start, OutputIter dest)
 
template<typename GraphType , typename OutputIter >
OutputIter _single_postorder_dfs (const GraphType &G, const typename GraphType::vertex_type &start, vertex_property< GraphType, bool > &visited, OutputIter dest)
 
template<typename GraphType , typename OutputIter >
OutputIter single_postorder_dfs (const GraphType &G, const typename GraphType::vertex_type &start, OutputIter dest)
 
template<typename GraphType , typename OutputIter >
OutputIter preorder_dfs (const GraphType &G, const typename GraphType::vertex_type start, OutputIter dest)
 
template<typename GraphType , typename OutputIter >
OutputIter preorder_dfs (const GraphType &G, OutputIter dest)
 
template<typename GraphType , typename OutputIter >
OutputIter postorder_dfs (const GraphType &G, const typename GraphType::vertex_type start, OutputIter dest)
 
template<typename GraphType , typename OutputIter >
OutputIter postorder_dfs (const GraphType &G, OutputIter dest)
 
template<typename vertex_t , typename attr_t >
std::ostream & operator<< (std::ostream &out, const edge_t< vertex_t, attr_t > &e)
 
template<typename vertex_t , typename attr_t >
edge_t< vertex_t, attr_t > make_edge (vertex_t from, vertex_t to, attr_t attribute)
 
template<typename GraphType , typename OutputIter >
OutputIter topological_order (const GraphType &G, OutputIter dest)
 

Function Documentation

template<typename GraphType , typename OutputIter >
OutputIter alglib::graph::_single_bfs ( const GraphType &  G,
const typename GraphType::vertex_type & start  ,
vertex_property< GraphType, bool > &  visited,
OutputIter  dest 
)
23  {
24 
25  typedef typename GraphType::vertex_type vertex_type;
26 
27  /* Maintains a list of unexplored vertices in order of their distance
28  * from the start vertex */
29  std::queue<vertex_type> frontier;
30 
31  /* Put `start` in the queue to start the bfs from */
32  frontier.push(start);
33 
34  while(!frontier.empty()) {
35  vertex_type inspect = frontier.front();
36  frontier.pop();
37  visited[inspect] = true;
38 
39  /* Put it into the output stream before inspection */
40  *dest++ = inspect;
41 
42  for(auto it = G.avbegin(inspect); it != G.avend(inspect); it++)
43  if(!visited(*it))
44  frontier.push(*it);
45  }
46  return dest;
47 }
template<typename GraphType , typename OutputIter >
OutputIter alglib::graph::_single_postorder_dfs ( const GraphType &  G,
const typename GraphType::vertex_type & start  ,
vertex_property< GraphType, bool > &  visited,
OutputIter  dest 
)
52  {
53  visited[start] = true;
54  for(auto it = G.avbegin(start); it != G.avend(start); it++)
55  if(!visited(*it))
56  dest = _single_postorder_dfs(G, *it, visited, dest);
57  *dest++ = start; // Put it on the output stream
58  return dest;
59 }
OutputIter _single_postorder_dfs(const GraphType &G, const typename GraphType::vertex_type &start, vertex_property< GraphType, bool > &visited, OutputIter dest)
Definition: dfs.h:49
template<typename GraphType , typename OutputIter >
OutputIter alglib::graph::_single_preorder_dfs ( const GraphType &  G,
const typename GraphType::vertex_type & start  ,
vertex_property< GraphType, bool > &  visited,
OutputIter  dest 
)
27  {
28  *dest++ = start; // Put it on the output stream
29  visited[start] = true;
30 
31  /* Explore adjacent vertices */
32  for(auto it = G.avbegin(start); it != G.avend(start); it++)
33  if(!visited(*it))
34  dest = _single_preorder_dfs(G, *it, visited, dest);
35 
36  return dest;
37 }
OutputIter _single_preorder_dfs(const GraphType &G, const typename GraphType::vertex_type &start, vertex_property< GraphType, bool > &visited, OutputIter dest)
Definition: dfs.h:24
template<typename GraphType >
vertex_property<GraphType, typename GraphType::edge_type::attr_t> alglib::graph::bellman_ford ( const GraphType &  G,
const typename GraphType::vertex_type source   
)
20  {
21 
22 }
template<typename GraphType , typename OutputIter >
OutputIter alglib::graph::bfs ( const GraphType &  G,
const typename GraphType::vertex_type & start  ,
OutputIter  dest 
)
60  {
61 
62  /* visited property initialized with false for each vertex */
63  vertex_property<GraphType, bool> visited(G, false);
64 
65  /* do the bfs of the start vertex first */
66  dest = _single_bfs(G, start, visited, dest);
67 
68  /* then others if they are not visited */
69  for(auto it = G.vbegin(); it != G.vend(); it++)
70  if(!visited(*it))
71  dest = _single_bfs(G, *it, visited, dest);
72 
73  return dest;
74 }
OutputIter _single_bfs(const GraphType &G, const typename GraphType::vertex_type &start, vertex_property< GraphType, bool > &visited, OutputIter dest)
Definition: bfs.h:20
template<typename GraphType , typename OutputIter >
OutputIter alglib::graph::bfs ( const GraphType &  G,
OutputIter  dest 
)
78  {
79  return bfs(G, *G.vbegin(), dest);
80 }
OutputIter bfs(const GraphType &G, OutputIter dest)
Definition: bfs.h:78
template<typename GraphType >
vertex_property<GraphType, int> alglib::graph::connected_components ( const GraphType &  G)
20  {
21  /* initialize each property with -1, indicating its component has not been ascertained */
22  vertex_property<GraphType, int> component_id(G, -1);
23 
24  /* start labelling component id with 1 */
25  int next_component_id = 1;
26 
27  for(auto it = G.vbegin(); it != G.vend(); it++) {
28  /* for every vertex which is not assigned a component id */
29  if(component_id(*it) == -1) {
30  std::vector<typename GraphType::vertex_type> component;
31  single_preorder_dfs(G, *it, back_inserter(component));
32 
33  /* set the component_id of each of the vertices in component */
34  for(auto vertex : component)
35  if(component_id(vertex) == -1)
36  component_id[vertex] = next_component_id;
37 
38  next_component_id++;
39  }
40  }
41  return component_id;
42 };
OutputIter single_preorder_dfs(const GraphType &G, const typename GraphType::vertex_type &start, OutputIter dest)
Definition: dfs.h:41
template<typename vertex_t , typename attr_t >
edge_t<vertex_t, attr_t> alglib::graph::make_edge ( vertex_t  from,
vertex_t  to,
attr_t  attribute 
)
63  {
64  return edge_t<vertex_t, attr_t>(from, to, attribute);
65 }
Definition: dijkstra.cpp:104
template<typename vertex_t , typename attr_t >
std::ostream& alglib::graph::operator<< ( std::ostream &  out,
const edge_t< vertex_t, attr_t > &  e 
)
53  {
54 
55  out << "(from: " << e.from << ", to: " << e.to
56  << ", attr: " << e.attribute << ")";
57  return out;
58 }
long long from()
Definition: dijkstra.cpp:109
long long to()
Definition: dijkstra.cpp:110
template<typename GraphType , typename OutputIter >
OutputIter alglib::graph::postorder_dfs ( const GraphType &  G,
const typename GraphType::vertex_type start  ,
OutputIter  dest 
)
97  {
98 
99  /* visited property on G, each initialized with false */
100  vertex_property<GraphType, bool> visited(G, false);
101 
102  /* do a dfs on the start vertex first */
103  dest = _single_postorder_dfs(G, start, visited, dest);
104 
105  /* check all the vertices and perform dfs on the unvisited ones */
106  for(auto it = G.vbegin(); it != G.vend(); it++)
107  if(!visited(*it))
108  dest = _single_postorder_dfs(G, *it, visited, dest);
109 
110  return dest;
111 }
OutputIter _single_postorder_dfs(const GraphType &G, const typename GraphType::vertex_type &start, vertex_property< GraphType, bool > &visited, OutputIter dest)
Definition: dfs.h:49
template<typename GraphType , typename OutputIter >
OutputIter alglib::graph::postorder_dfs ( const GraphType &  G,
OutputIter  dest 
)
115  {
116  return postorder_dfs(G, *G.vbegin(), dest);
117 }
OutputIter postorder_dfs(const GraphType &G, OutputIter dest)
Definition: dfs.h:115
template<typename GraphType , typename OutputIter >
OutputIter alglib::graph::preorder_dfs ( const GraphType &  G,
const typename GraphType::vertex_type start  ,
OutputIter  dest 
)
72  {
73 
74  /* visited property, initialized with false for each vertex */
75  vertex_property<GraphType, bool> visited(G, false);
76 
77  /* do a dfs on the start vertex first */
78  dest = _single_preorder_dfs(G, start, visited, dest);
79 
80  /* check all the vertices and perform dfs on the unvisited ones */
81  for(auto it = G.vbegin(); it != G.vend(); it++)
82  if(!visited(*it))
83  dest = _single_preorder_dfs(G, *it, visited, dest);
84 
85  return dest;
86 }
OutputIter _single_preorder_dfs(const GraphType &G, const typename GraphType::vertex_type &start, vertex_property< GraphType, bool > &visited, OutputIter dest)
Definition: dfs.h:24
template<typename GraphType , typename OutputIter >
OutputIter alglib::graph::preorder_dfs ( const GraphType &  G,
OutputIter  dest 
)
89  {
90  return preorder_dfs(G, *G.vbegin(), dest);
91 }
OutputIter preorder_dfs(const GraphType &G, OutputIter dest)
Definition: dfs.h:89
template<typename GraphType , typename OutputIter >
OutputIter alglib::graph::single_bfs ( const GraphType &  G,
const typename GraphType::vertex_type & start  ,
OutputIter  dest 
)
52  {
53  return _single_bfs(G, start, vertex_property<GraphType, bool>(G, false), dest);
54 }
OutputIter _single_bfs(const GraphType &G, const typename GraphType::vertex_type &start, vertex_property< GraphType, bool > &visited, OutputIter dest)
Definition: bfs.h:20
template<typename GraphType , typename OutputIter >
OutputIter alglib::graph::single_postorder_dfs ( const GraphType &  G,
const typename GraphType::vertex_type & start  ,
OutputIter  dest 
)
64  {
65  vertex_property<GraphType, bool> visited(G, false);
66  return _single_postorder_dfs(G, start, visited, dest);
67 }
OutputIter _single_postorder_dfs(const GraphType &G, const typename GraphType::vertex_type &start, vertex_property< GraphType, bool > &visited, OutputIter dest)
Definition: dfs.h:49
template<typename GraphType , typename OutputIter >
OutputIter alglib::graph::single_preorder_dfs ( const GraphType &  G,
const typename GraphType::vertex_type & start  ,
OutputIter  dest 
)
43  {
44  vertex_property<GraphType, bool> visited(G, false);
45  return _single_preorder_dfs(G, start, visited, dest);
46 }
OutputIter _single_preorder_dfs(const GraphType &G, const typename GraphType::vertex_type &start, vertex_property< GraphType, bool > &visited, OutputIter dest)
Definition: dfs.h:24
template<typename GraphType , typename OutputIter >
OutputIter alglib::graph::topological_order ( const GraphType &  G,
OutputIter  dest 
)
19  {
20  return postorder_dfs(G, dest);
21 }
OutputIter postorder_dfs(const GraphType &G, const typename GraphType::vertex_type start, OutputIter dest)
Definition: dfs.h:95