Commit d70f2642 authored by u214892's avatar u214892
Browse files

#57 first steps importlib_resources

parent 9464e58c
Pipeline #972 failed with stage
in 7 minutes and 58 seconds
......@@ -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
......@@ -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)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment