From 01da99f3c28c7b0e54781d5a194495cc7b23687c Mon Sep 17 00:00:00 2001 From: "Egli Adrian (IT-SCI-API-PFI)" <adrian.egli@sbb.ch> Date: Thu, 23 May 2019 13:39:22 +0200 Subject: [PATCH] Bug fix in rendering: Interface was borken --- examples/demo.py | 3 ++- flatland/utils/render_qt.py | 2 +- flatland/utils/rendertools.py | 13 +++++++------ flatland/utils/svg.py | 1 + 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/examples/demo.py b/examples/demo.py index 2ee1d5c0..7e3725bc 100644 --- a/examples/demo.py +++ b/examples/demo.py @@ -164,7 +164,6 @@ class Demo: agent_obs[a] = np.concatenate((time_obs[0][a], time_obs[1][a])) for step in range(max_nbr_of_steps): - self.renderer.renderEnv(show=True) time.sleep(.2) @@ -175,6 +174,8 @@ class Demo: action_prob[action] += 1 action_dict.update({a: action}) + self.renderer.renderEnv(show=True,action_dict=action_dict) + # Environment step next_obs, all_rewards, done, _ = self.env.step(action_dict) for a in range(self.env.get_num_agents()): diff --git a/flatland/utils/render_qt.py b/flatland/utils/render_qt.py index 0f3a0f89..73b8ca77 100644 --- a/flatland/utils/render_qt.py +++ b/flatland/utils/render_qt.py @@ -121,7 +121,7 @@ class QTSVG(GraphicsLayer): self.layout = QGridLayout() self.layout.setSpacing(0) self.wMain.setLayout(self.layout) - self.wWinMain.resize(1000, 1000) + self.wWinMain.resize(600, 600) self.wWinMain.show() self.wWinMain.setFocus() diff --git a/flatland/utils/rendertools.py b/flatland/utils/rendertools.py index 9cc06d1d..713f65f0 100644 --- a/flatland/utils/rendertools.py +++ b/flatland/utils/rendertools.py @@ -605,7 +605,7 @@ class RenderTool(object): ) def renderEnv(self, show=False, curves=True, spacing=False, - arrows=False, agents=True, show_observations=True, sRailColor="gray", frames=False, + arrows=False, agents=True, renderobs=True, show_observations=True, sRailColor="gray", frames=False, iEpisode=None, iStep=None, iSelectedAgent=None, action_dict=None): """ @@ -618,9 +618,10 @@ class RenderTool(object): if not self.gl.is_raster(): self.renderEnv2(show, curves, spacing, - arrows, agents, sRailColor, + arrows, agents, renderobs,sRailColor, frames, iEpisode, iStep, iSelectedAgent, action_dict) + return if type(self.gl) in (QTGL, PILGL): @@ -764,13 +765,13 @@ class RenderTool(object): # ** TODO *** # why should we only update if the action is valid ? - if False: + if True: if action_isValid: self.gl.setAgentAt(iAgent, *agent.position, agent.direction, new_direction, color=oColor) else: - pass - # print("invalid action - agent ", iAgent, " bend ", agent.direction, new_direction) - # self.gl.setAgentAt(iAgent, *agent.position, agent.direction, new_direction) + # pass + print("invalid action - agent ", iAgent, " bend ", agent.direction, new_direction) + self.gl.setAgentAt(iAgent, *agent.position, agent.direction, new_direction) else: self.gl.setAgentAt(iAgent, *agent.position, agent.direction, new_direction, color=oColor) diff --git a/flatland/utils/svg.py b/flatland/utils/svg.py index e7c295f7..fb8b987c 100644 --- a/flatland/utils/svg.py +++ b/flatland/utils/svg.py @@ -80,6 +80,7 @@ class Zug(object): self.svg_curve2 = SVG("svg/Zug_2_Weiche_#0091ea.svg") def getSvg(self, iAgent, iDirIn, iDirOut, color=None): + delta_dir = (iDirOut - iDirIn) % 4 # if delta_dir != 0: # print("Bend:", iAgent, iDirIn, iDirOut) -- GitLab