-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce route completion for PG map (#638)
* up * finish * finish * add doc * fix
- Loading branch information
1 parent
a369fd1
commit ffdb1e7
Showing
4 changed files
with
136 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
metadrive/tests/test_functionality/test_route_completion.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from metadrive.envs import MetaDriveEnv | ||
|
||
from metadrive.policy.idm_policy import IDMPolicy | ||
from metadrive.utils import setup_logger | ||
|
||
|
||
def test_route_completion_easy(): | ||
""" | ||
Use an easy map to test whether the route completion is computed correctly. | ||
""" | ||
# In easy map | ||
config = {} | ||
config["map"] = "SSS" | ||
config["traffic_density"] = 0 | ||
try: | ||
env = MetaDriveEnv(config=config) | ||
o, i = env.reset() | ||
assert "route_completion" in i | ||
rc = env.vehicle.navigation.route_completion | ||
epr = 0 | ||
for _ in range(1000): | ||
o, r, tm, tc, i = env.step([0, 1]) | ||
epr += r | ||
env.render(mode="topdown") | ||
if tm or tc: | ||
epr = 0 | ||
break | ||
assert "route_completion" in i | ||
print(i["route_completion"]) | ||
assert i["route_completion"] > 0.95 | ||
finally: | ||
if "env" in locals(): | ||
env.close() | ||
|
||
|
||
def test_route_completion_hard(): | ||
""" | ||
Use a hard map to test whether the route completion is computed correctly. | ||
""" | ||
# In hard map | ||
config = {} | ||
config["map"] = "SCXTO" | ||
config["agent_policy"] = IDMPolicy | ||
config["traffic_density"] = 0 | ||
try: | ||
env = MetaDriveEnv(config=config) | ||
o, i = env.reset() | ||
assert "route_completion" in i | ||
rc = env.vehicle.navigation.route_completion | ||
epr = 0 | ||
for _ in range(1000): | ||
o, r, tm, tc, i = env.step([0, 0]) | ||
epr += r | ||
env.render(mode="topdown") | ||
if tm or tc: | ||
epr = 0 | ||
break | ||
assert "route_completion" in i | ||
print(i["route_completion"], i) | ||
assert i["route_completion"] > 0.8 # The vehicle will not reach destination due to randomness in IDM. | ||
finally: | ||
if "env" in locals(): | ||
env.close() | ||
|
||
|
||
if __name__ == '__main__': | ||
setup_logger(True) | ||
test_route_completion_hard() |