-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_random_agent.py
48 lines (36 loc) · 1.33 KB
/
test_random_agent.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
from main_setting import Params
from environment.uav_collection.env import Env
from environment.uav_collection.log import Log
from environment.uav_collection.env_setting import Setting
import numpy as np
import time
import os
params = Params()
sg = Setting()
if params.trainable is True:
print("please set params.trainable is False!!!")
exit(0)
local_time = str(time.strftime("%Y %m-%d %H-%M-%S", time.localtime()))
env = Env(Log(0, params.max_time_steps, params.root_path, local_time))
# log.log(ARGUMENTS)
start_env = env.reset()
print(env.action_space)
print('Starting a new TEST iterations...')
print('Log_dir:', env.log_dir)
iteration = 0
time_step = 0
while iteration < params.max_test_episode:
action_n = np.array([[np.random.uniform(low=-1,high=1)*sg.V['MAP_X'],
np.random.uniform(low=-1,high=1)*sg.V['MAP_Y'],
np.random.uniform(low=0,high=1)]
for _ in range(env.sg.V["NUM_UAV"])])
ob, r, d, _, _, _,_ = env.step(action=action_n, current_step=time_step)
time_step += 1
terminal = (time_step >= params.max_time_steps)
# env.log.draw_path(env, iteration)
if d or terminal:
print('\n%d th episode:\n' % iteration)
env.log.draw_path(env, iteration)
iteration += 1
time_step = 0
obs_n = env.reset()