Skip to content

Commit 506ee9a

Browse files
committed
Merge branch 'feature-clean'
2 parents 520645f + 0e84bd0 commit 506ee9a

34 files changed

+3985
-3385
lines changed

app/fmm.cpp

Lines changed: 101 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -20,110 +20,115 @@
2020
#include "../src/gps.hpp"
2121
#include "../src/reader.hpp"
2222
#include "../src/writer.hpp"
23-
#include "../src/multilevel_debug.h"
23+
#include "../src/debug.h"
2424
#include "../src/config.hpp"
2525
using namespace std;
2626
using namespace MM;
2727
using namespace MM::IO;
2828
int main (int argc, char **argv)
2929
{
30-
std::cout<<"------------ Fast map matching (FMM) ------------"<<endl;
31-
std::cout<<"------------ Author: Can Yang ------------"<<endl;
32-
std::cout<<"------------ Version: 2018.03.09 ------------"<<endl;
33-
std::cout<<"------------ Applicaton: fmm ------------"<<endl;
34-
if (argc<2)
30+
spdlog::set_pattern("[%s:%#] %v");
31+
std::cout<<"------------ Fast map matching (FMM) ------------"<<endl;
32+
std::cout<<"------------ Author: Can Yang ------------"<<endl;
33+
std::cout<<"------------ Version: 2020.01.31 ------------"<<endl;
34+
std::cout<<"------------ Applicaton: fmm ------------"<<endl;
35+
if (argc<2)
36+
{
37+
std::cout<<"No configuration file supplied"<<endl;
38+
std::cout<<"A configuration file is given in the example folder"<<endl;
39+
std::cout<<"Run `fmm config.xml`"<<endl;
40+
} else {
41+
std::string configfile(argv[1]);
42+
FMM_Config config(configfile);
43+
if (!config.validate_mm())
3544
{
36-
std::cout<<"No configuration file supplied"<<endl;
37-
std::cout<<"A configuration file is given in the example folder"<<endl;
38-
std::cout<<"Run `fmm config.xml`"<<endl;
45+
std::cout<<"Invalid configuration file, program stop"<<endl;
46+
return 0;
47+
};
48+
config.print();
49+
spdlog::set_level((spdlog::level::level_enum) config.log_level);
50+
// clock_t begin_time = clock(); // program start time
51+
std::chrono::steady_clock::time_point begin =
52+
std::chrono::steady_clock::now();
53+
Network network(
54+
config.network_file,config.network_id,
55+
config.network_source,config.network_target);
56+
network.build_rtree_index();
57+
int multiplier = network.get_node_count();
58+
if (multiplier==0) multiplier = 50000;
59+
UBODT *ubodt=nullptr;
60+
if (config.binary_flag==1) {
61+
ubodt = read_ubodt_binary(config.ubodt_file,multiplier);
3962
} else {
40-
std::string configfile(argv[1]);
41-
FMM_Config config(configfile);
42-
if (!config.validate_mm())
43-
{
44-
std::cout<<"Invalid configuration file, program stop"<<endl;
45-
return 0;
46-
};
47-
config.print();
48-
// clock_t begin_time = clock(); // program start time
49-
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
50-
Network network(config.network_file,config.network_id,config.network_source,config.network_target);
51-
network.build_rtree_index();
52-
int multiplier = network.get_node_count();
53-
if (multiplier==0) multiplier = 50000;
54-
UBODT *ubodt=nullptr;
55-
if (config.binary_flag==1){
56-
ubodt = read_ubodt_binary(config.ubodt_file,multiplier);
57-
} else {
58-
ubodt = read_ubodt_csv(config.ubodt_file,multiplier);
59-
}
60-
if (!config.delta_defined){
61-
config.delta = ubodt->get_delta();
62-
std::cout<<" Delta inferred from ubodt as "<< config.delta <<'\n';
63-
}
64-
TrajectoryReader tr_reader(config.gps_file,config.gps_id);
65-
ResultConfig result_config = config.get_result_config();
66-
ResultWriter rw(config.result_file,&network,result_config);
67-
int progress=0;
68-
int points_matched=0;
69-
int total_points=0;
70-
int num_trajectories = tr_reader.get_num_trajectories();
71-
int step_size = num_trajectories/10;
72-
if (step_size<10) step_size=10;
73-
std::chrono::steady_clock::time_point corrected_begin = std::chrono::steady_clock::now();
74-
std::cout<<"Start to map match trajectories with total number "<< num_trajectories <<'\n';
75-
// The header is moved to constructor of result writer
76-
// rw.write_header();
63+
ubodt = read_ubodt_csv(config.ubodt_file,multiplier);
64+
}
65+
if (!config.delta_defined) {
66+
config.delta = ubodt->get_delta();
67+
std::cout<<" Delta inferred from ubodt as "<< config.delta <<'\n';
68+
}
69+
TrajectoryReader tr_reader(config.gps_file,config.gps_id);
70+
ResultConfig result_config = config.get_result_config();
71+
ResultWriter rw(config.result_file,network,result_config);
72+
int progress=0;
73+
int points_matched=0;
74+
int total_points=0;
75+
int num_trajectories = tr_reader.get_num_trajectories();
76+
int step_size = num_trajectories/10;
77+
if (step_size<10) step_size=10;
78+
std::chrono::steady_clock::time_point corrected_begin =
79+
std::chrono::steady_clock::now();
80+
std::cout<<"Start to map match trajectories with total number "
81+
<< num_trajectories <<'\n';
82+
// The header is moved to constructor of result writer
83+
// rw.write_header();
7784

78-
while (tr_reader.has_next_feature())
79-
{
80-
DEBUG(2) std::cout<<"Start of the loop"<<'\n';
81-
Trajectory trajectory = tr_reader.read_next_trajectory();
82-
int points_in_tr = trajectory.geom->getNumPoints();
83-
if (progress%step_size==0) std::cout<<"Progress "<<progress << " / " << num_trajectories <<'\n';
84-
DEBUG(1) std::cout<<"\n============================="<<'\n';
85-
DEBUG(1) std::cout<<"Process trips with id : "<<trajectory.id<<'\n';
86-
// Candidate search
87-
Traj_Candidates traj_candidates = network.search_tr_cs_knn(trajectory,config.k,config.radius,config.gps_error);
88-
TransitionGraph tg = TransitionGraph(&traj_candidates,trajectory.geom,ubodt,config.delta);
89-
// Optimal path inference
90-
O_Path *o_path_ptr = tg.viterbi(config.penalty_factor);
91-
// Complete path construction as an array of indices of edges vector
92-
T_Path *t_path_ptr = ubodt->construct_traversed_path(o_path_ptr);
93-
// C_Path *c_path_ptr = ubodt->construct_complete_path(o_path_ptr);
94-
if (result_config.write_mgeom) {
95-
LineString *m_geom = network.complete_path_to_geometry(o_path_ptr,&(t_path_ptr->cpath));
96-
rw.write_result(trajectory.id,trajectory.geom,o_path_ptr,t_path_ptr,m_geom);
97-
delete m_geom;
98-
} else {
99-
rw.write_result(trajectory.id,trajectory.geom,o_path_ptr,t_path_ptr,nullptr);
100-
}
101-
// update statistics
102-
total_points+=points_in_tr;
103-
if (t_path_ptr!=nullptr) points_matched+=points_in_tr;
104-
DEBUG(1) std::cout<<"Free memory of o_path and c_path"<<'\n';
105-
++progress;
106-
delete o_path_ptr;
107-
delete t_path_ptr;
108-
DEBUG(1) std::cout<<"============================="<<'\n';
109-
}
110-
std::cout<<"\n============================="<<'\n';
111-
std::cout<<"MM process finished"<<'\n';
112-
std::chrono::steady_clock::time_point end= std::chrono::steady_clock::now();
113-
// clock_t end_time = clock(); // program end time
114-
// Unit is second
115-
// double time_spent = (double)(end_time - begin_time) / CLOCKS_PER_SEC;
116-
double time_spent = std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count()/1000.;
117-
double time_spent_exclude_input = std::chrono::duration_cast<std::chrono::milliseconds>(end - corrected_begin).count()/1000.;
118-
std::cout<<"Time takes "<<time_spent<<'\n';
119-
std::cout<<"Time takes excluding input "<<time_spent_exclude_input<<'\n';
120-
std::cout<<"Finish map match total points "<<total_points
121-
<<" and points matched "<<points_matched<<'\n';
122-
std::cout<<"Matched percentage: "<<points_matched/(double)total_points<<'\n';
123-
std::cout<<"Point match speed:"<<points_matched/time_spent<<"pt/s"<<'\n';
124-
std::cout<<"Point match speed (excluding input): "<<points_matched/time_spent_exclude_input<<"pt/s"<<'\n';
125-
delete ubodt;
85+
while (tr_reader.has_next_feature())
86+
{
87+
Trajectory trajectory = tr_reader.read_next_trajectory();
88+
int points_in_tr = trajectory.geom.getNumPoints();
89+
if (progress%step_size==0)
90+
std::cout<<"Progress "<<progress << " / " << num_trajectories <<'\n';
91+
// Candidate search
92+
Traj_Candidates traj_candidates = network.search_tr_cs_knn(
93+
trajectory,config.k,config.radius,config.gps_error);
94+
TransitionGraph tg(
95+
&traj_candidates,trajectory.geom,*ubodt,config.delta);
96+
// Optimal path inference
97+
O_Path o_path = tg.viterbi(config.penalty_factor);
98+
T_Path t_path = ubodt->construct_traversed_path(o_path,network);
99+
LineString m_geom;
100+
if (result_config.write_mgeom) {
101+
m_geom = network.complete_path_to_geometry(o_path,t_path.cpath);
102+
}
103+
rw.write_result(trajectory.id,trajectory.geom,o_path,t_path,m_geom);
104+
// update statistics
105+
total_points+=points_in_tr;
106+
if (!t_path.cpath.empty()) points_matched+=points_in_tr;
107+
++progress;
126108
}
127-
std::cout<<"------------ Program finished ------------"<<endl;
128-
return 0;
109+
std::cout<<"\n============================="<<'\n';
110+
std::cout<<"MM process finished"<<'\n';
111+
std::chrono::steady_clock::time_point end= std::chrono::steady_clock::now();
112+
// clock_t end_time = clock(); // program end time
113+
// Unit is second
114+
// double time_spent = (double)(end_time - begin_time) / CLOCKS_PER_SEC;
115+
double time_spent =
116+
std::chrono::duration_cast<std::chrono::milliseconds>
117+
(end - begin).count()/1000.;
118+
double time_spent_exclude_input =
119+
std::chrono::duration_cast<std::chrono::milliseconds>
120+
(end - corrected_begin).count()/1000.;
121+
std::cout<<"Time takes "<<time_spent<<'\n';
122+
std::cout<<"Time takes excluding input "<<time_spent_exclude_input<<'\n';
123+
std::cout<<"Finish map match total points "<<total_points
124+
<<" and points matched "<<points_matched<<'\n';
125+
std::cout<<"Matched percentage: "
126+
<<points_matched/(double)total_points<<'\n';
127+
std::cout<<"Point match speed:"<<points_matched/time_spent<<"pt/s"<<'\n';
128+
std::cout<<"Point match speed (excluding input): "
129+
<<points_matched/time_spent_exclude_input<<"pt/s"<<'\n';
130+
delete ubodt;
131+
}
132+
std::cout<<"------------ Program finished ------------"<<endl;
133+
return 0;
129134
};

0 commit comments

Comments
 (0)