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

Commit

Permalink
Merge branch 'algorithm-result-printing' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
baatochan committed May 20, 2018
2 parents bca27d5 + 90d1c52 commit a2e1f88
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 36 deletions.
54 changes: 32 additions & 22 deletions DirectedGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ string DirectedGraph::runAlgorithm(char index, char arg1, int arg2, int arg3) {

if (index == 1) {
if (arg1 == 0) {
output = dijkstrasAlgorithmOnMatrix(arg2, arg3);
output = dijkstrasAlgorithmOnMatrix(arg2, arg3, true);
} else if (arg1 == 1) {
output = dijkstrasAlgorithmOnList(arg2, arg3);
output = dijkstrasAlgorithmOnList(arg2, arg3, true);
} else {
throw "Nieznany blad!"; // should never be thrown
}
Expand Down Expand Up @@ -148,7 +148,7 @@ void DirectedGraph::loadRawDataToList(std::vector<int> rawData) {

// private

std::string DirectedGraph::dijkstrasAlgorithmOnMatrix(int beginVertex, int endVertex) {
std::string DirectedGraph::dijkstrasAlgorithmOnMatrix(int beginVertex, int endVertex, bool print) {
if (incidenceMatrix.size() == 0)
throw "Graf pusty!";

Expand Down Expand Up @@ -210,23 +210,28 @@ std::string DirectedGraph::dijkstrasAlgorithmOnMatrix(int beginVertex, int endVe

}

string output;
output = "Najkrotsza droga z wierzch.: " + to_string(beginVertex) + " do wierzch.: " + to_string(endVertex) + " wynosi: " + to_string(pathLength[endVertex]) + ".\n";
output += "Prowadzi nastepujaca droga: ";
if (print) {
string output;
output = "Najkrotsza droga z wierzch.: " + to_string(beginVertex) + " do wierzch.: " + to_string(endVertex) +
" wynosi: " + to_string(pathLength[endVertex]) + ".\n";
output += "Prowadzi nastepujaca droga: ";

currentVertex = endVertex;

currentVertex = endVertex;
output += to_string(currentVertex);

output += to_string(currentVertex);
while (currentVertex != beginVertex) {
currentVertex = previousVertex[currentVertex];
output += " <- " + to_string(currentVertex);
}

while (currentVertex != beginVertex) {
currentVertex = previousVertex[currentVertex];
output += " <- " + to_string(currentVertex);
return output;
}

return output;
return "";
}

std::string DirectedGraph::dijkstrasAlgorithmOnList(int beginVertex, int endVertex) {
std::string DirectedGraph::dijkstrasAlgorithmOnList(int beginVertex, int endVertex, bool print) {
if (adjacencyList.size() == 0)
throw "Graf pusty!";

Expand Down Expand Up @@ -282,18 +287,23 @@ std::string DirectedGraph::dijkstrasAlgorithmOnList(int beginVertex, int endVert

}

string output;
output = "Najkrotsza droga z wierzch.: " + to_string(beginVertex) + " do wierzch.: " + to_string(endVertex) + " wynosi: " + to_string(pathLength[endVertex]) + ".\n";
output += "Prowadzi nastepujaca droga: ";
if (print) {
string output;
output = "Najkrotsza droga z wierzch.: " + to_string(beginVertex) + " do wierzch.: " + to_string(endVertex) +
" wynosi: " + to_string(pathLength[endVertex]) + ".\n";
output += "Prowadzi nastepujaca droga: ";

currentVertex = endVertex;

currentVertex = endVertex;
output += to_string(currentVertex);

output += to_string(currentVertex);
while (currentVertex != beginVertex) {
currentVertex = previousVertex[currentVertex];
output += " <- " + to_string(currentVertex);
}

while (currentVertex != beginVertex) {
currentVertex = previousVertex[currentVertex];
output += " <- " + to_string(currentVertex);
return output;
}

return output;
return "";
}
4 changes: 2 additions & 2 deletions DirectedGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class DirectedGraph : public Graph {
void loadRawDataToList(std::vector<int> rawData) override ;

private:
std::string dijkstrasAlgorithmOnMatrix(int beginVertex, int endVertex);
std::string dijkstrasAlgorithmOnList(int beginVertex, int endVertex);
std::string dijkstrasAlgorithmOnMatrix(int beginVertex, int endVertex, bool print);
std::string dijkstrasAlgorithmOnList(int beginVertex, int endVertex, bool print);

};

Expand Down
28 changes: 18 additions & 10 deletions UndirectedGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ string UndirectedGraph::runAlgorithm(char index, char arg1, int arg2, int arg3)

if (index == 1) {
if (arg1 == 0) {
output = primsAlgorithmOnMatrix();
output = primsAlgorithmOnMatrix(true);
} else if (arg1 == 1) {
output = primsAlgorithmOnList();
output = primsAlgorithmOnList(true);
} else {
throw "Nieznany blad!"; // should never be thrown
}
Expand Down Expand Up @@ -151,7 +151,7 @@ void UndirectedGraph::loadRawDataToList(std::vector<int> rawData) {

// private

string UndirectedGraph::primsAlgorithmOnMatrix() {
std::string UndirectedGraph::primsAlgorithmOnMatrix(bool print) {
// prepare vector for output
vector<vector<int>> minimumSpanningTree;

Expand Down Expand Up @@ -219,14 +219,18 @@ string UndirectedGraph::primsAlgorithmOnMatrix() {

} while (foundVertices.size() < numberOfVertices);

string output = "Minimalne drzewo rozpinajace\n";
if (print) {
string output = "Minimalne drzewo rozpinajace\n";

output += printMatrix(minimumSpanningTree);
output += printMatrix(minimumSpanningTree);

return output;
return output;
}

return "";
}

string UndirectedGraph::primsAlgorithmOnList() {
std::string UndirectedGraph::primsAlgorithmOnList(bool print) {
// prepare vector for output
std::vector<std::forward_list<EdgeListElement>> minimumSpanningTree;

Expand Down Expand Up @@ -273,9 +277,13 @@ string UndirectedGraph::primsAlgorithmOnList() {

} while (foundVertices.size() < numberOfVertices);

string output = "Minimalne drzewo rozpinajace\n";
if (print) {
string output = "Minimalne drzewo rozpinajace\n";

output += printList(minimumSpanningTree);
output += printList(minimumSpanningTree);

return output;
return output;
}

return "";
}
4 changes: 2 additions & 2 deletions UndirectedGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class UndirectedGraph : public Graph {
void loadRawDataToList(std::vector<int> rawData) override ;

private:
std::string primsAlgorithmOnMatrix();
std::string primsAlgorithmOnList();
std::string primsAlgorithmOnMatrix(bool print);
std::string primsAlgorithmOnList(bool print);

};

Expand Down

0 comments on commit a2e1f88

Please sign in to comment.