-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cpp
More file actions
138 lines (109 loc) · 3.84 KB
/
main.cpp
File metadata and controls
138 lines (109 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <iostream>
#include <exception>
#include <memory>
#include <cfloat>
using namespace std;
#include "graph.h"
#include "input.h"
#include "spatial.h"
#include "frechet.h"
#include "learning.h"
unique_ptr<ISpatialIndex> load(string file_prefix, int index_id)
{
auto storage = StorageManager::loadDiskStorageManager(file_prefix);
auto tree = unique_ptr<ISpatialIndex>(RTree::loadRTree(*storage, index_id));
return tree;
}
shared_ptr<ISpatialIndex> construct(id_type index_id)
{
RoadGraph graph;
graph.loadUTM("../data/test/nodes.txt", "../data/test/edges.txt", "../data/test/edgegeometry.txt");
auto storage = StorageManager::createNewMemoryStorageManager();
auto tree = shared_ptr<ISpatialIndex>(RTree::createNewRTree(*storage, FILL_FACTOR, CAPACITY, CAPACITY, 2, RTree::RV_RSTAR, index_id));
int64_t edgeCount = 0;
for (const Edge *e : graph.index())
{
int64_t nodeCount = 0;
for (const UTMNode &n: e->geometry)
{
MapPoint p(n);
tree->insertData(0, 0, p, SHAPE_ID(edgeCount, nodeCount));
++nodeCount;
}
++edgeCount;
}
return tree;
}
#include <ctime>
const char *DELIMETER = "\t & \t";
void run_experiment(ostream &out,
const string &type, const string &name, const Input &input, const Output &test_output,
const RoadGraph &graph, ISpatialIndex *index)
{
Output output;
double res_time = -1;
if (type == "global")
{
clock_t time = clock();
output = mmatch::match_frechet(graph, index, input, MAX_CONSIDERED_AREA);
res_time = double(clock() - time) / (CLOCKS_PER_SEC);
}
else if (type == "smartglobal")
{
clock_t time = clock();
output = mmatch::match_frechet_smart(graph, index, input);
res_time = double(clock() - time) / (CLOCKS_PER_SEC);
}
else if (type == "incr")
{
clock_t time = clock();
output = mmatch::backtracing_match(graph, index, input, MAX_ERROR_LOCAL);
res_time = double(clock() - time) / (CLOCKS_PER_SEC);
}
else if (type == "incrsmart")
{
clock_t time = clock();
output = mmatch::backtracing_match_smart(graph, index, input);
res_time = double(clock() - time) / (CLOCKS_PER_SEC);
}
else
{
cout << "unknown matching algorithm type" << endl;
return;
}
out << name << DELIMETER
<< type << DELIMETER
<< res_time << DELIMETER
<< output.evaluate(test_output) << DELIMETER
<< output.maxError() << "\\\\" << endl;
}
int main()
{
string file_prefix = "alldata";
id_type index_id = 1;
auto fixed = {3,5,6,9,10};
for (size_t i : fixed)
{
RoadGraph graph;
unique_ptr<ISpatialIndex> tree = load(file_prefix, index_id);
graph.loadBinary("../data/graph.dat");
string dataset = (i < 10 ? "0" : "") + to_string(i) + ".txt";
Input input("../data/input/input_" + dataset);
Output test_output("../data/output/output_" + dataset);
run_experiment(cout, "global", dataset, input, test_output, graph, tree.get());
run_experiment(cout, "incrsmart", dataset, input, test_output, graph, tree.get());
}
auto smart_fixed = {6,7,8};
for (size_t i : smart_fixed)
{
RoadGraph graph;
unique_ptr<ISpatialIndex> tree = load(file_prefix, index_id);
graph.loadBinary("../data/graph.dat");
string dataset = (i < 10 ? "0" : "") + to_string(i) + ".txt";
Input input("../data/input/input_" + dataset);
Output test_output("../data/output/output_" + dataset);
run_experiment(cout, "smartglobal", dataset, input, test_output, graph, tree.get());
run_experiment(cout, "incrsmart", dataset, input, test_output, graph, tree.get());
}
return 0;
}