Skip to content
This repository was archived by the owner on May 27, 2019. It is now read-only.

Commit 6094805

Browse files
committed
Add method for testing digraphs
1 parent f7e8038 commit 6094805

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

DirectedGraph.cpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
#include <cmath>
66
#include <random>
77
#include <climits>
8+
#include <iostream>
9+
#include <fstream>
10+
#include <ctime>
811
#include "DirectedGraph.h"
12+
#include "Counter.h"
913

1014
using namespace std;
1115

@@ -94,7 +98,84 @@ string DirectedGraph::runAlgorithm(char index, char arg1, int arg2, int arg3) {
9498
}
9599

96100
void DirectedGraph::test() {
101+
int numberOfElements[5] = {50, 100, 150, 200, 250};
102+
int density[4] = {25, 50, 75, 99};
103+
char representationType[2] = {'M', 'L'};
104+
int range = 1000;
105+
int numberOfTests = 100;
106+
string path;
107+
double sumOfResults;
108+
Counter counter;
109+
double result = 0;
110+
int beginVertex;
111+
int endVertex;
112+
113+
for (int i = 0; i < 5; i++) {
114+
for (int j = 0; j < 4; j++) {
115+
for (int k = 0; k < 2; k++) {
116+
path = "..\\wyniki\\";
117+
path += to_string(time(0));
118+
path += "-gSkierowany-algorytmDijkstry-n" + to_string(numberOfElements[i]) + "-g" +
119+
to_string(density[j]) + "-r" + representationType[k] + ".txt";
120+
121+
cout << "Test - Graf: Skierowany - Algorytm: Dijkstry - Ilosc elem: " << numberOfElements[i] << " - Gestosc: " << density[j] << " - Reprezentacja: " << representationType[k] << endl;
122+
123+
fstream file(path, fstream::out);
124+
125+
file.setf(ios::fixed);
126+
127+
sumOfResults = 0;
128+
129+
if (!file.is_open()) {
130+
cerr << "Wyniki sie nie zapisza!!!" << endl;
131+
}
97132

133+
for (int l = 0; l < numberOfTests; l++) {
134+
generate(numberOfElements[i], density[j], range);
135+
136+
cout << "Test: " << l << " - ";
137+
138+
std::random_device rd;
139+
std::mt19937 mt(rd());
140+
std::uniform_int_distribution<int> randomVertex(0, numberOfElements[i] - 1);
141+
beginVertex = randomVertex(mt);
142+
endVertex = randomVertex(mt);
143+
144+
if (representationType[k] == 'M') {
145+
try {
146+
counter.startCounter();
147+
dijkstrasAlgorithmOnMatrix(beginVertex, endVertex, false);
148+
result = counter.getCounter();
149+
} catch (const char* e) {
150+
l--;
151+
result = 0;
152+
}
153+
} else {
154+
try {
155+
counter.startCounter();
156+
dijkstrasAlgorithmOnList(beginVertex, endVertex, false);
157+
result = counter.getCounter();
158+
} catch (const char* e) {
159+
l--;
160+
result = 0;
161+
}
162+
}
163+
164+
cout << "Czas: " << result << endl;
165+
file << result << endl;
166+
167+
sumOfResults += result;
168+
}
169+
170+
sumOfResults /= numberOfTests;
171+
172+
cout << "Srednia: " << sumOfResults << endl;
173+
file << "Srednia" << endl << sumOfResults << endl;
174+
175+
file.close();
176+
}
177+
}
178+
}
98179
}
99180

100181
// protected

0 commit comments

Comments
 (0)