Fast map matching  0.1.0
network_graph.hpp
1 
21 #ifndef FMM_NETWORK_GRAPH_HPP
22 #define FMM_NETWORK_GRAPH_HPP
23 
24 #include "network/heap.hpp"
25 #include "network/graph.hpp"
26 #include "network/network.hpp"
27 
28 namespace FMM {
29 namespace NETWORK {
33 class NetworkGraph {
34  public:
39  explicit NetworkGraph(const Network &network_arg);
46  std::vector<EdgeIndex> shortest_path_dijkstra(
47  NodeIndex source, NodeIndex target) const;
54  double calc_heuristic_dist(
55  const CORE::Point &p1, const CORE::Point &p2) const;
62  std::vector<EdgeIndex> shortest_path_astar(NodeIndex source,
63  NodeIndex target) const;
72  std::vector<EdgeIndex> back_track(NodeIndex source,
73  NodeIndex target,
74  const PredecessorMap &pmap,
75  const DistanceMap &dmap) const;
84  double delta,
85  PredecessorMap *pmap,
86  DistanceMap *dmap) const;
91  int get_edge_index(NodeIndex source, NodeIndex target,
92  double cost) const;
98  inline int get_edge_id(EdgeIndex idx) const {
99  return network.get_edge_id(idx);
100  };
108  inline int get_edge_id(NodeIndex source, NodeIndex target,
109  double cost) const {
110  return network.get_edge_id(get_edge_index(source, target, cost));
111  };
117  inline int get_node_id(NodeIndex idx) const {
118  return network.get_node_id(idx);
119  };
125  inline NodeIndex get_node_index(NodeID id) const {
126  return network.get_node_index(id);
127  };
133  inline const FMM::CORE::Point &get_vertex_point(NodeIndex u) const {
134  return network.get_vertex_point(u);
135  };
139  void print_graph() const;
144  const Graph_T &get_boost_graph() const;
149  const Network &get_network();
154  unsigned int get_num_vertices() const;
155  protected:
160  static constexpr double DOUBLE_MIN = 1.e-6;
161  const Network &network;
162  unsigned int num_vertices = 0;
163 }; // NetworkGraph
164 }; // NETWORK
165 } // FMM
166 #endif /* FMM_NETWORK_GRAPH_HPP */
FMM::NETWORK::NetworkGraph::g
Graph_T g
The member storing a boost graph.
Definition: network_graph.hpp:156
FMM::NETWORK::Graph_T
boost::adjacency_list< boost::vecS, boost::vecS, boost::directedS, boost::no_property, EdgeProperty > Graph_T
Boost graph type.
Definition: graph.hpp:36
FMM::NETWORK::NetworkGraph::print_graph
void print_graph() const
Print graph information.
Definition: network_graph.cpp:34
FMM::NETWORK::Network::get_vertex_point
const FMM::CORE::Point & get_vertex_point(NodeIndex u) const
Get node geometry.
Definition: network.cpp:307
FMM::NETWORK::NetworkGraph::get_vertex_point
const FMM::CORE::Point & get_vertex_point(NodeIndex u) const
Get node point from node index.
Definition: network_graph.hpp:133
FMM::NETWORK::NetworkGraph::network
const Network & network
Road network.
Definition: network_graph.hpp:161
FMM::NETWORK::NetworkGraph::shortest_path_astar
std::vector< EdgeIndex > shortest_path_astar(NodeIndex source, NodeIndex target) const
AStar Shortest path query from source to target.
Definition: network_graph.cpp:105
FMM::NETWORK::DistanceMap
std::unordered_map< NodeIndex, double > DistanceMap
Distance map.
Definition: graph.hpp:61
FMM::NETWORK::NetworkGraph::single_source_upperbound_dijkstra
void single_source_upperbound_dijkstra(NodeIndex source, double delta, PredecessorMap *pmap, DistanceMap *dmap) const
Single source shortest path query with an uppper bound.
Definition: network_graph.cpp:209
FMM::NETWORK::NetworkGraph::get_edge_id
int get_edge_id(EdgeIndex idx) const
Get the edge ID from edge index.
Definition: network_graph.hpp:98
FMM::NETWORK::Network::get_node_id
NodeID get_node_id(NodeIndex index) const
Get node ID from index.
Definition: network.cpp:161
FMM::NETWORK::NetworkGraph::get_network
const Network & get_network()
Get inner network reference.
Definition: network_graph.cpp:47
FMM
Fast map matching.
Definition: geom_algorithm.hpp:17
FMM::NETWORK::Network::get_node_index
NodeIndex get_node_index(NodeID id) const
Get node index from id.
Definition: network.cpp:165
FMM::NETWORK::Network
Road network class.
Definition: network.hpp:36
FMM::NETWORK::NetworkGraph::get_boost_graph
const Graph_T & get_boost_graph() const
Get inner boost graph.
Definition: network_graph.cpp:43
FMM::NETWORK::Network::get_edge_id
EdgeID get_edge_id(EdgeIndex index) const
Get edge ID from index.
Definition: network.cpp:152
FMM::NETWORK::NetworkGraph::DOUBLE_MIN
static constexpr double DOUBLE_MIN
A value used in checking edge from source,target and cost.
Definition: network_graph.hpp:160
FMM::NETWORK::NetworkGraph::NetworkGraph
NetworkGraph(const Network &network_arg)
Construct a network graph from a network.
Definition: network_graph.cpp:15
FMM::NETWORK::NetworkGraph::get_num_vertices
unsigned int get_num_vertices() const
Get number of vertices in the graph.
Definition: network_graph.cpp:50
FMM::NETWORK::NetworkGraph::num_vertices
unsigned int num_vertices
number of vertices
Definition: network_graph.hpp:162
FMM::NETWORK::NetworkGraph
Graph class of the network.
Definition: network_graph.hpp:33
FMM::NETWORK::NodeID
int NodeID
Node ID in the network, can be discontinuous int.
Definition: type.hpp:22
FMM::NETWORK::NetworkGraph::get_edge_index
int get_edge_index(NodeIndex source, NodeIndex target, double cost) const
Find the edge ID given a pair of nodes and its cost, if not found, return -1.
Definition: network_graph.cpp:188
FMM::NETWORK::NetworkGraph::get_node_id
int get_node_id(NodeIndex idx) const
Get node ID from a node index.
Definition: network_graph.hpp:117
FMM::NETWORK::NetworkGraph::shortest_path_dijkstra
std::vector< EdgeIndex > shortest_path_dijkstra(NodeIndex source, NodeIndex target) const
Dijkstra Shortest path query from source to target.
Definition: network_graph.cpp:54
FMM::NETWORK::NodeIndex
unsigned int NodeIndex
Node Index in the network, range from [0,num_vertices-1 ].
Definition: type.hpp:24
FMM::NETWORK::EdgeIndex
unsigned int EdgeIndex
Edge Index in the network, range from [0,num_edges-1 ].
Definition: type.hpp:26
FMM::NETWORK::NetworkGraph::calc_heuristic_dist
double calc_heuristic_dist(const CORE::Point &p1, const CORE::Point &p2) const
Calculate heuristic distance from p1 to p2,which is used in Astar routing.
Definition: network_graph.cpp:99
FMM::CORE::Point
boost::geometry::model::point< double, 2, boost::geometry::cs::cartesian > Point
Point class.
Definition: geometry.hpp:28
FMM::NETWORK::NetworkGraph::get_edge_id
int get_edge_id(NodeIndex source, NodeIndex target, double cost) const
Get edge ID from source node, target node and cost.
Definition: network_graph.hpp:108
FMM::NETWORK::PredecessorMap
std::unordered_map< NodeIndex, NodeIndex > PredecessorMap
Predecessor Map.
Definition: graph.hpp:55
FMM::NETWORK::NetworkGraph::get_node_index
NodeIndex get_node_index(NodeID id) const
Get node index from node ID.
Definition: network_graph.hpp:125
FMM::NETWORK::NetworkGraph::back_track
std::vector< EdgeIndex > back_track(NodeIndex source, NodeIndex target, const PredecessorMap &pmap, const DistanceMap &dmap) const
Backtrack the routing result to find a path from source to target.
Definition: network_graph.cpp:160