Fast map matching  0.1.0
ubodt.hpp
1 
10 #ifndef FMM_UBODT_H_
11 #define FMM_UBODT_H_
12 
13 #include "network/type.hpp"
14 #include "mm/transition_graph.hpp"
15 #include "util/debug.hpp"
16 
17 namespace FMM {
18 namespace MM {
19 
23 struct Record {
29  double cost;
31 };
32 
36 class UBODT {
37  public:
38  UBODT(const UBODT &) = delete;
39  UBODT &operator=(const UBODT &) = delete;
46  UBODT(int buckets_arg, int multiplier_arg);
47  ~UBODT();
55  Record *look_up(NETWORK::NodeIndex source, NETWORK::NodeIndex target) const;
56 
64  std::vector<NETWORK::EdgeIndex> look_sp_path(NETWORK::NodeIndex source,
65  NETWORK::NodeIndex target) const;
66 
80  const std::vector<NETWORK::Edge> &edges,
81  std::vector<int> *indices) const;
86  double get_delta() const;
93  unsigned int cal_bucket_index(NETWORK::NodeIndex source,
94  NETWORK::NodeIndex target) const;
95 
100  void insert(Record *r);
101 
109  static std::shared_ptr<UBODT> read_ubodt_file(const std::string &filename,
110  int multiplier = 50000);
117  static std::shared_ptr<UBODT> read_ubodt_csv(const std::string &filename,
118  int multiplier = 50000);
119 
126  static std::shared_ptr<UBODT> read_ubodt_binary(const std::string &filename,
127  int multiplier = 50000);
133  static long estimate_ubodt_rows(const std::string &filename);
139  static int find_prime_number(double value);
140  constexpr static double LOAD_FACTOR = 2.0;
143  static const int BUFFER_LINE = 1024;
145  private:
146  const long long multiplier; // multiplier to get a unique ID
147  const int buckets; // number of buckets
148  double delta = 0.0;
149  Record **hashtable;
150 };
151 }
152 }
153 
154 #endif //FMM_SRC_FMM_FFMM_UBODT_H_
FMM::MM::UBODT::cal_bucket_index
unsigned int cal_bucket_index(NETWORK::NodeIndex source, NETWORK::NodeIndex target) const
Find the bucket index for an OD pair.
Definition: ubodt.cpp:109
FMM::MM::UBODT::LOAD_FACTOR
constexpr static double LOAD_FACTOR
factor measuring the average number of elements in a bucket.
Definition: ubodt.hpp:140
FMM::MM::TGOpath
std::vector< const TGNode * > TGOpath
The optimal path of nodes in the transition graph.
Definition: transition_graph.hpp:46
FMM::MM::UBODT::look_up
Record * look_up(NETWORK::NodeIndex source, NETWORK::NodeIndex target) const
Look up the row according to a source node and a target node.
Definition: ubodt.cpp:42
FMM::MM::UBODT::read_ubodt_binary
static std::shared_ptr< UBODT > read_ubodt_binary(const std::string &filename, int multiplier=50000)
Read UBODT from a binary file.
Definition: ubodt.cpp:215
FMM::MM::UBODT::construct_complete_path
C_Path construct_complete_path(const TGOpath &path, const std::vector< NETWORK::Edge > &edges, std::vector< int > *indices) const
Construct the complete path (a vector of edge ID) from an optimal path (a vector of optimal nodes in ...
Definition: ubodt.cpp:70
FMM::MM::UBODT::get_delta
double get_delta() const
Get the upperbound of the UBODT.
Definition: ubodt.cpp:105
FMM::MM::UBODT::find_prime_number
static int find_prime_number(double value)
Find a large prime number according to input value.
Definition: ubodt.cpp:147
FMM::MM::C_Path
std::vector< FMM::NETWORK::EdgeID > C_Path
Complete path, ids of a sequence of topologically connected edges.
Definition: mm_type.hpp:47
FMM
Fast map matching.
Definition: geom_algorithm.hpp:17
FMM::MM::Record::target
NETWORK::NodeIndex target
target node
Definition: ubodt.hpp:25
FMM::MM::UBODT::BUFFER_LINE
static const int BUFFER_LINE
Number of characters to store in a line.
Definition: ubodt.hpp:143
FMM::MM::Record::prev_n
NETWORK::NodeIndex prev_n
last node visited before target
Definition: ubodt.hpp:27
FMM::MM::Record::source
NETWORK::NodeIndex source
source node
Definition: ubodt.hpp:24
FMM::MM::UBODT::read_ubodt_csv
static std::shared_ptr< UBODT > read_ubodt_csv(const std::string &filename, int multiplier=50000)
Read UBODT from a CSV file.
Definition: ubodt.cpp:174
FMM::MM::Record::first_n
NETWORK::NodeIndex first_n
next node visited from source to target
Definition: ubodt.hpp:26
FMM::MM::UBODT::estimate_ubodt_rows
static long estimate_ubodt_rows(const std::string &filename)
Estimate the number of rows in a file.
Definition: ubodt.cpp:122
FMM::MM::UBODT::look_sp_path
std::vector< NETWORK::EdgeIndex > look_sp_path(NETWORK::NodeIndex source, NETWORK::NodeIndex target) const
Look up a shortest path (SP) containing edges from source to target.
Definition: ubodt.cpp:55
FMM::MM::Record::cost
double cost
distance from source to target
Definition: ubodt.hpp:29
FMM::MM::UBODT::read_ubodt_file
static std::shared_ptr< UBODT > read_ubodt_file(const std::string &filename, int multiplier=50000)
Read UBODT from a file.
Definition: ubodt.cpp:160
FMM::NETWORK::NodeIndex
unsigned int NodeIndex
Node Index in the network, range from [0,num_vertices-1 ].
Definition: type.hpp:24
FMM::MM::Record
Record type of the upper bounded origin destination table
Definition: ubodt.hpp:23
FMM::NETWORK::EdgeIndex
unsigned int EdgeIndex
Edge Index in the network, range from [0,num_edges-1 ].
Definition: type.hpp:26
FMM::MM::Record::next_e
NETWORK::EdgeIndex next_e
next edge visited from source to target
Definition: ubodt.hpp:28
FMM::MM::UBODT::insert
void insert(Record *r)
Insert a record into the hash table.
Definition: ubodt.cpp:114
FMM::MM::UBODT
Upperbounded origin destination table.
Definition: ubodt.hpp:36
FMM::MM::Record::next
Record * next
the next record stored in hashtable
Definition: ubodt.hpp:30