def regenerate(self, method=None, nAgents=0, env=None): self.log("Regenerate size", self.regen_size_width, self.regen_size_height) if method is None or method == "Empty": fnMethod = empty_rail_generator() elif method == "Random Cell": fnMethod = random_rail_generator( cell_type_relative_proportion=[1] * 11) else: fnMethod = complex_rail_generator(nr_start_goal=nAgents, nr_extra=20, min_dist=12, seed=int(time.time())) if env is None: self.env = RailEnv( width=self.regen_size_width, height=self.regen_size_height, rail_generator=fnMethod, number_of_agents=nAgents, obs_builder_object=TreeObsForRailEnv(max_depth=2)) else: self.env = env self.env.reset(regenerate_rail=True) self.fix_env() self.set_env(self.env) self.view.new_env() self.redraw()
def test_render_env(save_new_images=False): np.random.seed(100) oEnv = RailEnv(width=10, height=10, rail_generator=empty_rail_generator(), number_of_agents=0, obs_builder_object=TreeObsForRailEnv(max_depth=2)) oEnv.reset() oEnv.rail.load_transition_map('env_data.tests', "test1.npy") oRT = rt.RenderTool(oEnv, gl="PILSVG") oRT.render_env(show=False) checkFrozenImage(oRT, "basic-env.npz", resave=save_new_images) oRT = rt.RenderTool(oEnv, gl="PIL") oRT.render_env() checkFrozenImage(oRT, "basic-env-PIL.npz", resave=save_new_images)
def __init__(self, env=None, sGL="PIL", env_filename="temp.pkl"): """ Create an Editor MVC assembly around a railenv, or create one if None. """ if env is None: env = RailEnv(width=10, height=10, rail_generator=empty_rail_generator(), number_of_agents=0, obs_builder_object=TreeObsForRailEnv(max_depth=2)) env.reset() self.editor = EditorModel(env, env_filename=env_filename) self.editor.view = self.view = View(self.editor, sGL=sGL) self.view.controller = self.editor.controller = self.controller = Controller(self.editor, self.view) self.view.init_canvas() self.view.init_widgets() # has to be done after controller
def test_empty_rail_generator(): n_agents = 1 x_dim = 5 y_dim = 10 # Check that a random level at with correct parameters is generated env = RailEnv(width=x_dim, height=y_dim, rail_generator=empty_rail_generator(), number_of_agents=n_agents) env.reset() # Check the dimensions assert env.rail.grid.shape == (y_dim, x_dim) # Check that no grid was generated assert np.count_nonzero(env.rail.grid) == 0 # Check that no agents where placed assert env.get_num_agents() == 0