diff --git a/env-data/__init__.py b/env-data/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/env-data/railway/__init__.py b/env-data/railway/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/examples/demo.py b/examples/demo.py index 933a9b1f5e00906f46e3800b2014e3d4aba60147..db28717c2f348489a774a2be5a4f5697d9000213 100644 --- a/examples/demo.py +++ b/examples/demo.py @@ -53,7 +53,7 @@ class Scenario_Generator: return env @staticmethod - def load_scenario(filename, number_of_agents=3): + def load_scenario(resource, package='env-data.railway', number_of_agents=3): env = RailEnv(width=2 * (1 + number_of_agents), height=1 + number_of_agents) @@ -64,11 +64,8 @@ class Scenario_Generator: [filename, number_of_agents=number_of_agents) """ - if os.path.exists(filename): - env.load(filename) - env.reset(False, False) - else: - print("File does not exist:", filename, " Working directory: ", os.getcwd()) + env.load_resource(package, resource) + env.reset(False, False) return env @@ -135,45 +132,36 @@ if False: demo_001.run_demo() demo_001 = None - demo_000 = Demo(Scenario_Generator.load_scenario( - os.path.join(__file_dirname__, '..', 'env-data', 'railway', 'example_network_000.pkl'))) + demo_000 = Demo(Scenario_Generator.load_scenario('example_network_000.pkl')) demo_000.run_demo() demo_000 = None - demo_001 = Demo(Scenario_Generator.load_scenario( - os.path.join(__file_dirname__, '..', 'env-data', 'railway', 'example_network_001.pkl'))) + demo_001 = Demo(Scenario_Generator.load_scenario('example_network_001.pkl')) demo_001.run_demo() demo_001 = None - demo_002 = Demo(Scenario_Generator.load_scenario( - os.path.join(__file_dirname__, '..', 'env-data', 'railway', 'example_network_002.pkl'))) + demo_002 = Demo(Scenario_Generator.load_scenario('example_network_002.pkl')) demo_002.run_demo() demo_002 = None - demo_flatland_000 = Demo( - Scenario_Generator.load_scenario( - os.path.join(__file_dirname__, '..', 'env-data', 'railway', 'example_flatland_000.pkl'))) + demo_flatland_000 = Demo(Scenario_Generator.load_scenario('example_flatland_000.pkl')) demo_flatland_000.renderer.resize() demo_flatland_000.run_demo(60) demo_flatland_000 = None - demo_flatland_000 = Demo( - Scenario_Generator.load_scenario( - os.path.join(__file_dirname__, '..', 'env-data', 'railway', 'example_network_003.pkl'))) + demo_flatland_000 = Demo(Scenario_Generator.load_scenario('example_network_003.pkl')) demo_flatland_000.renderer.resize() demo_flatland_000.set_max_framerate(5) demo_flatland_000.run_demo(30) demo_flatland_000 = None - demo_flatland_000 = Demo( - Scenario_Generator.load_scenario( - os.path.join(__file_dirname__, '..', 'env-data', 'railway', 'example_flatland_001.pkl'))) + demo_flatland_000 = Demo(Scenario_Generator.load_scenario('example_flatland_001.pkl')) demo_flatland_000.renderer.resize() demo_flatland_000.set_record_frames(os.path.join(__file_dirname__, '..', 'rendering', 'frame_{:04d}.bmp')) demo_flatland_000.run_demo(60) demo_flatland_000 = None -demo_001 = Demo(Scenario_Generator.load_scenario('./env-data/railway/complex_scene.pkl')) -demo_001.set_record_frames('./rendering/frame_{:04d}.bmp') +demo_001 = Demo(Scenario_Generator.load_scenario('complex_scene.pkl')) +demo_001.set_record_frames(os.path.join(__file_dirname__, '..', 'rendering', 'frame_{:04d}.bmp')) demo_001.run_demo(360) demo_001 = None diff --git a/flatland/envs/rail_env.py b/flatland/envs/rail_env.py index 8a2bcf49ff2301cb47ff74acada59ca5b8ccbef8..c8551b6ec4c18d5e15bb42ff9a0eef1dc1e791e9 100644 --- a/flatland/envs/rail_env.py +++ b/flatland/envs/rail_env.py @@ -216,11 +216,11 @@ class RailEnv(Environment): if action == RailEnvActions.DO_NOTHING and agent.moving: # Keep moving # Changed MOVE_FORWARD to DO_NOTHING - #action_dict[iAgent] = RailEnvActions.DO_NOTHING + # action_dict[iAgent] = RailEnvActions.DO_NOTHING action = RailEnvActions.MOVE_FORWARD if action == RailEnvActions.STOP_MOVING and agent.moving: - #action_dict[iAgent] = RailEnvActions.DO_NOTHING + # action_dict[iAgent] = RailEnvActions.DO_NOTHING # CHanged DO_NOTHING to STOP_MOVING # action = RailEnvActions.STOP_MOVING agent.moving = False @@ -391,3 +391,8 @@ class RailEnv(Environment): with open(filename, "rb") as file_in: load_data = file_in.read() self.set_full_state_msg(load_data) + + def load_resource(self, package, resource): + from importlib_resources import read_binary + load_data = read_binary(package, resource) + self.set_full_state_msg(load_data)