PGROUTING  3.2
pgr_topologicalSort.hpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: pgr_topologicalSort.hpp
3 
4 Copyright (c) 2015 pgRouting developers
6 
7 Function's developer:
8 Copyright (c) 2019 Hang Wu
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 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 ********************************************************************PGR-GNU*/
24 
25 #ifndef INCLUDE_TOPOLOGICALSORT_PGR_TOPOLOGICALSORT_HPP_
26 #define INCLUDE_TOPOLOGICALSORT_PGR_TOPOLOGICALSORT_HPP_
27 #pragma once
28 
29 #include <boost/config.hpp>
30 #include <boost/graph/adjacency_list.hpp>
31 #include <boost/graph/graph_traits.hpp>
32 #include <boost/typeof/typeof.hpp>
33 #include <boost/graph/topological_sort.hpp>
34 
35 
36 #include <iostream>
37 #include <vector>
38 #include <algorithm>
39 #include <sstream>
40 #include <functional>
41 #include <limits>
42 
46 
47 template < class G > class Pgr_topologicalSort;
48 // user's functions
49 // for development
50 
51 //******************************************
52 
53 template < class G >
54 class Pgr_topologicalSort {
55  public:
56  typedef typename G::V V;
57 
58  std::vector<pgr_topologicalSort_t> topologicalSort(
59  G &graph);
60 
61  private:
62  std::vector< pgr_topologicalSort_t >
64  const G &graph ) {
65  std::vector< pgr_topologicalSort_t > results;
66 
67  typedef typename std::vector< V > container;
68  container c;
69 
70  /* abort in case of an interruption occurs (e.g. the query is being cancelled) */
71  CHECK_FOR_INTERRUPTS();
72 
73  boost::topological_sort(graph.graph, std::back_inserter(c));
74 
75  typename std::vector< V >::reverse_iterator ii;
76  for (ii = c.rbegin(); ii != c.rend(); ++ii) {
77  auto t = *ii;
79  tmp.sorted_v = graph.graph[t].id;
80  results.push_back(tmp);
81  }
82 
83  return results;
84  }
85 };
86 
87 template < class G >
88 std::vector<pgr_topologicalSort_t>
90  G &graph) {
91  return generatetopologicalSort(
92  graph);
93 }
94 
95 
96 #endif // INCLUDE_TOPOLOGICALSORT_PGR_TOPOLOGICALSORT_HPP_
interruption.h
Pgr_topologicalSort
Definition: pgr_topologicalSort.hpp:47
pgr_base_graph.hpp
Pgr_topologicalSort::generatetopologicalSort
std::vector< pgr_topologicalSort_t > generatetopologicalSort(const G &graph)
Definition: pgr_topologicalSort.hpp:63
Pgr_topologicalSort::V
G::V V
Definition: pgr_topologicalSort.hpp:56
Pgr_topologicalSort::topologicalSort
std::vector< pgr_topologicalSort_t > topologicalSort(G &graph)
Definition: pgr_topologicalSort.hpp:89
pgr_topologicalSort_t
Definition: pgr_topologicalSort_t.h:37
pgr_topologicalSort_t::sorted_v
int64_t sorted_v
Definition: pgr_topologicalSort_t.h:39
pgrouting::alphashape::G
graph::Pgr_base_graph< BG, XY_vertex, Basic_edge > G
Definition: pgr_alphaShape.h:56
pgrouting::alphashape::V
boost::graph_traits< BG >::vertex_descriptor V
Definition: pgr_alphaShape.h:58
basePath_SSEC.hpp