PGROUTING  3.2
dfs_visitor.hpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: Dfs_visitor.hpp
3 
4 Copyright (c) 2020 pgRouting developers
6 
7 Copyright (c) 2020 Ashish Kumar
9 
10 ------
11 
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16 
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21 
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 
26  ********************************************************************PGR-GNU*/
27 
28 #ifndef INCLUDE_VISITORS_DFS_VISITOR_HPP_
29 #define INCLUDE_VISITORS_DFS_VISITOR_HPP_
30 #pragma once
31 
32 #include <boost/graph/depth_first_search.hpp>
33 
34 #include <vector>
35 #include <set>
36 #include <map>
37 #include <iostream>
38 
39 #include "visitors/found_goals.hpp"
40 
41 namespace pgrouting {
42 namespace visitors {
43 
44 template <typename V, typename E, typename G>
45 class Dfs_visitor : public boost::default_dfs_visitor {
46  public:
48  V root,
49  std::vector<E> &data,
50  int64_t max_depth,
51  std::vector<boost::default_color_type> &colors,
52  G &graph) :
53  m_roots(root),
54  m_data(data),
55  m_max_depth(max_depth),
56  m_colors(colors),
57  m_graph(graph) {
58  m_depth.resize(m_graph.num_vertices(), 0);
59  }
60  template <typename B_G>
61  void start_vertex(V v, const B_G&) {
62  // exception for visitor termination
63  if (v != m_roots) throw found_goals();
64  m_depth[v] = 0;
65  }
66  template <typename B_G>
67  void examine_edge(E e, const B_G&) {
68  auto source = m_graph.source(e), target = m_graph.target(e);
69  // If the target has not been visited before
70  if (m_depth[target] == 0 && target != m_roots)
71  m_depth[target] = m_depth[source] + 1;
72 
73  // If the max_depth is reached, mark the target as visited, and push the corresponding edge
74  if (m_depth[target] == m_max_depth && m_colors[target] != 4) {
75  m_colors[target] = boost::black_color;
76  m_data.push_back(e);
77  }
78  }
79  template <typename B_G>
80  void tree_edge(E e, const B_G&) {
81  m_data.push_back(e);
82  }
83 
84  private:
86  std::vector<E> &m_data;
87  int64_t m_max_depth;
88  std::vector<boost::default_color_type> &m_colors;
90  std::vector<int64_t> m_depth;
91 };
92 
93 
94 } // namespace visitors
95 } // namespace pgrouting
96 
97 #endif // INCLUDE_VISITORS_DFS_VISITOR_HPP_
pgrouting::visitors::Dfs_visitor::tree_edge
void tree_edge(E e, const B_G &)
Definition: dfs_visitor.hpp:80
pgrouting::visitors::Dfs_visitor::m_colors
std::vector< boost::default_color_type > & m_colors
Definition: dfs_visitor.hpp:88
found_goals.hpp
pgrouting::visitors::Dfs_visitor::m_graph
G & m_graph
Definition: dfs_visitor.hpp:89
pgrouting::alphashape::E
boost::graph_traits< BG >::edge_descriptor E
Definition: pgr_alphaShape.h:57
pgrouting::visitors::Dfs_visitor::m_max_depth
int64_t m_max_depth
Definition: dfs_visitor.hpp:87
pgrouting::visitors::Dfs_visitor::start_vertex
void start_vertex(V v, const B_G &)
Definition: dfs_visitor.hpp:61
pgrouting::visitors::Dfs_visitor::m_depth
std::vector< int64_t > m_depth
Definition: dfs_visitor.hpp:90
pgrouting::visitors::Dfs_visitor::Dfs_visitor
Dfs_visitor(V root, std::vector< E > &data, int64_t max_depth, std::vector< boost::default_color_type > &colors, G &graph)
Definition: dfs_visitor.hpp:47
pgrouting::visitors::Dfs_visitor::examine_edge
void examine_edge(E e, const B_G &)
Definition: dfs_visitor.hpp:67
pgrouting::alphashape::G
graph::Pgr_base_graph< BG, XY_vertex, Basic_edge > G
Definition: pgr_alphaShape.h:56
pgrouting::visitors::Dfs_visitor::m_roots
V m_roots
Definition: dfs_visitor.hpp:85
pgrouting::visitors::Dfs_visitor
Definition: dfs_visitor.hpp:45
pgrouting::found_goals
exception for visitor termination
Definition: found_goals.hpp:33
pgrouting::alphashape::V
boost::graph_traits< BG >::vertex_descriptor V
Definition: pgr_alphaShape.h:58
pgrouting::visitors::Dfs_visitor::m_data
std::vector< E > & m_data
Definition: dfs_visitor.hpp:86
pgrouting
Book keeping class for swapping orders between vehicles.
Definition: pgr_alphaShape.cpp:56