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

#57 first steps importlib_resources

parent 9464e58c
No related branches found
No related tags found
No related merge requests found
...@@ -53,7 +53,7 @@ class Scenario_Generator: ...@@ -53,7 +53,7 @@ class Scenario_Generator:
return env return env
@staticmethod @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), env = RailEnv(width=2 * (1 + number_of_agents),
height=1 + number_of_agents) height=1 + number_of_agents)
...@@ -64,11 +64,8 @@ class Scenario_Generator: ...@@ -64,11 +64,8 @@ class Scenario_Generator:
[filename, [filename,
number_of_agents=number_of_agents) number_of_agents=number_of_agents)
""" """
if os.path.exists(filename): env.load_resource(package, resource)
env.load(filename) env.reset(False, False)
env.reset(False, False)
else:
print("File does not exist:", filename, " Working directory: ", os.getcwd())
return env return env
...@@ -135,45 +132,36 @@ if False: ...@@ -135,45 +132,36 @@ if False:
demo_001.run_demo() demo_001.run_demo()
demo_001 = None demo_001 = None
demo_000 = Demo(Scenario_Generator.load_scenario( demo_000 = Demo(Scenario_Generator.load_scenario('example_network_000.pkl'))
os.path.join(__file_dirname__, '..', 'env-data', 'railway', 'example_network_000.pkl')))
demo_000.run_demo() demo_000.run_demo()
demo_000 = None demo_000 = None
demo_001 = Demo(Scenario_Generator.load_scenario( demo_001 = Demo(Scenario_Generator.load_scenario('example_network_001.pkl'))
os.path.join(__file_dirname__, '..', 'env-data', 'railway', 'example_network_001.pkl')))
demo_001.run_demo() demo_001.run_demo()
demo_001 = None demo_001 = None
demo_002 = Demo(Scenario_Generator.load_scenario( demo_002 = Demo(Scenario_Generator.load_scenario('example_network_002.pkl'))
os.path.join(__file_dirname__, '..', 'env-data', 'railway', 'example_network_002.pkl')))
demo_002.run_demo() demo_002.run_demo()
demo_002 = None demo_002 = None
demo_flatland_000 = Demo( demo_flatland_000 = Demo(Scenario_Generator.load_scenario('example_flatland_000.pkl'))
Scenario_Generator.load_scenario(
os.path.join(__file_dirname__, '..', 'env-data', 'railway', 'example_flatland_000.pkl')))
demo_flatland_000.renderer.resize() demo_flatland_000.renderer.resize()
demo_flatland_000.run_demo(60) demo_flatland_000.run_demo(60)
demo_flatland_000 = None demo_flatland_000 = None
demo_flatland_000 = Demo( demo_flatland_000 = Demo(Scenario_Generator.load_scenario('example_network_003.pkl'))
Scenario_Generator.load_scenario(
os.path.join(__file_dirname__, '..', 'env-data', 'railway', 'example_network_003.pkl')))
demo_flatland_000.renderer.resize() demo_flatland_000.renderer.resize()
demo_flatland_000.set_max_framerate(5) demo_flatland_000.set_max_framerate(5)
demo_flatland_000.run_demo(30) demo_flatland_000.run_demo(30)
demo_flatland_000 = None demo_flatland_000 = None
demo_flatland_000 = Demo( demo_flatland_000 = Demo(Scenario_Generator.load_scenario('example_flatland_001.pkl'))
Scenario_Generator.load_scenario(
os.path.join(__file_dirname__, '..', 'env-data', 'railway', 'example_flatland_001.pkl')))
demo_flatland_000.renderer.resize() demo_flatland_000.renderer.resize()
demo_flatland_000.set_record_frames(os.path.join(__file_dirname__, '..', 'rendering', 'frame_{:04d}.bmp')) demo_flatland_000.set_record_frames(os.path.join(__file_dirname__, '..', 'rendering', 'frame_{:04d}.bmp'))
demo_flatland_000.run_demo(60) demo_flatland_000.run_demo(60)
demo_flatland_000 = None demo_flatland_000 = None
demo_001 = Demo(Scenario_Generator.load_scenario('./env-data/railway/complex_scene.pkl')) demo_001 = Demo(Scenario_Generator.load_scenario('complex_scene.pkl'))
demo_001.set_record_frames('./rendering/frame_{:04d}.bmp') demo_001.set_record_frames(os.path.join(__file_dirname__, '..', 'rendering', 'frame_{:04d}.bmp'))
demo_001.run_demo(360) demo_001.run_demo(360)
demo_001 = None demo_001 = None
...@@ -216,11 +216,11 @@ class RailEnv(Environment): ...@@ -216,11 +216,11 @@ class RailEnv(Environment):
if action == RailEnvActions.DO_NOTHING and agent.moving: if action == RailEnvActions.DO_NOTHING and agent.moving:
# Keep moving # Keep moving
# Changed MOVE_FORWARD to DO_NOTHING # Changed MOVE_FORWARD to DO_NOTHING
#action_dict[iAgent] = RailEnvActions.DO_NOTHING # action_dict[iAgent] = RailEnvActions.DO_NOTHING
action = RailEnvActions.MOVE_FORWARD action = RailEnvActions.MOVE_FORWARD
if action == RailEnvActions.STOP_MOVING and agent.moving: 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 # CHanged DO_NOTHING to STOP_MOVING
# action = RailEnvActions.STOP_MOVING # action = RailEnvActions.STOP_MOVING
agent.moving = False agent.moving = False
...@@ -391,3 +391,8 @@ class RailEnv(Environment): ...@@ -391,3 +391,8 @@ class RailEnv(Environment):
with open(filename, "rb") as file_in: with open(filename, "rb") as file_in:
load_data = file_in.read() load_data = file_in.read()
self.set_full_state_msg(load_data) 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)
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