Skip to content
Snippets Groups Projects
Commit 6fb36086 authored by Egli Adrian (IT-SCI-API-PFI)'s avatar Egli Adrian (IT-SCI-API-PFI)
Browse files
parents 4cef4743 b08c9aae
No related branches found
No related tags found
No related merge requests found
Showing
with 89 additions and 88 deletions
......@@ -9,7 +9,11 @@ Development
* G Spigler <giacomo.spigler@gmail.com>
* A Egli <adrian.egli@sbb.ch>
* A Egli <adrian.egli@sbb.ch>
* E Nygren <erik.nygren@sbb.ch>
* Ch. Eichenberger <christian.markus.eichenberger@sbb.ch>
* Mattias Ljungström
......
......@@ -4,11 +4,12 @@ include HISTORY.rst
include LICENSE
include README.rst
include requirements_dev.txt
include requirements_continuous_integration.txt
graft svg
graft env-data
graft env_data
recursive-include tests *
......
......@@ -17,3 +17,19 @@ Frequently Asked Questions (FAQs)
export LC_ALL=en_US.utf-8
export LANG=en_US.utf-8
- We use `importlib-resources`_ to read from local files.
Sample usages:
.. code-block:: python
from importlib_resources import path
with path(package, resource) as file_in:
new_grid = np.load(file_in)
.. code-block:: python
from importlib_resources import read_binary
load_data = read_binary(package, resource)
self.set_full_state_msg(load_data)
.. _importlib-resources: https://importlib-resources.readthedocs.io/en/latest/
File moved
File moved
......@@ -53,22 +53,11 @@ 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)
"""
env = RailEnv(width=20,
height=20,
rail_generator=rail_from_list_of_saved_GridTransitionMap_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
......@@ -125,55 +114,57 @@ class Demo:
self.renderer.close_window()
@staticmethod
def run_generate_random_scenario():
demo_000 = Demo(Scenario_Generator.generate_random_scenario())
demo_000.run_demo()
@staticmethod
def run_generate_complex_scenario():
demo_001 = Demo(Scenario_Generator.generate_complex_scenario())
demo_001.run_demo()
@staticmethod
def run_example_network_000():
demo_000 = Demo(Scenario_Generator.load_scenario('example_network_000.pkl'))
demo_000.run_demo()
@staticmethod
def run_example_network_001():
demo_001 = Demo(Scenario_Generator.load_scenario('example_network_001.pkl'))
demo_001.run_demo()
@staticmethod
def run_example_network_002():
demo_002 = Demo(Scenario_Generator.load_scenario('example_network_002.pkl'))
demo_002.run_demo()
@staticmethod
def run_example_network_003():
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)
@staticmethod
def run_example_flatland_000():
demo_flatland_000 = Demo(Scenario_Generator.load_scenario('example_flatland_000.pkl'))
demo_flatland_000.renderer.resize()
demo_flatland_000.run_demo(60)
@staticmethod
def run_example_flatland_001():
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)
@staticmethod
def run_complex_scene():
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)
if False:
demo_000 = Demo(Scenario_Generator.generate_random_scenario())
demo_000.run_demo()
demo_000 = None
demo_001 = Demo(Scenario_Generator.generate_complex_scenario())
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.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.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.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.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.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.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.run_demo(360)
demo_001 = None
if __name__ == "__main__":
Demo.run_complex_scene()
......@@ -2,7 +2,7 @@ import random
import numpy as np
from flatland.envs.generators import random_rail_generator # , rail_from_list_of_saved_GridTransitionMap_generator
from flatland.envs.generators import random_rail_generator
from flatland.envs.observations import TreeObsForRailEnv
from flatland.envs.rail_env import RailEnv
from flatland.utils.rendertools import RenderTool
......
......@@ -84,21 +84,6 @@ class Environment:
"""
raise NotImplementedError()
def predict(self):
"""
Predictions step.
Returns predictions for the agents.
The returns are dicts mapping from agent_id strings to values.
Returns
-------
predictions : dict
New predictions for each ready agent.
"""
raise NotImplementedError()
def get_agent_handles(self):
"""
Returns a list of agents' handles to be used as keys in the step()
......
......@@ -29,7 +29,7 @@ class PredictionBuilder:
def get(self, handle=0):
"""
Called whenever step_prediction is called on the environment.
Called whenever predict is called on the environment.
Parameters
-------
......
......@@ -3,6 +3,7 @@ TransitionMap and derived classes.
"""
import numpy as np
from importlib_resources import path
from numpy import array
from .transitions import Grid4Transitions, Grid8Transitions, RailEnvTransitions
......@@ -263,7 +264,7 @@ class GridTransitionMap(TransitionMap):
"""
np.save(filename, self.grid)
def load_transition_map(self, filename, override_gridsize=True):
def load_transition_map(self, package, resource, override_gridsize=True):
"""
Load the transitions grid from `filename' (npy format).
The load function only updates the transitions grid, and possibly width and height, but the object has to be
......@@ -271,8 +272,10 @@ class GridTransitionMap(TransitionMap):
Parameters
----------
filename : string
Name of the file from which to load the transitions grid.
package : string
Name of the package from which to load the transitions grid.
resource : string
Name of the file from which to load the transitions grid within the package.
override_gridsize : bool
If override_gridsize=True, the width and height of the GridTransitionMap object are replaced with the size
of the map loaded from `filename'. If override_gridsize=False, the transitions grid is either cropped (if
......@@ -280,7 +283,8 @@ class GridTransitionMap(TransitionMap):
(height,width) )
"""
new_grid = np.load(filename)
with path(package, resource) as file_in:
new_grid = np.load(file_in)
new_height = new_grid.shape[0]
new_width = new_grid.shape[1]
......
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