consolidate all repos to one for archive
This commit is contained in:
3
semester_2/osnove_algoritmov/naloga_5/.gitignore
vendored
Normal file
3
semester_2/osnove_algoritmov/naloga_5/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
.idea/*
|
||||
cmake-build-debug/*
|
||||
CMakeLists.txt
|
1
semester_2/osnove_algoritmov/naloga_5/README.md
Normal file
1
semester_2/osnove_algoritmov/naloga_5/README.md
Normal file
@@ -0,0 +1 @@
|
||||
Navodila v folder navodila
|
139
semester_2/osnove_algoritmov/naloga_5/main.cpp
Normal file
139
semester_2/osnove_algoritmov/naloga_5/main.cpp
Normal file
@@ -0,0 +1,139 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
void FLOYD_WARSHALL(int **&C, int **&D, int **&PI, int st_vozlisc) {
|
||||
|
||||
D = new int *[st_vozlisc];
|
||||
PI = new int *[st_vozlisc];
|
||||
|
||||
for (int i = 0; i < st_vozlisc; i++) {
|
||||
PI[i] = new int[st_vozlisc];
|
||||
D[i] = new int[st_vozlisc];
|
||||
}
|
||||
|
||||
for (int i = 0; i < st_vozlisc; i++) {
|
||||
for (int j = 0; j < st_vozlisc; j++) {
|
||||
D[i][j] = C[i][j];
|
||||
if (i != j && C[i][j] != INT16_MAX) { //inf
|
||||
PI[i][j] = i;
|
||||
} else {
|
||||
PI[i][j] = INT16_MAX; //nill
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int k = 0; k < st_vozlisc; k++) {
|
||||
for (int i = 0; i < st_vozlisc; i++) {
|
||||
for (int j = 0; j < st_vozlisc; j++) {
|
||||
if (D[i][j] > D[i][k] + D[k][j]) {
|
||||
D[i][j] = D[i][k] + D[k][j];
|
||||
PI[i][j] = PI[k][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void beri(int **&C, int &st_vozlisc) {
|
||||
int st_povezav;
|
||||
std::ifstream f("graf3.txt");
|
||||
f >> st_vozlisc;
|
||||
f >> st_povezav;
|
||||
int v1, v2, cena;
|
||||
|
||||
C = new int *[st_vozlisc];
|
||||
|
||||
for (int i = 0; i < st_vozlisc; i++) {
|
||||
C[i] = new int[st_vozlisc];
|
||||
}
|
||||
|
||||
for (int i = 0; i < st_vozlisc; i++) {
|
||||
for (int j = 0; j < st_vozlisc; j++) {
|
||||
if (i == j) {
|
||||
C[i][j] = 0;
|
||||
} else {
|
||||
C[i][j] = INT16_MAX; //inf
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < st_povezav; i++) {
|
||||
f >> v1 >> v2 >> cena;
|
||||
C[v1 - 1][v2 - 1] = cena;
|
||||
}
|
||||
std::cout << "Vozlisca: " << st_vozlisc << " Povezave: " << st_povezav << "\n";
|
||||
}
|
||||
|
||||
void izpisPoti(int **&PI, int s, int g) {
|
||||
if (s == g) {
|
||||
std::cout << s << " ";
|
||||
} else {
|
||||
if (PI[s][g] == INT16_MAX) { //inf
|
||||
std::cout << "med " << s << " in " << g << " ni poti";
|
||||
} else {
|
||||
izpisPoti(PI, s, PI[s][g]);
|
||||
std::cout << g << " ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void menu() {
|
||||
std::cout << "Dijkstrov algoritem - izbira:\n"
|
||||
"1 Nalozi graf\n"
|
||||
"2 Zagon algoritma\n"
|
||||
"3 Izpis najkrajse poti\n"
|
||||
"0 Konec\n\n"
|
||||
"Vasa izbira: ";
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
std::cout << "Hello, World!" << std::endl;
|
||||
int **C;
|
||||
int **D;
|
||||
int **PI;
|
||||
int st_vozlisc = 0;
|
||||
bool runing = true;
|
||||
int condition;
|
||||
int s, g;
|
||||
bool func = false;
|
||||
while (runing) {
|
||||
menu();
|
||||
std::cin >> condition;
|
||||
switch (condition) {
|
||||
case 1:
|
||||
beri(C, st_vozlisc);
|
||||
break;
|
||||
case 2:
|
||||
FLOYD_WARSHALL(C, D, PI, st_vozlisc);
|
||||
func = true;
|
||||
break;
|
||||
case 3:
|
||||
if (func) {
|
||||
do {
|
||||
std::cout << "Izberi s:";
|
||||
std::cin >> s;
|
||||
} while (s > st_vozlisc);
|
||||
do {
|
||||
std::cout << "Izberi g:";
|
||||
std::cin >> g;
|
||||
}while(g > st_vozlisc);
|
||||
std::cout << "Pot: ";
|
||||
izpisPoti(PI, s, g);
|
||||
std::cout << "\n Cena: " << D[s][g];
|
||||
std::cout << "\n";
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
runing = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
semester_2/osnove_algoritmov/naloga_5/navodila/Vaja_5.pdf
Normal file
BIN
semester_2/osnove_algoritmov/naloga_5/navodila/Vaja_5.pdf
Normal file
Binary file not shown.
8
semester_2/osnove_algoritmov/naloga_5/navodila/graf1.txt
Normal file
8
semester_2/osnove_algoritmov/naloga_5/navodila/graf1.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
3
|
||||
6
|
||||
1 2 10
|
||||
1 3 4
|
||||
2 3 3
|
||||
2 1 5
|
||||
3 1 8
|
||||
3 2 2
|
8
semester_2/osnove_algoritmov/naloga_5/navodila/graf2.txt
Normal file
8
semester_2/osnove_algoritmov/naloga_5/navodila/graf2.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
4
|
||||
6
|
||||
1 2 8
|
||||
1 4 1
|
||||
2 3 1
|
||||
3 1 4
|
||||
4 2 2
|
||||
4 3 9
|
11
semester_2/osnove_algoritmov/naloga_5/navodila/graf3.txt
Normal file
11
semester_2/osnove_algoritmov/naloga_5/navodila/graf3.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
5
|
||||
9
|
||||
1 2 3
|
||||
1 3 8
|
||||
1 5 -4
|
||||
2 4 1
|
||||
2 5 7
|
||||
3 2 4
|
||||
4 1 2
|
||||
4 3 -5
|
||||
5 4 6
|
Reference in New Issue
Block a user