Skip to content

Commit 655df71

Browse files
committed
Added program to improve comparison of outputs and made minor fixes
1 parent 1b92a8f commit 655df71

6 files changed

Lines changed: 115 additions & 7 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ ThirdParty/log4cplus-2.0.7/src/liblog4cplus.so.2.0.7
4141
graphitti
4242
ggraphitti
4343
cgraphitti
44+
compare_matrices
4445
tests
4546
serialFullTest
4647
serialFirstHalfTest

Simulator/Connections/NG911/Connections911.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ bool Connections911::updateConnections()
7373
// Record old type map
7474
int numVertices = Simulator::getInstance().getTotalVertices();
7575
Layout &layout = Simulator::getInstance().getModel().getLayout();
76-
// oldTypeMap_ = layout.vertexTypeMap_;
76+
AllVertices &vertices = layout.getVertices();
7777

7878
// Erase PSAPs
7979
for (int i = 0; i < psapsToErase_; i++) {

Simulator/Connections/Neuro/ConnStatic.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,6 @@ class ConnStatic : public Connections {
8383
return destVertexIndexCurrentEpoch_.getVector();
8484
}
8585

86-
/// Output the weights matrix after every epoch.
87-
///
88-
/// @return true if successful, false otherwise.
89-
virtual bool updateConnections() override;
90-
9186
/// Cereal serialization method
9287
template <class Archive> void serialize(Archive &archive);
9388

Simulator/Vertices/NG911/All911Vertices.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void All911Vertices::registerHistoryVariables()
139139
Recorder &recorder = Simulator::getInstance().getModel().getRecorder();
140140

141141
// Registering the following variables to be recorded
142-
recorder.registerVariable("numTrunkS", numTrunks_, Recorder::UpdatedType::CONSTANT);
142+
recorder.registerVariable("numTrunks", numTrunks_, Recorder::UpdatedType::CONSTANT);
143143
recorder.registerVariable("numServers", numServers_, Recorder::UpdatedType::CONSTANT);
144144
recorder.registerVariable("droppedCalls", droppedCalls_, Recorder::UpdatedType::DYNAMIC);
145145
recorder.registerVariable("receivedCalls", receivedCalls_, Recorder::UpdatedType::CONSTANT);
0 Bytes
Binary file not shown.
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#include <iostream>
2+
#include <fstream>
3+
#include <sstream>
4+
#include <string>
5+
#include <vector>
6+
#include <map>
7+
#include <set>
8+
#include <algorithm>
9+
10+
// Helper to trim whitespace
11+
std::string trim(const std::string& s) {
12+
size_t start = s.find_first_not_of(" \t\r\n");
13+
size_t end = s.find_last_not_of(" \t\r\n");
14+
return (start == std::string::npos) ? "" : s.substr(start, end - start + 1);
15+
}
16+
17+
// Parse matrices from XML file
18+
std::map<std::string, std::vector<std::string>> parse_matrices(const std::string& filename) {
19+
std::ifstream file(filename);
20+
std::map<std::string, std::vector<std::string>> matrices;
21+
std::string line, current_name;
22+
bool in_matrix = false;
23+
std::vector<std::string> values;
24+
25+
while (std::getline(file, line)) {
26+
line = trim(line);
27+
if (line.find("<Matrix") == 0) {
28+
size_t name_pos = line.find("name=\"");
29+
if (name_pos != std::string::npos) {
30+
size_t start = name_pos + 6;
31+
size_t end = line.find("\"", start);
32+
current_name = line.substr(start, end - start);
33+
in_matrix = true;
34+
values.clear();
35+
}
36+
} else if (in_matrix && line.find("</Matrix>") == 0) {
37+
matrices[current_name] = values;
38+
in_matrix = false;
39+
} else if (in_matrix) {
40+
std::istringstream iss(line);
41+
std::string val;
42+
while (iss >> val) {
43+
values.push_back(val);
44+
}
45+
}
46+
}
47+
return matrices;
48+
}
49+
50+
int main(int argc, char* argv[]) {
51+
if (argc != 3) {
52+
std::cerr << "Usage: compare_matrices good_output.xml test_output.xml\n";
53+
return 1;
54+
}
55+
56+
auto good = parse_matrices(argv[1]);
57+
auto test = parse_matrices(argv[2]);
58+
59+
std::set<std::string> all_vars;
60+
for (const auto& kv : good) all_vars.insert(kv.first);
61+
for (const auto& kv : test) all_vars.insert(kv.first);
62+
63+
int compared = 0;
64+
std::vector<std::string> mismatched_vars;
65+
66+
for (const auto& var : all_vars) {
67+
68+
int in_good = good.count(var);
69+
int in_test = test.count(var);
70+
71+
if (in_good==0) {
72+
std::cout << "Variable '" << var << "' present in test output but missing from good output.\n";
73+
continue;
74+
}
75+
if (in_test==0) {
76+
std::cout << "Variable '" << var << "' present in good output but missing from test output.\n";
77+
continue;
78+
}
79+
80+
compared++;
81+
const auto& good_vals = good[var];
82+
const auto& test_vals = test[var];
83+
if (good_vals.size() != test_vals.size()) {
84+
std::cout << "Variable '" << var << "' has different number of values (good: " << good_vals.size()
85+
<< ", test: " << test_vals.size() << ").\n";
86+
mismatched_vars.push_back(var);
87+
continue;
88+
}
89+
bool mismatch = false;
90+
for (size_t i = 0; i < good_vals.size(); ++i) {
91+
if (good_vals[i] != test_vals[i]) {
92+
mismatch = true;
93+
break;
94+
}
95+
}
96+
if (mismatch) {
97+
std::cout << "Variable '" << var << "' has mismatched values.\n";
98+
mismatched_vars.push_back(var);
99+
}
100+
}
101+
102+
std::cout << compared << " variables compared.\n";
103+
if (!mismatched_vars.empty()) {
104+
std::cout << "Mismatched values found for variables:\n";
105+
for (const auto& var : mismatched_vars) {
106+
std::cout << " " << var << "\n";
107+
}
108+
} else {
109+
std::cout << "All compared variables matched.\n";
110+
}
111+
return 0;
112+
}

0 commit comments

Comments
 (0)