-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecompose.py
More file actions
75 lines (60 loc) · 1.98 KB
/
Copy pathdecompose.py
File metadata and controls
75 lines (60 loc) · 1.98 KB
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
from classe import *
from algo1 import *
from normalize import *
def schema(fds):
setattr = SetAttr()
for fd in fds:
setattr.update(fd.prerequis,fd.conclusion)
return setattr
def check_key(fds,attr):
return improved(fds,attr).issuperset(schema(fds))
def check_condition(fds,r):
for fd in fds:
closure = improved(fds,fd.prerequis)
for table in r:
if(fd.prerequis.issubset(table)):
if(not fd.conclusion.isdisjoint(table) and not table.issubset(closure)):
return True,table,fd
break
return False,None,None
def check_condition_debug(fds,r):
for fd in fds:
closure = improved(fds,fd.prerequis)
test = False
for table in r:
if(fd.prerequis.issubset(table)):
test = True
if(not fd.conclusion.isdisjoint(table) and not table.issubset(closure)):
return True,table,fd
print(fd,table)
break
return False,None,None
def decompose(fds,u):
new_fds = normalize(fds)
r = set({u})
continuer,table_faux,fd_faux = check_condition(fds,r)
while(continuer):
r.remove(table_faux)
closure = improved(fds,fd_faux.prerequis)
r.add(SetAttr(table_faux.intersection(closure)))
r.add(SetAttr(table_faux.difference(closure).union(fd_faux.prerequis)))
continuer,table_faux,fd_faux = check_condition(fds,r)
# check_condition_debug(fds,r)
return r
"""s = SetAttr("ABC")
s1 = SetAttr("AB")
s2 = SetAttr("AC")
s3 = SetAttr("A")
s4 = SetAttr("B")
s5 = SetAttr("C")
s6 = SetAttr("D")
s7 = SetAttr("BDE")
s8 = SetAttr("BC")
s9 = SetAttr("BE")
fds = [FD(s4,s5),FD(s3,s1),FD(s5,s6),FD(s7,s3),FD(s8,s9)]
print(schema(fds))
print(check_key(fds,SetAttr("B")))
print(check_key(fds,SetAttr("A")))
print(check_key(fds,SetAttr("E")))
print(decompose(fds,schema(fds)))"""
# print(decompose(generate(40),schema(generate(40))))