5 #include "mm/fmm/fmm_algorithm.hpp"
6 #include "algorithm/geom_algorithm.hpp"
7 #include "util/util.hpp"
8 #include "util/debug.hpp"
16 FastMapMatchConfig::FastMapMatchConfig(
int k_arg,
double r_arg,
18 k(k_arg), radius(r_arg), gps_error(gps_error) {
22 SPDLOG_INFO(
"FMMAlgorithmConfig");
27 const boost::property_tree::ptree &xml_data) {
28 int k = xml_data.get(
"config.parameters.k", 8);
29 double radius = xml_data.get(
"config.parameters.r", 300.0);
30 double gps_error = xml_data.get(
"config.parameters.gps_error", 50.0);
35 const cxxopts::ParseResult &arg_data) {
36 int k = arg_data[
"candidates"].as<
int>();
37 double radius = arg_data[
"radius"].as<
double>();
38 double gps_error = arg_data[
"error"].as<
double>();
44 SPDLOG_CRITICAL(
"Invalid mm parameter k {} r {} gps error {}",
54 SPDLOG_TRACE(
"Search candidates");
57 SPDLOG_TRACE(
"Trajectory candidate {}", tc);
59 SPDLOG_TRACE(
"Generate transition graph");
61 SPDLOG_TRACE(
"Update cost in transition graph");
64 SPDLOG_TRACE(
"Optimal path inference");
66 SPDLOG_TRACE(
"Optimal path size {}", tg_opath.size());
68 std::transform(tg_opath.begin(), tg_opath.end(),
69 matched_candidate_path.begin(),
71 return MatchedCandidate{
72 *(a->c), a->ep, a->tp, a->sp_dist
75 O_Path opath(tg_opath.size());
76 std::transform(tg_opath.begin(), tg_opath.end(),
79 return a->c->edge->id;
81 std::vector<int> indices;
82 const std::vector<Edge> &edges = network_.get_edges();
83 C_Path cpath = ubodt_->construct_complete_path(tg_opath, edges,
85 SPDLOG_TRACE(
"Cpath {}", cpath);
86 SPDLOG_TRACE(
"Complete path inference");
87 LineString mgeom = network_.complete_path_to_geometry(
89 SPDLOG_TRACE(
"Complete path inference done");
91 traj.
id, matched_candidate_path, opath, cpath, indices, mgeom};
97 std::vector<double> timestamps;
101 output.
id = result.
id;
135 if (r ==
nullptr)
return ubodt_->get_delta();
142 void FastMapMatch::update_tg(
145 SPDLOG_TRACE(
"Update transition graph");
146 std::vector<TGLayer> &layers = tg->
get_layers();
148 int N = layers.size();
149 for (
int i = 0; i < N - 1; ++i) {
150 update_layer(i, &(layers[i]), &(layers[i + 1]),
153 SPDLOG_TRACE(
"Update transition graph done");
156 void FastMapMatch::update_layer(
int level,
160 SPDLOG_TRACE(
"Update layer");
162 for (
auto iter_a = la_ptr->begin(); iter_a != la_ptr->end(); ++iter_a) {
164 for (
auto iter_b = lb_ptr->begin(); iter_b != lb_ptr->end(); ++iter_b) {
165 double sp_dist = get_sp_dist(iter_a->c, iter_b->c);
166 double tp = TransitionGraph::calc_tp(sp_dist, eu_dist);
167 if (iter_a->cumu_prob + tp * iter_b->ep >= iter_b->cumu_prob) {
168 iter_b->cumu_prob = iter_a->cumu_prob + tp * iter_b->ep;
169 iter_b->prev = &(*iter_a);
171 iter_b->sp_dist = sp_dist;
175 SPDLOG_TRACE(
"Update layer done");
Transition graph class in HMM.
std::vector< MatchedCandidate > MatchedCandidatePath
A vector of candidates, used for representing the matching result of a trajectory.
LineString geom
Geometry of the trajectory.
CORE::LineString mgeom
Geometry of the matched path.
std::vector< Point_Candidates > Traj_Candidates
trajectory candidates
void add_point(double x, double y)
Add a point to the end of the current line.
FMM::CORE::Point point
boost point
std::vector< const TGNode * > TGOpath
The optimal path of nodes in the transition graph.
NETWORK::Edge * edge
candidate edge
Candidate c
Candidate matched to a point.
Map matched result representation.
std::vector< PyCandidate > candidates
Candidate matched to each point.
TGOpath backtrack()
Backtrack the transition graph to find an optimal path.
double radius
Search radius.
double gps_error
GPS error.
EdgeID id
Edge ID, can be discontinuous integers.
POD Match result type used in Python API.
std::vector< FMM::NETWORK::EdgeID > C_Path
Complete path, ids of a sequence of topologically connected edges.
double dist
distance from original point p to map matched point p'
C_Path cpath
the complete path, containing ids of a sequence of topologically connected edges traversed by the tra...
static FastMapMatchConfig load_from_xml(const boost::property_tree::ptree &xml_data)
Load configuration from xml data.
std::vector< int > indices
index of matched edge in the cpath
FMM::MM::Traj_Candidates search_tr_cs_knn(FMM::CORE::Trajectory &trajectory, std::size_t k, double radius) const
Search for k nearest neighboring (KNN) candidates of a trajectory within a search radius.
CORE::LineString pgeom
Point position matched for each GPS point.
CORE::LineString mgeom
the geometry of the matched path
void print() const
Print information about this configuration.
int id
id of the trajectory to be matched
Candidate edge matched to a GPS point
double tp
transition probability to previous matched candidate
double offset
offset distance from the start of polyline to p'
int k
Number of candidates.
MM::O_Path opath
Edge ID matched for each point of the trajectory
Linestring geometry class.
MatchedCandidatePath opt_candidate_path
A vector of candidate matched to each point of a trajectory.
Class related with map matching.
O_Path opath
the optimal path, containing id of edges matched to each point in a trajectory
Classes related with network and graph.
std::vector< FMM::NETWORK::EdgeID > O_Path
Optimal path, edge id matched to each point in the trajectory.
MatchResult match_traj(const CORE::Trajectory &traj, const FastMapMatchConfig &config)
Match a trajectory to the road network.
double cost
distance from source to target
LineString wkt2linestring(const std::string &wkt)
Convert a wkt into a linestring.
void update_tg(TransitionGraph *tg, const CORE::Trajectory &traj, const FastMapMatchConfig &config)
Update probabilities in a transition graph.
std::vector< int > indices
index of opath edge in cpath
A candidate matched to a point.
std::vector< TGLayer > & get_layers()
Get a reference to the inner layers of the transition graph.
NodeIndex source
source node index
unsigned int NodeIndex
Node Index in the network, range from [0,num_vertices-1 ].
bool validate() const
Check if the configuration is valid or not.
std::vector< double > cal_eu_dist(const FMM::CORE::LineString &trajectory)
Calculate segment length of a trajectory.
Record type of the upper bounded origin destination table
MM::C_Path cpath
Edge ID traversed by the matched path.
int get_num_points() const
Get the number of points in a line.
double length
length of the edge polyline
A node in the transition graph.
double sp_dist
shortest path distance to previous matched candidate
std::vector< TGNode > TGLayer
A layer of nodes in the transition graph.
Configuration class for fmm algorithm.
Data type for Python API.
NodeIndex target
target node index
double ep
emission probability
static FastMapMatchConfig load_from_arg(const cxxopts::ParseResult &arg_data)
Load configuration from argument data.