forked from kapilvaidya24/QueryOptimisation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_gen_clique.py
205 lines (128 loc) · 2.66 KB
/
query_gen_clique.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
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 chain query as input")
else:
s=int(sys.argv[1])
n=int(sys.argv[2])
random.seed(s)
size_list=[]
sel_list=[]
dom_list=[]
for i in range(0,n):
size_list.append(fsize())
attr_num=random.randint(n+1,n+11)
temp=[]
for j in range(0,attr_num):
temp.append(dsize())
dom_list.append(temp)
for i in range(0,n):
for j in range(0,n):
if i>=j:
continue
temp=0.00
k=len(dom_list[j])
attr_ind=random.randint(0,k-1)
temp=float(dom_list[j][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)*4000)
alpha=1.0
t=1.0
for i in range(0,n):
t=t*float(size_list[i])
if i<len(sel_list):
t=t*float(sel_list[i])
for i in range(0,len(sel_list)):
if i<n:
continue
t=t*float(sel_list[i])
# print(str(t)+" is value of t")
if(t<1000000 or t>1000000000):
if t <= 0:
print "t is 0"
t=t/10000000
# t=1/t
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])
t=1.0
for i in range(0,n):
t=t*float(size_list[i])
if i<len(sel_list):
t=t*float(sel_list[i])
for i in range(0,len(sel_list)):
if i<n:
continue
t=t*float(sel_list[i])
# print(str(t)+" is value of t")
print(n)
print((n*(n-1))/2)
t=0;
for i in range(1,n):
s1=""
for j in range(1,i):
s1+="0"
s1+="1"
for j in range(i,n):
s1+="0"
for j in range(i,n):
print(s1)
s="0"
for k in range(1,j):
s+="0"
s+="1"
for k in range(j,n-1):
s+="0"
print(s)
print(sel_list[t])
t+=1
for i in range(1,n+1):
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)