|
5 | 5 | #include <cmath> |
6 | 6 | #include <random> |
7 | 7 | #include <climits> |
| 8 | +#include <iostream> |
| 9 | +#include <fstream> |
| 10 | +#include <ctime> |
8 | 11 | #include "DirectedGraph.h" |
| 12 | +#include "Counter.h" |
9 | 13 |
|
10 | 14 | using namespace std; |
11 | 15 |
|
@@ -94,7 +98,88 @@ string DirectedGraph::runAlgorithm(char index, char arg1, int arg2, int arg3) { |
94 | 98 | } |
95 | 99 |
|
96 | 100 | 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 | + cout.setf(ios::fixed); |
| 114 | + |
| 115 | + for (int i = 0; i < 5; i++) { |
| 116 | + for (int j = 0; j < 4; j++) { |
| 117 | + for (int k = 0; k < 2; k++) { |
| 118 | + path = "..\\wyniki\\"; |
| 119 | + path += to_string(time(0)); |
| 120 | + path += "-gSkierowany-algorytmDijkstry-n" + to_string(numberOfElements[i]) + "-g" + |
| 121 | + to_string(density[j]) + "-r" + representationType[k] + ".txt"; |
| 122 | + |
| 123 | + cout << "Test - Graf: Skierowany - Algorytm: Dijkstry - Ilosc elem: " << numberOfElements[i] << " - Gestosc: " << density[j] << " - Reprezentacja: " << representationType[k] << endl; |
| 124 | + |
| 125 | + fstream file(path, fstream::out); |
| 126 | + |
| 127 | + file.setf(ios::fixed); |
| 128 | + |
| 129 | + sumOfResults = 0; |
| 130 | + |
| 131 | + if (!file.is_open()) { |
| 132 | + cerr << "Wyniki sie nie zapisza!!!" << endl; |
| 133 | + } |
| 134 | + |
| 135 | + for (int l = 0; l < numberOfTests; l++) { |
| 136 | + generate(numberOfElements[i], density[j], range); |
| 137 | + |
| 138 | + cout << "Test: " << l << " - "; |
| 139 | + |
| 140 | + std::random_device rd; |
| 141 | + std::mt19937 mt(rd()); |
| 142 | + std::uniform_int_distribution<int> randomVertex(0, numberOfElements[i] - 1); |
| 143 | + beginVertex = randomVertex(mt); |
| 144 | + endVertex = randomVertex(mt); |
| 145 | + |
| 146 | + cout << "PW: " << beginVertex << ", KW: " << endVertex << " - "; |
| 147 | + |
| 148 | + if (representationType[k] == 'M') { |
| 149 | + try { |
| 150 | + counter.startCounter(); |
| 151 | + dijkstrasAlgorithmOnMatrix(beginVertex, endVertex, false); |
| 152 | + result = counter.getCounter(); |
| 153 | + } catch (const char* e) { |
| 154 | + l--; |
| 155 | + result = 0; |
| 156 | + } |
| 157 | + } else { |
| 158 | + try { |
| 159 | + counter.startCounter(); |
| 160 | + dijkstrasAlgorithmOnList(beginVertex, endVertex, false); |
| 161 | + result = counter.getCounter(); |
| 162 | + } catch (const char* e) { |
| 163 | + l--; |
| 164 | + result = 0; |
| 165 | + } |
| 166 | + } |
97 | 167 |
|
| 168 | + cout << "Czas: " << result << endl; |
| 169 | + file << result << endl; |
| 170 | + |
| 171 | + sumOfResults += result; |
| 172 | + } |
| 173 | + |
| 174 | + sumOfResults /= numberOfTests; |
| 175 | + |
| 176 | + cout << "Srednia: " << sumOfResults << endl; |
| 177 | + file << "Srednia" << endl << sumOfResults << endl; |
| 178 | + |
| 179 | + file.close(); |
| 180 | + } |
| 181 | + } |
| 182 | + } |
98 | 183 | } |
99 | 184 |
|
100 | 185 | // protected |
|
0 commit comments