-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_env.py
90 lines (79 loc) · 2.24 KB
/
test_env.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
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
"""Unit tester for the SimpleHighwayRamp environment model."""
from simple_highway_with_ramp import SimpleHighwayRamp
from simple_highway_ramp_wrapper import SimpleHighwayRampWrapper
config = {"debug": 0}
# Case 1 - reset the env
print("\n+++++ Begin case 1")
env = SimpleHighwayRamp(config)
obs = env.reset()
print("Case 1: reset obs = ", obs)
# Case 2 - step with invalid accel command
print("\n+++++ Begin case 2")
action = [-5.4, 0.0]
try:
env.step(action)
except Exception as e:
print("Caught exception: ", e)
# Case 3 - step with invalid lane change command
print("\n+++++ Begin case 3")
action = [0.2, 2.0]
try:
env.step(action)
except Exception as e:
print("Caught exception: ", e)
# Case 4 - step with positive accel, tiny steering command
print("\n+++++ Begin case 4")
action = [0.83, -0.19]
try:
env.step(action)
except Exception as e:
print("Caught exception: ", e)
# Case 5 - another step with positive accel, tiny steering command
print("\n+++++ Begin case 5")
action = [0.98, 0.48]
try:
env.step(action)
except Exception as e:
print("Caught exception: ", e)
# Case 6 - v0 makes illegal lane change
print("\n+++++ Begin case 6")
action = [0.0, -0.51]
try:
env.step(action)
except Exception as e:
print("Caught exception: ", e)
# Case 7 - collision between v0 and v1 in adjacent lanes
print("\n+++++ Begin case 7")
action = [0.0, -1.0]
env.vehicles[0].dist_downtrack = 481.0
env.vehicles[0].speed = 23.4
env.vehicles[1].dist_downtrack = 802.0
env.vehicles[1].speed = 22.0
try:
env.step(action)
except Exception as e:
print("Caught exception: ", e)
# Case 8 - collision between v2 and v1 in same lane
print("\n+++++ Begin case 8")
env.reset()
action = [0.0, 0.0]
env.vehicles[1].dist_downtrack = 55.0
env.vehicles[1].speed = 22.0
env.vehicles[2].dist_downtrack = 49.0
env.vehicles[2].speed = 24.4
try:
env.step(action)
except Exception as e:
print("Caught exception: ", e)
# Case 9 - exercise the env wrapper
print("\n+++++ Begin case 9")
env = SimpleHighwayRampWrapper(config)
env.reset()
action = [0.976, 0.98] #from a hypothetical NN
try:
env.step(action)
print("+++++ step 1 complete.")
env.step(action)
print("+++++ step 2 complete.")
except Exception as e:
print("Caught exception: ", e)