Skip to content
Snippets Groups Projects
Commit 0782bb70 authored by u214892's avatar u214892
Browse files

Merge branch '169-Enhance_sparse_rail_generator' of...

Merge branch '169-Enhance_sparse_rail_generator' of gitlab.aicrowd.com:flatland/flatland into 163-multispeed-tests-penalties
parents 44b55f20 7f762e82
No related branches found
No related tags found
No related merge requests found
......@@ -24,10 +24,11 @@ def profile(resource, entry):
cProfile.run('my_func()', sort='time')
for entry in [entry for entry in importlib_resources.contents('examples') if
not pkg_resources.resource_isdir('examples', entry)
and entry.endswith(".py")
and '__init__' not in entry
and 'demo.py' not in entry
]:
profile('examples', entry)
if __name__ == '__main__':
for entry in [entry for entry in importlib_resources.contents('examples') if
not pkg_resources.resource_isdir('examples', entry)
and entry.endswith(".py")
and '__init__' not in entry
and 'demo.py' not in entry
]:
profile('examples', entry)
......@@ -8,22 +8,30 @@ from importlib_resources import path
from benchmarks.benchmark_utils import swap_attr
for entry in [entry for entry in importlib_resources.contents('examples') if
not pkg_resources.resource_isdir('examples', entry)
and entry.endswith(".py")
and '__init__' not in entry
and 'demo.py' not in entry
and 'DELETE' not in entry
]:
with path('examples', entry) as file_in:
print("")
print("")
print("")
print("*****************************************************************")
print("Running {}".format(entry))
print("*****************************************************************")
with swap_attr(sys, "stdin", StringIO("q")):
runpy.run_path(file_in, run_name="__main__", init_globals={
'argv': ['--sleep-for-animation=False']
})
# https://stackoverflow.com/questions/715417/converting-from-a-string-to-boolean-in-python
def str2bool(v):
return v.lower() in ("yes", "true", "t", "1")
if __name__ == '__main__':
for entry in [entry for entry in importlib_resources.contents('examples') if
not pkg_resources.resource_isdir('examples', entry)
and entry.endswith(".py")
and '__init__' not in entry
and 'demo.py' not in entry
and 'DELETE' not in entry
]:
with path('examples', entry) as file_in:
print("")
print("")
print("")
print("*****************************************************************")
print("Running {}".format(entry))
print("*****************************************************************")
with swap_attr(sys, "stdin", StringIO("q")):
runpy.run_path(file_in, run_name="__main__", init_globals={
'argv': ['--sleep-for-animation=False']
})
......@@ -5,6 +5,7 @@ import time
import numpy as np
from benchmarks.run_all_examples import str2bool
from flatland.core.grid.grid4_utils import get_new_position
from flatland.envs.observations import TreeObsForRailEnv
from flatland.envs.rail_env import RailEnv
......@@ -51,7 +52,8 @@ class SingleAgentNavigationObs(TreeObsForRailEnv):
for direction in [(agent.direction + i) % 4 for i in range(-1, 2)]:
if possible_transitions[direction]:
new_position = get_new_position(agent.position, direction)
min_distances.append(self.env.distance_map.get()[handle, new_position[0], new_position[1], direction])
min_distances.append(
self.env.distance_map.get()[handle, new_position[0], new_position[1], direction])
else:
min_distances.append(np.inf)
......@@ -70,7 +72,7 @@ def main(args):
sleep_for_animation = True
for o, a in opts:
if o in ("--sleep-for-animation"):
sleep_for_animation = bool(a)
sleep_for_animation = str2bool(a)
else:
assert False, "unhandled option"
......
......@@ -5,6 +5,7 @@ import time
import numpy as np
from benchmarks.run_all_examples import str2bool
from flatland.core.grid.grid_utils import coordinate_to_position
from flatland.envs.observations import TreeObsForRailEnv
from flatland.envs.predictions import ShortestPathPredictorForRailEnv
......@@ -110,7 +111,7 @@ def main(args):
sleep_for_animation = True
for o, a in opts:
if o in ("--sleep-for-animation"):
sleep_for_animation = bool(a)
sleep_for_animation = str2bool(a)
else:
assert False, "unhandled option"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment