forked from MiskaMoska/Fast-TRA
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanalysis.cpp
More file actions
84 lines (68 loc) · 1.97 KB
/
analysis.cpp
File metadata and controls
84 lines (68 loc) · 1.97 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
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <tuple>
#include <iomanip> // For std::setprecision
using namespace std;
//outside node is (5,5)
pair<int, int> calculate_coordinates(int value) {
if (value == 192) {
return {5, 5};
}
int x = (value / 12) % 4;
int y = (value / 12) / 4;
return {x, y};
}
struct Edge {
pair<int, int> source;
pair<int, int> destination;
double total_c;
Edge(pair<int, int> src, pair<int, int> dest, double c)
: source(src), destination(dest), total_c(c) {}
};
void processFile(const string& file_path) {
vector<Edge> edges;
ifstream file(file_path);
if (!file.is_open()) {
cerr << "fail to open file: " << file_path << endl;
return;
}
string line;
while (getline(file, line)) {
stringstream ss(line);
int a, b;
double c;
if (!(ss >> a >> b >> c)) {
cerr << "wrong data format: " << line << endl;
continue;
}
if ((a / 12 == b / 12) && a != 192 && b != 192) {
continue;
}
pair<int, int> source = calculate_coordinates(a);
pair<int, int> destination = calculate_coordinates(b);
bool found = false;
for (auto& edge : edges) {
if (edge.source == source && edge.destination == destination) {
edge.total_c += c;
found = true;
break;
}
}
if (!found) {
edges.emplace_back(source, destination, c);
}
}
file.close();
for (const auto& edge : edges) {
cout << "(" << edge.source.first << ", " << edge.source.second << ") -> ("
<< edge.destination.first << ", " << edge.destination.second << ") Total c: "
<< fixed << setprecision(2) << edge.total_c << endl;
}
}
int main() {
string file_path = "./4*4mesh/simulateresult.txt";
processFile(file_path);
return 0;
}