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

Commit ed0e5fe

Browse files
committed
Merge branch 'dijkstras-fix'
2 parents 294f34c + aa24b26 commit ed0e5fe

1 file changed

Lines changed: 71 additions & 19 deletions

File tree

DirectedGraph.cpp

Lines changed: 71 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void DirectedGraph::test() {
118118
path = "..\\wyniki\\";
119119
path += to_string(time(0));
120120
path += "-gSkierowany-algorytmDijkstry-n" + to_string(numberOfElements[i]) + "-g" +
121-
to_string(density[j]) + "-r" + representationType[k] + ".txt";
121+
to_string(density[j]) + "-r" + representationType[k] + ".txt";
122122

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

@@ -289,25 +289,51 @@ std::string DirectedGraph::dijkstrasAlgorithmOnMatrix(int beginVertex, int endVe
289289
}
290290

291291
if ((i != numberOfVertices - 1) && (shortestPathVertex == -1))
292-
throw "Graf niespojny!";
292+
break;
293293

294294
currentVertex = shortestPathVertex;
295295

296296
}
297297

298298
if (print) {
299299
string output;
300-
output = "Najkrotsza droga z wierzch.: " + to_string(beginVertex) + " do wierzch.: " + to_string(endVertex) +
301-
" wynosi: " + to_string(pathLength[endVertex]) + ".\n";
302-
output += "Prowadzi nastepujaca droga: ";
300+
shortestPath = pathLength[endVertex];
303301

304-
currentVertex = endVertex;
302+
if (shortestPath == ULONG_MAX) {
303+
output += "Droga pomiedzy wybranymi wierzcholkami nie istnieje!\n\n";
304+
} else {
305+
output =
306+
"Najkrotsza droga z wierzch.: " + to_string(beginVertex) + " do wierzch.: " + to_string(endVertex) +
307+
" wynosi: " + to_string(shortestPath) + ".\n";
308+
output += "Prowadzi nastepujaca droga: ";
309+
310+
currentVertex = endVertex;
311+
312+
output += to_string(currentVertex);
313+
314+
while (currentVertex != beginVertex) {
315+
currentVertex = previousVertex[currentVertex];
316+
output += " <- " + to_string(currentVertex);
317+
}
305318

306-
output += to_string(currentVertex);
319+
output += "\n\n";
320+
}
321+
322+
output += "Najkrotsza droga do innych wierzcholkow: \n";
323+
output += "W | Dlugosc\n";
324+
output += "------------------\n";
325+
for (int i = 0; i < numberOfVertices; i++) {
326+
shortestPath = pathLength[i];
327+
328+
output += to_string(i) + " | ";
329+
330+
if (shortestPath == ULONG_MAX) {
331+
output += "BRAK";
332+
} else {
333+
output += to_string(shortestPath);
334+
}
307335

308-
while (currentVertex != beginVertex) {
309-
currentVertex = previousVertex[currentVertex];
310-
output += " <- " + to_string(currentVertex);
336+
output += "\n";
311337
}
312338

313339
return output;
@@ -366,25 +392,51 @@ std::string DirectedGraph::dijkstrasAlgorithmOnList(int beginVertex, int endVert
366392
}
367393

368394
if ((i != numberOfVertices - 1) && (shortestPathVertex == -1))
369-
throw "Graf niespojny!";
395+
break;
370396

371397
currentVertex = shortestPathVertex;
372398

373399
}
374400

375401
if (print) {
376402
string output;
377-
output = "Najkrotsza droga z wierzch.: " + to_string(beginVertex) + " do wierzch.: " + to_string(endVertex) +
378-
" wynosi: " + to_string(pathLength[endVertex]) + ".\n";
379-
output += "Prowadzi nastepujaca droga: ";
403+
shortestPath = pathLength[endVertex];
380404

381-
currentVertex = endVertex;
405+
if (shortestPath == ULONG_MAX) {
406+
output += "Droga pomiedzy wybranymi wierzcholkami nie istnieje!\n\n";
407+
} else {
408+
output =
409+
"Najkrotsza droga z wierzch.: " + to_string(beginVertex) + " do wierzch.: " + to_string(endVertex) +
410+
" wynosi: " + to_string(shortestPath) + ".\n";
411+
output += "Prowadzi nastepujaca droga: ";
412+
413+
currentVertex = endVertex;
414+
415+
output += to_string(currentVertex);
416+
417+
while (currentVertex != beginVertex) {
418+
currentVertex = previousVertex[currentVertex];
419+
output += " <- " + to_string(currentVertex);
420+
}
382421

383-
output += to_string(currentVertex);
422+
output += "\n\n";
423+
}
424+
425+
output += "Najkrotsza droga do innych wierzcholkow: \n";
426+
output += "W | Dlugosc\n";
427+
output += "------------------\n";
428+
for (int i = 0; i < numberOfVertices; i++) {
429+
shortestPath = pathLength[i];
430+
431+
output += to_string(i) + " | ";
432+
433+
if (shortestPath == ULONG_MAX) {
434+
output += "BRAK";
435+
} else {
436+
output += to_string(shortestPath);
437+
}
384438

385-
while (currentVertex != beginVertex) {
386-
currentVertex = previousVertex[currentVertex];
387-
output += " <- " + to_string(currentVertex);
439+
output += "\n";
388440
}
389441

390442
return output;

0 commit comments

Comments
 (0)