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

Commit 01c22cd

Browse files
committed
Merge branch 'development'
Looks like everything is done
2 parents 7d360a6 + 7706e88 commit 01c22cd

File tree

6 files changed

+219
-1
lines changed

6 files changed

+219
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,6 @@ com_crashlytics_export_strings.xml
4747
crashlytics.properties
4848
crashlytics-build.properties
4949
fabric.properties
50+
51+
# Test results folder
52+
wyniki/

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ if (CMAKE_BUILD_TYPE MATCHES RELEASE)
77
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
88
endif (CMAKE_BUILD_TYPE MATCHES RELEASE)
99

10-
set(SOURCE_FILES main.cpp Program.cpp Graph.cpp DirectedGraph.cpp UndirectedGraph.cpp MinHeapElement.cpp)
10+
set(SOURCE_FILES main.cpp Program.cpp Graph.cpp DirectedGraph.cpp UndirectedGraph.cpp MinHeapElement.cpp Counter.cpp)
1111
add_executable(GraphRepresentationsAndAlgorithmsComparison ${SOURCE_FILES})

Counter.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// Created by barto on 18.04.17.
3+
//
4+
5+
#include "Counter.h"
6+
7+
// public
8+
9+
void Counter::startCounter() {
10+
LARGE_INTEGER li;
11+
if (!QueryPerformanceFrequency(&li))
12+
std::cout << "QueryPerformanceFrequency failed!\n";
13+
14+
PCFreq = double(li.QuadPart) / 1000000.0;
15+
16+
QueryPerformanceCounter(&li);
17+
CounterStart = li.QuadPart;
18+
}
19+
20+
double Counter::getCounter() {
21+
LARGE_INTEGER li;
22+
QueryPerformanceCounter(&li);
23+
return double(li.QuadPart - CounterStart) / PCFreq;
24+
}

Counter.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// Created by barto on 18.04.17.
3+
//
4+
// Code written by Ramonster.
5+
// It was said in task description that we can use code from that link.
6+
//
7+
8+
#ifndef DATASTRUCTURESSDIZO_COUNTER_H
9+
#define DATASTRUCTURESSDIZO_COUNTER_H
10+
11+
12+
#include <windows.h>
13+
#include <iostream>
14+
15+
class Counter {
16+
private:
17+
18+
double PCFreq = 0.0;
19+
20+
__int64 CounterStart = 0;
21+
22+
public:
23+
24+
void startCounter();
25+
26+
double getCounter();
27+
28+
};
29+
30+
31+
#endif //DATASTRUCTURESSDIZO_COUNTER_H

DirectedGraph.cpp

Lines changed: 85 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,88 @@ 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+
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+
}
97167

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+
}
98183
}
99184

100185
// protected

UndirectedGraph.cpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
#include <random>
66
#include <queue>
77
#include <algorithm>
8+
#include <iostream>
9+
#include <fstream>
10+
#include <ctime>
811
#include "UndirectedGraph.h"
912
#include "MinHeapElement.h"
13+
#include "Counter.h"
1014

1115
using namespace std;
1216

@@ -96,7 +100,78 @@ string UndirectedGraph::runAlgorithm(char index, char arg1, int arg2, int arg3)
96100
}
97101

98102
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;
99112

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 += "-gNieskierowany-algorytmPrima-n" + to_string(numberOfElements[i]) + "-g" +
121+
to_string(density[j]) + "-r" + representationType[k] + ".txt";
122+
123+
cout << "Test - Graf: Nieskierowany - Algorytm: Prima - 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+
if (representationType[k] == 'M') {
141+
try {
142+
counter.startCounter();
143+
primsAlgorithmOnMatrix(false);
144+
result = counter.getCounter();
145+
} catch (const char* e) {
146+
l--;
147+
result = 0;
148+
}
149+
} else {
150+
try {
151+
counter.startCounter();
152+
primsAlgorithmOnList(false);
153+
result = counter.getCounter();
154+
} catch (const char* e) {
155+
l--;
156+
result = 0;
157+
}
158+
}
159+
160+
cout << "Czas: " << result << endl;
161+
file << result << endl;
162+
163+
sumOfResults += result;
164+
}
165+
166+
sumOfResults /= numberOfTests;
167+
168+
cout << "Srednia: " << sumOfResults << endl;
169+
file << "Srednia" << endl << sumOfResults << endl;
170+
171+
file.close();
172+
}
173+
}
174+
}
100175
}
101176

102177
// protected

0 commit comments

Comments
 (0)