-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontour.cpp
More file actions
219 lines (198 loc) · 6.69 KB
/
Copy pathcontour.cpp
File metadata and controls
219 lines (198 loc) · 6.69 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*
* Global Position Estimation
*/
#define _DEBUG
#include "boost/accumulators/accumulators.hpp"
#include "boost/accumulators/statistics/count.hpp"
#include "boost/accumulators/statistics/mean.hpp"
#include "boost/accumulators/statistics/moment.hpp"
#include "boost/accumulators/statistics/stats.hpp"
#include "boost/accumulators/statistics/variance.hpp"
#include "boost/program_options.hpp"
#include "boost/program_options.hpp"
#include <algorithm>
#include <fstream>
#include <graph.hpp>
#include <iostream>
#include <map>
using namespace std;
using namespace boost::accumulators;
namespace po = boost::program_options;
int main(int argc, char **argv) {
string ifname;
string tfname;
string ofname;
string oxfname;
string oyfname;
string onfname;
string config;
float thresx = 0;
float thresy = 0;
float thress = 0;
po::options_description desc("General Options");
desc.add_options()
("help", "produce help message")
("config,C", po::value<string>(&config), "configuration file")
("input,I", po::value<string>(&ifname), "input file")
("table,T", po::value<string>(&tfname), "lookup table file")
("output,O", po::value<string>(&ofname), "output file")
("xoutput,X", po::value<string>(&oxfname), "x output file")
("youtput,Y", po::value<string>(&oyfname), "y output file")
("noutput,N", po::value<string>(&onfname), "isnoisy output file")
("thresx", po::value<float>(&thresx), "threshold x")
("thresy", po::value<float>(&thresy), "threshold y")
("thress", po::value<float>(&thress), "threshold s");
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if (vm.count("help")) {
cout << desc << "\n";
return 0;
} else if (vm.count("config")) {
cout << config << endl;
ifstream fconf(config);
po::store(po::parse_config_file(fconf, desc), vm);
po::notify(vm);
fconf.close();
}
auto tabmx = map<int, float>();
auto tabmy = map<int, float>();
auto tabmr = map<int, float>();
auto tabvx = map<int, float>();
auto tabvy = map<int, float>();
auto tabvr = map<int, float>();
int from, to, fromto;
float mx, my, mr;
float vx, vy, vr;
FILE *fin = fopen(ifname.c_str(), "r");
FILE *ftable = fopen(tfname.c_str(), "r");
FILE *fout = fopen(ofname.c_str(), "w");
FILE *foutx = fopen(oxfname.c_str(), "w");
FILE *fouty = fopen(oyfname.c_str(), "w");
FILE *foutn = fopen(onfname.c_str(), "w");
int i = 1;
int ct;
while (fscanf(ftable, "%d\t%d\t%f\t%f\t%f\t%f\t%f\t%f", &fromto, &ct, &vx,
&vy, &vr, &mx, &my, &mr) != EOF) {
tabmx[fromto] = mx;
tabmy[fromto] = my;
tabmr[fromto] = mr;
tabvx[fromto] = vx;
tabvy[fromto] = vy;
tabvr[fromto] = vr;
i++;
}
fclose(ftable);
cout << "there are " << i << " entries." << endl;
// Load graph
auto g = graph();
while (fscanf(fin, "%d\t%d", &from, &to) != EOF) {
g.addNode(from, thresx, thresy, thress);
g.addNode(to, thresx, thresy, thress);
fromto = from * 10000 + to;
edge aedge(from, to, tabmx[fromto], tabmy[fromto], tabmr[fromto],
tabvx[fromto], tabvy[fromto], tabvr[fromto], false);
edge bedge(to, from, -tabmx[fromto] / tabmr[fromto],
-tabmy[fromto] / tabmr[fromto], 1 / tabmr[fromto], tabvx[fromto],
tabvy[fromto], tabvr[fromto], true);
g.nodes[from].addEdge(to, aedge);
g.nodes[to].addEdge(from, bedge);
}
i = 0;
// Sort nodes index by degrees
vector<int> nids(g.nodes.size());
size_t j = 0;
for (auto it = g.nodes.begin(); j < g.nodes.size(); j++, it++) {
nids[j] = it->first;
}
sort(nids.begin(), nids.end(), [&g](const int &a, const int &b) {
return g.nodes[a].neighbors.size() > g.nodes[b].neighbors.size();
});
// set initial values
set<int> visited;
set<int> queue;
map<int, vector<float>> result;
map<int, vector<float>> resultx;
map<int, vector<float>> resulty;
map<int, vector<bool>> resultn;
queue.insert(nids[0]);
while (queue.size() > 0) {
int current = *queue.begin();
visited.insert(current);
queue.erase(queue.begin());
if (current == nids[0]) {
g.nodes[nids[0]].scale = 1;
g.nodes[nids[0]].absx = 0;
g.nodes[nids[0]].absy = 0;
} else {
g.nodes[current].calculateScale(g.nodes);
}
vector<int> unvisited;
copy_if(g.nodes[current].neighbors.begin(),
g.nodes[current].neighbors.end(), back_inserter(unvisited),
[&visited](const int &ai) { return (visited.count(ai) == 0); });
cout << "there are " << unvisited.size() << " unvisited neighbors" << endl;
queue.insert(unvisited.begin(), unvisited.end());
}
for (auto it = g.nodes.begin(); it != g.nodes.end(); it++) {
result[it->first].push_back(it->second.scale);
resultx[it->first].push_back(it->second.absx);
resulty[it->first].push_back(it->second.absy);
resultn[it->first].push_back(it->second.noise);
}
for (int j = 0; j < 10; j++) {
for (auto it = nids.begin(); it != nids.end(); it++) {
if (g.nodes[*it].scale != 0) {
g.nodes[*it].calculateScale(g.nodes);
/*
if (*it==124){
cout<<"Node 124 Variance:\tx: "<<g.nodes[*it].varX
<<"\ty: "<<g.nodes[*it].varY<<"\t s: "
<<g.nodes[*it].varS<<endl;
}
*/
}
}
for (auto it = g.nodes.begin(); it != g.nodes.end(); it++) {
result[it->first].push_back(it->second.scale);
resultx[it->first].push_back(it->second.absx);
resulty[it->first].push_back(it->second.absy);
resultn[it->first].push_back(it->second.noise);
}
}
for (auto it = result.begin(); it != result.end(); it++) {
fprintf(fout, "%d", it->first);
for (auto it2 = it->second.begin(); it2 != it->second.end(); it2++) {
fprintf(fout, "\t%f", *it2);
}
fprintf(fout, "\n");
}
for (auto it = resultx.begin(); it != resultx.end(); it++) {
fprintf(foutx, "%d", it->first);
for (auto it2 = it->second.begin(); it2 != it->second.end(); it2++) {
fprintf(foutx, "\t%f", *it2);
}
fprintf(foutx, "\n");
}
for (auto it = resulty.begin(); it != resulty.end(); it++) {
fprintf(fouty, "%d", it->first);
for (auto it2 = it->second.begin(); it2 != it->second.end(); it2++) {
fprintf(fouty, "\t%f", *it2);
}
fprintf(fouty, "\n");
}
for (auto it = resultn.begin(); it != resultn.end(); it++) {
fprintf(foutn, "%d", it->first);
for (auto it2 = it->second.begin(); it2 != it->second.end(); it2++) {
fprintf(foutn, "\t%s", (*it2) ? "true" : "false");
}
fprintf(foutn, "\n");
}
cout << "there are " << g.nodes.size() << " node." << endl;
fclose(fin);
fclose(fout);
fclose(foutx);
fclose(fouty);
fclose(foutn);
cout << "done." << endl;
}