-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathother_func.cpp
110 lines (100 loc) · 2.74 KB
/
other_func.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "other_func.h"
#include "city.h"
#include <iostream>
using namespace std;
int min(int i, int j) {
if (i < j)
return i;
else if (i > j)
return j;
else
return i;
}
int max(int i, int j) {
if (i > j)
return i;
else if (i < j)
return j;
else
return i;
}
void print_path(City* cities, int n) {
int i = 1;
while(cities[i].next_city != n) {
cout << cities[i].next_city << "\n";
i = cities[i].next_city;
}
}
void print_path(MatrixItem** matrix, int j, int n) {
int index = 1;
while(matrix[j][index].next_city != n && matrix[j][index].next_city != 0) {
cout << matrix[j][index].next_city << "\n";
index = matrix[j][index].next_city;
}
}
void print_matrix_M(MatrixItem** matrix, int j, int i) {
cout << "Matrix M values:\n";
for (int m = 0; m < j; m++) {
cout << m << " - [";
for (int n = 0; n < i; n++) {
if (matrix[m][n].M == INF) {
//cout << "(M:I,s:" << matrix[m][n].stays;
//cout << ",nc:" << matrix[m][n].next_city << ",u?:" << matrix[m][n].unique << ")";
cout << "I ";
} else {
//cout << "(M:" << matrix[m][n].M << ",s:" << matrix[m][n].stays;
//cout << ",nc:" << matrix[m][n].next_city << ",u?:" << matrix[m][n].unique << ")";
cout << matrix[m][n].M << " ";
}
}
cout << "]\n";
}
}
void print_matrix_s(MatrixItem** matrix, int j, int i) {
cout << "Matrix stays:\n";
for (int m = 0; m < j; m++) {
cout << m << " - [";
for (int n = 0; n < i; n++) {
cout << matrix[m][n].stays << " ";
}
cout << "]\n";
}
}
void print_matrix_n(MatrixItem** matrix, int j, int i) {
cout << "Matrix next cities:\n";
for (int m = 0; m < j; m++) {
cout << m << " - [";
for (int n = 0; n < i; n++) {
cout << matrix[m][n].next_city << " ";
}
cout << "]\n";
}
}
void print_matrix_u(MatrixItem** matrix, int j, int i) {
cout << "Matrix unique? values:\n";
for (int m = 0; m < j; m++) {
cout << m << " - [";
for (int n = 0; n < i; n++) {
cout << matrix[m][n].unique << " ";
}
cout << "]\n";
}
}
int path_unique(City* cities, int n) {
int i = 1;
while(cities[i].next_city != n) {
if (cities[i].unique == 0)
return 0;
i = cities[i].next_city;
}
return 1;
}
int path_unique(MatrixItem** matrix, int j, int n) {
int index = 1;
while(matrix[j][index].next_city != n) {
if (matrix[j][index].unique == 0)
return 0;
index = matrix[j][index].next_city;
}
return 1;
}