-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFinal_partition.py
74 lines (60 loc) · 1.88 KB
/
Final_partition.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
import algo
import math
QA_matrix = algo.query_access_matrix # Query access matrix
sum_attr_access = algo.sum_attr_access # Sum of accesses by the query applications
order_CA = algo.mat[0][1:]
print(order_CA)
no_of_queries = algo.no_of_queries
def sum_access(arr):
sum = 0
for items in arr:
sum = sum + sum_attr_access[items - 1]
return sum
def partition():
z = []
fragments = []
for split_point in range(1, len(order_CA)):
frag1 = order_CA[0:split_point]
frag2 = order_CA[split_point:len(order_CA)]
fragments.append([frag1, frag2])
print("Fragments =", frag1, frag2)
TA = [] #
TB = []
for i in range(no_of_queries):
use_frag1 = 0
for items in frag1:
if QA_matrix[i, items - 1] == 1:
use_frag1 = 1
break
TA.append(use_frag1)
use_frag2 = 0
for items in frag2:
if QA_matrix[i, items - 1] == 1:
use_frag2 = 1
break
TB.append(use_frag2)
print("\t","TA =", TA)
print("\t","TB =", TB)
TQ = []
BQ = []
OQ = []
for i in range(no_of_queries):
if TA[i] == 0 and TB[i] == 1:
BQ.append(i + 1)
elif TA[i] == 1 and TB[i] == 0:
TQ.append(i + 1)
else:
OQ.append(i + 1)
print("\t","TQ =", TQ)
print("\t","BQ =", BQ)
print("\t","OQ =", OQ)
CTQ = sum_access(TQ)
CBQ = sum_access(BQ)
COQ = sum_access(OQ)
z.append(CTQ * CBQ - math.pow(COQ, 2))
print("\t","z =", z)
if max(z) < 0:
print("Vertical Fragmentation not possible.")
else:
print("Best partition = ", fragments[z.index(max(z))][0], fragments[z.index(max(z))][1])
partition()