-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting.py
More file actions
78 lines (55 loc) · 1.79 KB
/
Copy pathtesting.py
File metadata and controls
78 lines (55 loc) · 1.79 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
import sys
import os
old_stdout = sys.stdout
sys.stdout = open(os.devnull, "w")
old_stderr = sys.stderr
sys.stderr = open(os.devnull, "w")
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
import random
import gym
import engine.envs.engineEnv
import time
import random
import engine.choices as choices
from engine.virus import Virus
import numpy as np
from collections import deque
import parameters as param
import engine.envs.render as render
from training import DQNSolver
sys.stdout = old_stdout
sys.stderr = old_stderr
def simulation():
env = gym.make(param.ENV_NAME)
virus = Virus(range = param.VIRUS_RANGE, pInfection = param.VIRUS_P_INFECTION, severity = param.VIRUS_SEVERITY, lethality = param.VIRUS_LETHALITY)
env.initialize(virus = virus, nHouses = param.N_HOUSES)
dqn_solver = DQNSolver(False)
dqn_solver.read_model()
observation_space = env.observation_space.shape[0]
action_space = env.action_space.n
curr_state = env.reset()
state = deque()
for k in range(param.STATUS_WINDOW):
state.append(curr_state)
# end for
step = 0
acc_reward = 0
while True:
step += 1
env.render()
array_state = np.reshape(list(state), (1, param.STATUS_WINDOW, observation_space))
action = dqn_solver.act(array_state)
print (action)
curr_state_next, reward, terminal, info = env.step(action)
sys.stdout.write("\rStep: " + str(step) + ", Reward: " + str(reward))
sys.stdout.flush()
state_next = state.copy()
state_next.popleft()
state_next.append(curr_state_next)
acc_reward += reward
state = state_next
if terminal:
print("\nTerminated with score: " + str(acc_reward / step))
break
if __name__ == "__main__":
simulation()