/
generator.py
64 lines (50 loc) · 1.13 KB
/
generator.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
# -*- coding: utf-8 -*-
"""
Generate input for all the algorithms
"""
from config import CFG
from random import randint
from math import sqrt, ceil
def generate():
c = []
T = []
t = []
n = CFG['N']
m = CFG['M']
E = CFG['E']
P = CFG['P']
a = CFG['a']
b = CFG['b']
for i in xrange(n):
c.append(randint(*CFG['c']))
T.append(randint(*CFG['T']))
temp = []
for j in xrange(m):
bound = int(ceil(float(b ** 2 * E) / (a * P)))
l, r = CFG['t']
l += bound
r += bound
temp.append(randint(l, r))
t.append(temp)
f = get_f_list(t)
return (c, T, t, f)
def get_f_list(t):
n = CFG['N']
m = CFG['M']
E = CFG['E']
P = CFG['P']
a = CFG['a']
b = CFG['b']
d = []
for i in xrange(n):
temp = []
for j in xrange(m):
temp.append(sqrt(float(t[i][j] * a * P) / E) - b)
d.append(temp)
f = []
for i in xrange(n):
temp = []
for j in xrange(m):
temp.append(((d[i][j] + b) ** 2 / a - 1) * E)
f.append(temp)
return f