-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.py
More file actions
127 lines (113 loc) · 3.22 KB
/
test.py
File metadata and controls
127 lines (113 loc) · 3.22 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
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
import json
import random
import requests
import time
N = 35
W = 80
M = 200
weights = [[random.randint(0, 256) for _ in range(W)] for _ in range(N)]
mapping = {f"Airline {n}": [n] for n in range(M)}
configs = []
decoder = json.JSONDecoder()
for _ in range(M):
config = list(range(W))
random.shuffle(config)
configs.append(config[:N])
print("\tGet Status")
print(requests.get("http://127.0.0.1:80/status"))
# print("\tPut Session")
# r1 = requests.put("http://127.0.0.1:80/sessionClear", json={'weights': weights, 'mapping': {}})
# print(r1)
print("\tEncode Weights")
r0 = requests.put("http://127.0.0.1:88/", json=weights)
print(r0)
encoded = decoder.decode(r0.content.decode())
print("\tInstall Encoded Weights")
r1 = requests.put("http://127.0.0.1:80/sessionSecret", json={'mapping': mapping, 'weights': encoded})
print(r1)
print("\tCompute Fitness Clear")
t1 = time.time()
r2 = requests.put("http://127.0.0.1:80/computeFitnessClear", json=configs)
t2 = time.time()
print(r2)
print(f"time: {t2 - t1:.2f}s")
res2 = [sum([weights[i][j] for i, j in enumerate(c)]) for c in configs]
if res2 == r2.json():
print("OK")
else:
print(res2)
print(r2.json())
print("\tCompute Population Order")
t1 = time.time()
r3 = requests.put("http://127.0.0.1:80/computePopulationOrder", json=configs)
t2 = time.time()
print(r3)
print(f"time: {t2 - t1:.2f}s")
res3 = list(enumerate(res2))
res3.sort(key=(lambda x: x[1]))
res3 = [x[0] for x in res3]
if r3.json() == {'maximum': max(res2), 'order': res3}:
print("OK")
else:
print(max(res2), res3)
print(r3.json())
print("\tCompute Classification")
t1 = time.time()
r4 = requests.put("http://127.0.0.1:80/computeClassification/75", json=configs)
t2 = time.time()
print(r4)
print(f"time: {t2 - t1:.2f}s")
ma = max(res2)
mi = min(res2)
span = ma - mi
thresh = ma - (span // 4)
res4 = [i for i, x in enumerate(res2) if x >= thresh]
if r4.json() == {'highest': ma, 'best': False, 'indices': res4}:
print("OK")
else:
print(res4)
print(r4.json())
print("\tCompute Exact Solution")
t1 = time.time()
r5 = requests.put("http://127.0.0.1:80/computeExact", json=configs)
t2 = time.time()
print(r5)
print(f"time: {t2 - t1:.2f}s")
print("\tCompute 5 Buckets")
t1 = time.time()
r6 = requests.put("http://127.0.0.1:80/computeBuckets/5", json=configs)
t2 = time.time()
print(r6)
print(f"time: {t2 - t1:.2f}s")
res6 = [((r - mi) * 5) // (span + 1) for r in res2]
if r6.json() == {'maximum': ma, 'mapping': res6}:
print("OK")
else:
print(res6)
print(r6.json())
print("\tCompute 5 Quantiles")
t1 = time.time()
r7 = requests.put("http://127.0.0.1:80/computeQuantiles/5", json=configs)
t2 = time.time()
print(r7)
print(f"time: {t2 - t1:.2f}s")
res7 = [(x, (i*5) // M) for i, x in enumerate(res3)]
res7.sort(key=(lambda x: x[0]))
res7 = [x[1] for x in res7]
if r7.json() == {'maximum': ma, 'mapping': res7}:
print("OK")
else:
print(res7)
print(r7.json())
print("\tCompute 10 Top Individuals")
t1 = time.time()
r8 = requests.put("http://127.0.0.1:80/computeTopIndividuals/10", json=configs)
t2 = time.time()
print(r8)
print(f"time: {t2 - t1:.2f}s")
res8 = sorted(res3[-10:])
if r8.json() == {'highest': max(res2), 'best': False, 'indices': res8}:
print("OK")
else:
print(res8)
print(r8.json())