|
5 | 5 | #include <random> |
6 | 6 | #include <queue> |
7 | 7 | #include <algorithm> |
| 8 | +#include <iostream> |
| 9 | +#include <fstream> |
| 10 | +#include <ctime> |
8 | 11 | #include "UndirectedGraph.h" |
9 | 12 | #include "MinHeapElement.h" |
| 13 | +#include "Counter.h" |
10 | 14 |
|
11 | 15 | using namespace std; |
12 | 16 |
|
@@ -96,7 +100,76 @@ string UndirectedGraph::runAlgorithm(char index, char arg1, int arg2, int arg3) |
96 | 100 | } |
97 | 101 |
|
98 | 102 | void UndirectedGraph::test() { |
| 103 | + int numberOfElements[5] = {50, 100, 150, 200, 250}; |
| 104 | + int density[4] = {25, 50, 75, 99}; |
| 105 | + char representationType[2] = {'M', 'L'}; |
| 106 | + int range = 1000; |
| 107 | + int numberOfTests = 100; |
| 108 | + string path; |
| 109 | + double sumOfResults; |
| 110 | + Counter counter; |
| 111 | + double result = 0; |
| 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 += "-gNieskierowany-algorytmPrima-n" + to_string(numberOfElements[i]) + "-g" + |
| 119 | + to_string(density[j]) + "-r" + representationType[k] + ".txt"; |
| 120 | + |
| 121 | + cout << "Test - Graf: Nieskierowany - Algorytm: Prima - 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 | + } |
| 132 | + |
| 133 | + for (int l = 0; l < numberOfTests; l++) { |
| 134 | + generate(numberOfElements[i], density[j], range); |
| 135 | + |
| 136 | + cout << "Test: " << l << " - "; |
| 137 | + |
| 138 | + if (representationType[k] == 'M') { |
| 139 | + try { |
| 140 | + counter.startCounter(); |
| 141 | + primsAlgorithmOnMatrix(false); |
| 142 | + result = counter.getCounter(); |
| 143 | + } catch (const char* e) { |
| 144 | + l--; |
| 145 | + result = 0; |
| 146 | + } |
| 147 | + } else { |
| 148 | + try { |
| 149 | + counter.startCounter(); |
| 150 | + primsAlgorithmOnList(false); |
| 151 | + result = counter.getCounter(); |
| 152 | + } catch (const char* e) { |
| 153 | + l--; |
| 154 | + result = 0; |
| 155 | + } |
| 156 | + } |
| 157 | + |
| 158 | + cout << "Czas: " << result << endl; |
| 159 | + file << result << endl; |
| 160 | + |
| 161 | + sumOfResults += result; |
| 162 | + } |
99 | 163 |
|
| 164 | + sumOfResults /= numberOfTests; |
| 165 | + |
| 166 | + cout << "Srednia: " << sumOfResults << endl; |
| 167 | + file << "Srednia" << endl << sumOfResults << endl; |
| 168 | + |
| 169 | + file.close(); |
| 170 | + } |
| 171 | + } |
| 172 | + } |
100 | 173 | } |
101 | 174 |
|
102 | 175 | // protected |
|
0 commit comments