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

Commit f15fa2c

Browse files
committed
Merge branch 'refactoring'
2 parents ed0e5fe + 7599af6 commit f15fa2c

File tree

8 files changed

+37
-29
lines changed

8 files changed

+37
-29
lines changed

DirectedGraph.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include <cmath>
66
#include <random>
7-
#include <climits>
87
#include <iostream>
98
#include <fstream>
109
#include <ctime>
@@ -26,7 +25,7 @@ std::string DirectedGraph::getAvailableAlgorithms() {
2625
}
2726

2827
void DirectedGraph::generate(int numberOfVertices, int density, int range) {
29-
double dens = (double)density / 100;
28+
double dens = (double) density / 100;
3029
dens *= numberOfVertices * (numberOfVertices - 1);
3130
int numberOfEdges = round(dens);
3231

@@ -37,7 +36,7 @@ void DirectedGraph::generate(int numberOfVertices, int density, int range) {
3736
incidenceMatrix.resize(numberOfEdges);
3837
adjacencyList.resize(numberOfVertices);
3938

40-
for (auto& row : incidenceMatrix) {
39+
for (auto &row : incidenceMatrix) {
4140
row.assign(numberOfVertices, 0);
4241
}
4342

@@ -59,13 +58,13 @@ void DirectedGraph::generate(int numberOfVertices, int density, int range) {
5958
for (int i = 0; i < numberOfEdges; i++) {
6059
// random beggining
6160
edgeBeginningNotAvailable = true;
62-
while (edgeBeginningNotAvailable){
61+
while (edgeBeginningNotAvailable) {
6362
beginningVertex = randomVertex(mt);
6463
edgeBeginningNotAvailable = !edgeBeginningAvailable(beginningVertex);
6564
};
6665
// random end
6766
edgeEndNotAvailable = true;
68-
while (edgeEndNotAvailable){
67+
while (edgeEndNotAvailable) {
6968
endVertex = randomVertex(mt);
7069
edgeEndNotAvailable = !edgeEndAvailable(beginningVertex, endVertex);
7170
};
@@ -109,7 +108,7 @@ void DirectedGraph::test() {
109108
double result = 0;
110109
int beginVertex;
111110
int endVertex;
112-
111+
113112
cout.setf(ios::fixed);
114113

115114
for (int i = 0; i < 5; i++) {
@@ -118,9 +117,10 @@ void DirectedGraph::test() {
118117
path = "..\\wyniki\\";
119118
path += to_string(time(0));
120119
path += "-gSkierowany-algorytmDijkstry-n" + to_string(numberOfElements[i]) + "-g" +
121-
to_string(density[j]) + "-r" + representationType[k] + ".txt";
120+
to_string(density[j]) + "-r" + representationType[k] + ".txt";
122121

123-
cout << "Test - Graf: Skierowany - Algorytm: Dijkstry - Ilosc elem: " << numberOfElements[i] << " - Gestosc: " << density[j] << " - Reprezentacja: " << representationType[k] << endl;
122+
cout << "Test - Graf: Skierowany - Algorytm: Dijkstry - Ilosc elem: " << numberOfElements[i]
123+
<< " - Gestosc: " << density[j] << " - Reprezentacja: " << representationType[k] << endl;
124124

125125
fstream file(path, fstream::out);
126126

@@ -189,7 +189,7 @@ void DirectedGraph::loadRawDataToMatrix(std::vector<int> rawData) {
189189
int i = 0;
190190
incidenceMatrix.resize(rawData[i++]); // clear vector and resize to first item of raw data
191191

192-
for (auto& row : incidenceMatrix) {
192+
for (auto &row : incidenceMatrix) {
193193
row.assign(rawData[i], 0);
194194
}
195195
i++;
@@ -261,7 +261,7 @@ std::string DirectedGraph::dijkstrasAlgorithmOnMatrix(int beginVertex, int endVe
261261
for (int i = 0; i < numberOfVertices; i++) {
262262
unsigned long currentLength = pathLength[currentVertex];
263263

264-
for (auto& row : incidenceMatrix) {
264+
for (auto &row : incidenceMatrix) {
265265
if (row[currentVertex] > 0) {
266266
for (int j = 0; j < numberOfVertices; j++) {
267267
if (row[j] < 0) {
@@ -370,8 +370,8 @@ std::string DirectedGraph::dijkstrasAlgorithmOnList(int beginVertex, int endVert
370370
for (int i = 0; i < numberOfVertices; i++) {
371371
unsigned long currentLength = pathLength[currentVertex];
372372

373-
for (auto& edge : adjacencyList[currentVertex]) {
374-
if (pathLength[edge.edgeEnd] > currentLength + edge.value){
373+
for (auto &edge : adjacencyList[currentVertex]) {
374+
if (pathLength[edge.edgeEnd] > currentLength + edge.value) {
375375
pathLength[edge.edgeEnd] = currentLength + edge.value;
376376
previousVertex[edge.edgeEnd] = currentVertex;
377377
}

DirectedGraph.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ class DirectedGraph : public Graph {
2121
void test() override;
2222

2323
protected:
24-
void loadRawDataToMatrix(std::vector<int> rawData) override ;
25-
void loadRawDataToList(std::vector<int> rawData) override ;
24+
void loadRawDataToMatrix(std::vector<int> rawData) override;
25+
26+
void loadRawDataToList(std::vector<int> rawData) override;
2627

2728
private:
2829
std::string dijkstrasAlgorithmOnMatrix(int beginVertex, int endVertex, bool print);
30+
2931
std::string dijkstrasAlgorithmOnList(int beginVertex, int endVertex, bool print);
3032

3133
};

Graph.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ vector<int> Graph::loadRawDataFrom(string path) {
6161
while (file >> temp) {
6262
try {
6363
returnIntVector.push_back(stoi(temp));
64-
} catch (const exception& e) {
64+
} catch (const exception &e) {
6565
returnIntVector.clear();
6666
throw "Bledna zawartosc pliku! Upewnij sie ze podales odpowiedni format!";
6767
}
@@ -72,7 +72,7 @@ vector<int> Graph::loadRawDataFrom(string path) {
7272

7373
bool Graph::edgeBeginningAvailable(int vertex) {
7474
int i = 0;
75-
for (auto& v : adjacencyList[vertex]) {
75+
for (auto &v : adjacencyList[vertex]) {
7676
i++;
7777
}
7878

@@ -85,7 +85,7 @@ bool Graph::edgeEndAvailable(int beginning, int end) {
8585
return false;
8686
}
8787

88-
for (auto& v : adjacencyList[beginning]) {
88+
for (auto &v : adjacencyList[beginning]) {
8989
if (v.edgeEnd == end)
9090
return false;
9191
}
@@ -182,7 +182,7 @@ std::string Graph::printList(vector<forward_list<Graph::EdgeListElement>> v) {
182182
output += temp + " ||";
183183

184184
// kolejne pozycje
185-
for (auto& element : v[i]) {
185+
for (auto &element : v[i]) {
186186
output += " " + to_string(element.edgeEnd) + ", " + to_string(element.value) + " |";
187187
}
188188

Graph.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,15 @@ class Graph {
5454
std::vector<int> loadRawDataFrom(std::string path);
5555

5656
virtual void loadRawDataToMatrix(std::vector<int> rawData)= 0;
57+
5758
virtual void loadRawDataToList(std::vector<int> rawData)= 0;
5859

5960
bool edgeBeginningAvailable(int vertex);
61+
6062
bool edgeEndAvailable(int beginning, int end);
6163

6264
std::string printMatrix(std::vector<std::vector<int>> v);
65+
6366
std::string printList(std::vector<std::forward_list<EdgeListElement>> v);
6467

6568
};

MinHeapElement.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ class MinHeapElement {
1717

1818
public:
1919
int getEdgeBeginning() const;
20+
2021
int getEdgeEnd() const;
22+
2123
int getEdgeValue() const;
2224

2325
};
2426

2527
class MinHeapElementComparator {
2628
public:
27-
int operator() (const MinHeapElement& element1, const MinHeapElement& element2);
29+
int operator()(const MinHeapElement &element1, const MinHeapElement &element2);
2830

2931
};
3032

Program.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//
44

55
#include <iostream>
6-
#include <limits>
76
#include "Program.h"
87

98
using namespace std;

UndirectedGraph.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include <random>
66
#include <queue>
7-
#include <algorithm>
87
#include <iostream>
98
#include <fstream>
109
#include <ctime>
@@ -27,7 +26,7 @@ std::string UndirectedGraph::getAvailableAlgorithms() {
2726
}
2827

2928
void UndirectedGraph::generate(int numberOfVertices, int density, int range) {
30-
double dens = (double)density / 100;
29+
double dens = (double) density / 100;
3130
dens *= numberOfVertices * (numberOfVertices - 1);
3231
dens /= 2;
3332
int numberOfEdges = round(dens);
@@ -39,7 +38,7 @@ void UndirectedGraph::generate(int numberOfVertices, int density, int range) {
3938
incidenceMatrix.resize(numberOfEdges);
4039
adjacencyList.resize(numberOfVertices);
4140

42-
for (auto& row : incidenceMatrix) {
41+
for (auto &row : incidenceMatrix) {
4342
row.assign(numberOfVertices, 0);
4443
}
4544

@@ -96,7 +95,7 @@ string UndirectedGraph::runAlgorithm(char index, char arg1, int arg2, int arg3)
9695
throw "Algorytm nie istnieje!";
9796
}
9897

99-
return output;
98+
return output;
10099
}
101100

102101
void UndirectedGraph::test() {
@@ -120,7 +119,8 @@ void UndirectedGraph::test() {
120119
path += "-gNieskierowany-algorytmPrima-n" + to_string(numberOfElements[i]) + "-g" +
121120
to_string(density[j]) + "-r" + representationType[k] + ".txt";
122121

123-
cout << "Test - Graf: Nieskierowany - Algorytm: Prima - Ilosc elem: " << numberOfElements[i] << " - Gestosc: " << density[j] << " - Reprezentacja: " << representationType[k] << endl;
122+
cout << "Test - Graf: Nieskierowany - Algorytm: Prima - Ilosc elem: " << numberOfElements[i]
123+
<< " - Gestosc: " << density[j] << " - Reprezentacja: " << representationType[k] << endl;
124124

125125
fstream file(path, fstream::out);
126126

@@ -181,7 +181,7 @@ void UndirectedGraph::loadRawDataToMatrix(vector<int> rawData) {
181181
int i = 0;
182182
incidenceMatrix.resize(rawData[i++]); // clear vector and resize to first item of raw data
183183

184-
for (auto& row : incidenceMatrix) {
184+
for (auto &row : incidenceMatrix) {
185185
row.assign(rawData[i], 0);
186186
}
187187
i++;
@@ -328,7 +328,7 @@ std::string UndirectedGraph::primsAlgorithmOnList(bool print) {
328328

329329
do {
330330
// look for edges from first vertices
331-
for (auto& element : adjacencyList[vertexID]) {
331+
for (auto &element : adjacencyList[vertexID]) {
332332
queue.push(MinHeapElement(vertexID, element.edgeEnd, element.value));
333333
}
334334

UndirectedGraph.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ class UndirectedGraph : public Graph {
2121
void test() override;
2222

2323
protected:
24-
void loadRawDataToMatrix(std::vector<int> rawData) override ;
25-
void loadRawDataToList(std::vector<int> rawData) override ;
24+
void loadRawDataToMatrix(std::vector<int> rawData) override;
25+
26+
void loadRawDataToList(std::vector<int> rawData) override;
2627

2728
private:
2829
std::string primsAlgorithmOnMatrix(bool print);
30+
2931
std::string primsAlgorithmOnList(bool print);
3032

3133
};

0 commit comments

Comments
 (0)