forked from kapilvaidya24/QueryOptimisation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_gen_star.py
173 lines (109 loc) · 2.32 KB
/
query_gen_star.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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import sys
import random
import math
# relation size prob.
# 10-100 15%
# 100-1,000 30%
# 1,000-10,000 25%
# 10,000-100,000 20%
# domain size prob.
# 2-10 5%
# 10-100 50%
# 100-500 35%
# 500-1,000 15%
def fsize():
t=random.randint(1,101)
if(t<16):
return (random.randint(0,90)+10)*100
if(t<46):
return (random.randint(0,900)+100)*100
if(t<71):
return (random.randint(0,9000)+1000)*100
return (random.randint(0,90000)+10000)*100
def dsize():
t=random.randint(1,101)
if(t<6):
return (random.randint(0,8)+2)*100
if(t<56):
return (random.randint(0,90)+10)*100
if(t<91):
return (random.randint(0,400)+100)*100
return (random.randint(0,500)+500)*100
n=1
s=1
if(len(sys.argv)<3):
print("please give seed and size of star query as input")
else:
s=int(sys.argv[1])
n=int(sys.argv[2])
random.seed(s)
centre_size=fsize()
temp=[]
attr_num=n-1
for j in range(0,attr_num):
temp.append(dsize())
centre_dom_size=temp
size_list=[]
sel_list=[]
dom_list=[]
for i in range(0,n-1):
size_list.append(fsize())
attr_num=random.randint(1,11)
temp=[]
for j in range(0,attr_num):
temp.append(dsize())
dom_list.append(temp)
for i in range(0,n-1):
temp=0.00
k=len(centre_dom_size)
attr_ind=i
temp=float(centre_dom_size[attr_ind])
k=len(dom_list[i])
attr_ind=random.randint(0,k-1)
if(temp<float(dom_list[i][attr_ind])):
temp=float(dom_list[i][attr_ind])
sel_list.append(float(1/temp))
t=float(centre_size)
alpha=1.0
for i in range(0,n-1):
t=t*float(size_list[i])
t=t*float(sel_list[i])
# print(str(t)+" is value of t")
if(t<1000000 or t>1000000000):
t=t/10000000
alpha=math.log(t,2)
alpha=alpha/len(sel_list)
alpha=math.pow(2,alpha)
# print(str(alpha)+" is alpha")
for i in range(len(sel_list)):
# print(sel_list[i-1])
sel_list[i]=sel_list[i]/alpha
# print(sel_list[i-1])
print(n)
print(n-1)
for i in range(1,n):
s="1"
for j in range(1,n):
s=s+"0"
print(s)
s="0"
for j in range(1,i):
s+="0"
s+="1"
for j in range(i,n-1):
s+="0"
print(s)
print(sel_list[i-1])
print(centre_size);
print(len(centre_dom_size));
for i in range(1,n):
print(size_list[i-1])
print(len(dom_list[i-1]))
# print(centre_size)
# for i in range(0,n-1):
# print(size_list[i])
# t=float(centre_size)
# for i in range(0,n-1):
# t=t*float(size_list[i])
# t=t*float(sel_list[i])
# print(t)