-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathrandom_tester.py
55 lines (40 loc) · 1.65 KB
/
random_tester.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
import numpy as np
from service_batch_generator import *
from environment import *
from config import *
if __name__ == "__main__":
""" Configuration """
config, _ = get_config()
""" Environment """
env = Environment(config.num_cpus, config.num_vnfd)
""" Network service generator """
vocab_size = config.num_vnfd + 1
networkServices = ServiceBatchGenerator(1, config.min_length, config.max_length, vocab_size)
# New batch of states
networkServices.getNewState()
placement = [0] * networkServices.service_length[0]
try:
e = 1
goals = 0
while True:
for i in range(networkServices.service_length[0]):
cpuID = np.random.randint(0, config.num_cpus-1, dtype='int32')
placement[i] = cpuID
""" Place in the environment """
env.clear()
env.step(networkServices.service_length[0], networkServices.state[0], placement)
reward = env.reward
if env.invalid_placement == False and env.invalid_bandwidth == False and env.invalid_latency == False:
goals += 1
if e == 0 or e % 1000 == 0:
print("\n-------------")
print("Episode: ", e)
print("NS: ", networkServices.state[0])
print("Placement: ", placement)
print("Goals: ", goals)
print("Invalid placement:", env.invalid_placement)
print("Invalid bandwidth:", env.invalid_bandwidth)
print("Invalid latency:", env.invalid_latency)
e += 1
except KeyboardInterrupt:
print("Interrupted by user.")