-
Notifications
You must be signed in to change notification settings - Fork 0
/
Algorithm_with_multiple_rows
147 lines (135 loc) · 5.67 KB
/
Algorithm_with_multiple_rows
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import json
from typing import List
VOS215 = [1, 2, 13, 15, 16, 19, 28, 78] # list of VOS 215
# list of IoT and YOTA
IoT_YOTA = [251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271]
# functions for excepting: VOS215, IoT_YOTA and 238/228
def for_215(x):
for z in x:
if z == 215:
return True
return False
def search_in_215(x):
for y in x:
if y in VOS215:
return True
return False
def search_in_yota_and_iot(x):
for y in x:
if y in IoT_YOTA:
return True
return False
def for_228_and_238(x):
for tt in x:
if (tt == 228) or (tt == 238):
return True
return False
def search_for_denied(x):
for i in x:
if i == 'denied':
yield False
if i == 'permitted':
yield True
#getting the values from json
with open('file.json', "r") as f:
dic = json.load(f)
branch1 = dic["branch1"]
branch2 = dic["branch2"]
VOS_num1: list = dic["set1"]
VOS_num2: list = dic["set2"]
#Algorithm
result = []
subresult = []
if len(branch1) == len(branch2):
for i in range(len(branch1)):
if branch1[i] == branch2[i]:
result.append('permitted')
elif branch1[i] != branch2[i]:
if VOS_num1[i] and VOS_num2[i]:
VOS1 = []
VOS2 = []
if type(VOS_num1[i]) is not list:
VOS1.append(VOS_num1[i])
else:
VOS1.extend(VOS_num1[i])
if type(VOS_num2[i]) is not list:
VOS2.append(VOS_num2[i])
else:
VOS2.extend(VOS_num2[i])
if len(VOS1) == 1 and len(VOS2) == 1:
if VOS_num1[i] == VOS_num2[i]:
result.append('permitted')
elif VOS_num1[i] == any(VOS215) and VOS_num2[i] == 215:
result.append('permitted')
elif VOS_num1[i] == any(VOS215) and VOS_num2[i] == 215:
result.append('permitted')
elif (VOS_num1[i] in IoT_YOTA) or (VOS_num2[i] in IoT_YOTA):
result.append('permitted')
elif (VOS_num1[i] == 238 or VOS_num1[i] == 228) and (VOS_num2[i] == 238 or VOS_num2[i] == 228):
result.append('permitted')
else:
result.append('denied')
elif len(VOS1) == 1 and len(VOS2)>1:
if VOS_num1[i] in VOS2:
result.append('permitted')
elif VOS_num1[i] == 215 and search_in_215(VOS2):
result.append('permitted')
elif (VOS_num1[i] in VOS215) and for_215(VOS2):
result.append('permitted')
elif (VOS_num1[i] == 228 or VOS_num1[i] == 238) and for_228_and_238(VOS2):
result.append('permitted')
elif (VOS_num1[i] in IoT_YOTA) or search_in_yota_and_iot(VOS2):
result.append('permitted')
else:
result.append('denied')
elif len(VOS2) == 1 and len(VOS1)>1:
if VOS_num2[i] in VOS1:
result.append('permitted')
elif VOS_num2[i] == 215 and search_in_215(VOS1):
result.append('permitted')
elif (VOS_num2[i] in VOS215) and for_215(VOS1):
result.append('permitted')
elif (VOS_num2[i] == 228 or VOS_num2[i] == 238) and for_228_and_238(VOS1):
result.append('permitted')
elif (VOS_num2[i] in IoT_YOTA) or search_in_yota_and_iot(VOS1):
result.append('permitted')
else:
result.append('denied')
elif len(VOS1)>1 and len(VOS2)>1:
for v in VOS1:
if v in VOS2:
subresult.append('permitted')
break
elif (v not in VOS2) and (v in VOS215):
if for_215(VOS2):
subresult.append('permitted')
elif search_in_yota_and_iot(VOS2):
subresult.append('permitted')
else:
subresult.append('denied')
elif (v not in VOS2) and (v == 215):
if search_in_215(VOS2):
subresult.append('permitted')
elif search_in_yota_and_iot(VOS2):
subresult.append('permitted')
else:
subresult.append('denied')
else:
if search_in_yota_and_iot(VOS1) or search_in_yota_and_iot(VOS2):
subresult.append('permitted')
elif for_228_and_238(VOS1) and for_228_and_238(VOS2):
subresult.append('permitted')
else:
subresult.append('denied')
if 'permitted' in subresult:
result.append('permitted')
else:
result.append('denied')
else:
result.append('denied')
if all(list(search_for_denied(result))):
print('permitted')
else:
print('denied')
else:
raise ValueError('There are not enough subnets in a column')