-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacierz.py
101 lines (83 loc) · 2.36 KB
/
macierz.py
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
import generowanie
def nastepniki(n,tab,nast):
for i in range(n):
pom = []
for j in range(n):
if tab[i][j]==1:
pom.append(j)
nast.append(pom)
def poprzedniki(n,tab,pop):
for i in range(n):
pom = []
for j in range(n):
if tab[j][i] == 1:
pom.append(j)
pop.append(pom)
def incydencji(n,nast,pop,incy):
for i in range(n):
pom=[]
for j in range(n):
if ((j not in nast[i]) and (j not in pop[i])):
pom.append(j)
incy.append(pom)
def macierz(n,nast,pop,incy,macie,npb):
for i in range(n):
pom = []
for j in range(n):
pom.append(0)
macie.append(pom)
for i in range(n):
pom = []
for j in range(3):
pom.append(0)
npb.append(pom)
for i in range(n):
if len(nast[i])==0:
npb[i][0] = -1
elif len(nast[i])==1:
npb[i][0]=nast[i][0]
macie[i][nast[i][0]]=nast[i][0]
elif len(nast[i])!=0:
npb[i][0]=nast[i][0]
for j in range(len(nast[i])-1):
macie[i][nast[i][j]]=nast[i][j+1]
macie[i][nast[i][j+1]] = nast[i][j+1]
if len(pop[i]) == 0:
npb[i][1] = -1
elif len(pop[i]) == 1:
npb[i][1] = pop[i][0]
macie[i][pop[i][0]] = pop[i][0]*(-1)
elif len(pop[i]) != 0:
npb[i][1] = pop[i][0]
for j in range(len(pop[i]) - 1):
macie[i][pop[i][j]] = pop[i][j + 1]*(-1)
macie[i][pop[i][j + 1]] = pop[i][j + 1]*(-1)
if len(incy)==0:
npb[i][2]= -1
if len(incy[i]) == 1:
npb[i][2] = incy[i][0]
macie[i][incy[i][0]] = incy[i][0]+n
elif len(incy[i]) != 0:
npb[i][2] = incy[i][0]
for j in range(len(incy[i]) - 1):
macie[i][incy[i][j]] = incy[i][j + 1]+n
macie[i][incy[i][j + 1]] = incy[i][j + 1]+n
if __name__ == "__main__":
n=5
tab=[]
generowanie.generate(n,tab)
print(tab)
nast = []
nastepniki(n, tab, nast)
print(nast)
pop=[]
poprzedniki(n,tab,pop)
print(pop)
incy=[]
incydencji(n,nast,pop,incy)
print(incy)
macie=[]
npb=[]
macierz(n,nast,pop,incy,macie,npb)
print(macie)
print(npb)