flatland.utils.rendertools module

class flatland.utils.rendertools.AgentRenderVariant[source]

Bases: enum.IntEnum

An enumeration.

AGENT_SHOWS_OPTIONS = 2
AGENT_SHOWS_OPTIONS_AND_BOX = 4
BOX_ONLY = 0
ONE_STEP_BEHIND = 1
ONE_STEP_BEHIND_AND_BOX = 3
class flatland.utils.rendertools.RenderBase(env)[source]

Bases: object

close_window()[source]
render_env()[source]
reset()[source]
set_new_rail()[source]

Signal to the renderer that the env has changed and will need re-rendering.

update_background()[source]

A lesser version of set_new_rail? TODO: can update_background be pruned for simplicity?

class flatland.utils.rendertools.RenderLocal(env, gl='PILSVG', jupyter=False, agent_render_variant=<AgentRenderVariant.ONE_STEP_BEHIND: 1>, show_debug=False, clear_debug_text=True, screen_width=800, screen_height=600)[source]

Bases: flatland.utils.rendertools.RenderBase

Class to render the RailEnv and agents. Uses two layers, layer 0 for rails (mostly static), layer 1 for agents etc (dynamic) The lower / rail layer 0 is only redrawn after set_new_rail() has been called. Created with a “GraphicsLayer” or gl - now either PIL or PILSVG

arc = array([[1.00000000e+00, 0.00000000e+00], [9.23879533e-01, 3.82683432e-01], [7.07106781e-01, 7.07106781e-01], [3.82683432e-01, 9.23879533e-01], [6.12323400e-17, 1.00000000e+00]])
close_window()[source]
color_list = ['b', 'r', 'g', 'c', 'm', 'y', 'k']
draw_transition(line, center, rotation, dead_end=False, curves=False, color='gray', arrow=True, spacing=0.1)[source]

gLine is a numpy 2d array of points, in the plotting space / coords. eg: [[0,.5],[1,0.2]] means a line from x=0, y=0.5 to x=1, y=0.2

get_image()[source]
get_transition_row_col(row_col_pos, direction, bgiTrans=False)[source]

Get the available transitions for row_col_pos in direction direction, as row & col deltas.

If bgiTrans is True, return a grid of indices of available transitions.

eg for a cell row_col_pos = (4,5), in direction direction = 0 (N), where the available transitions are N and E, returns: [[-1,0], [0,1]] ie N=up one row, and E=right one col. and if bgiTrans is True, returns a tuple: (

[[-1,0], [0,1]], # deltas as before [0, 1] # available transition indices, ie N, E

)

grid = array([[[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], [[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1], [-2, -2, -2, -2, -2, -2, -2, -2, -2, -2], [-3, -3, -3, -3, -3, -3, -3, -3, -3, -3], [-4, -4, -4, -4, -4, -4, -4, -4, -4, -4], [-5, -5, -5, -5, -5, -5, -5, -5, -5, -5], [-6, -6, -6, -6, -6, -6, -6, -6, -6, -6], [-7, -7, -7, -7, -7, -7, -7, -7, -7, -7], [-8, -8, -8, -8, -8, -8, -8, -8, -8, -8], [-9, -9, -9, -9, -9, -9, -9, -9, -9, -9]]])
half_pix_per_cell = 0.5
pix_per_cell = 1
plot_agents(targets=True, selected_agent=None)[source]
plot_single_agent(position_row_col, direction, color='r', target=None, static=False, selected=False)[source]

Plot a simple agent. Assumes a working graphics layer context (cf a MPL figure).

plot_transition(position_row_col, transition_row_col, color='r', depth=None)[source]

plot the transitions in transition_row_col at position position_row_col. transition_row_col is a 2d numpy array containing a list of RC transitions, eg [[-1,0], [0,1]] means N, E.

render_env(show=False, show_agents=True, show_inactive_agents=False, show_observations=True, show_predictions=False, show_rowcols=False, frames=False, episode=None, step=None, selected_agent=None, return_image=False)[source]

Draw the environment using the GraphicsLayer this RenderTool was created with. (Use show=False from a Jupyter notebook with %matplotlib inline)

render_env_pil(show=False, show_agents=True, show_inactive_agents=False, show_observations=True, show_predictions=False, show_rowcols=False, frames=False, episode=None, step=None, selected_agent=None, return_image=False)[source]
render_env_svg(show=False, show_observations=True, show_predictions=False, selected_agent=None, show_agents=True, show_inactive_agents=False, show_rowcols=False, return_image=False)[source]

Renders the environment with SVG support (nice image)

render_observation(agent_handles, observation_dict)[source]

Render the extent of the observation of each agent. All cells that appear in the agent observation will be highlighted. :param agent_handles: List of agent indices to adapt color and get correct observation :param observation_dict: dictionary containing sets of cells of the agent observation

render_prediction(agent_handles, prediction_dict)[source]

Render the extent of the observation of each agent. All cells that appear in the agent observation will be highlighted. :param agent_handles: List of agent indices to adapt color and get correct observation :param observation_dict: dictionary containing sets of cells of the agent observation

render_rail(spacing=False, rail_color='gray', curves=True, arrows=False)[source]
reset()[source]

Resets the environment :return:

resize()[source]
row_col_to_xy = array([[ 0, -1], [ 1, 0]])
set_new_rail()[source]

Tell the renderer that the rail has changed. eg when the rail has been regenerated, or updated in the editor.

theta = array([0. , 0.39269908, 0.78539816, 1.17809725, 1.57079633])
transitions_row_col = array([[-1, 0], [ 0, 1], [ 1, 0], [ 0, -1]])
update_background()[source]

A lesser version of set_new_rail? TODO: can update_background be pruned for simplicity?

class visit(rc, iDir, iDepth, prev)

Bases: object

iDepth
iDir
prev
rc
x_y_half = array([ 0.5, -0.5])
class flatland.utils.rendertools.RenderTool(env, gl='PGL', jupyter=False, agent_render_variant=<AgentRenderVariant.ONE_STEP_BEHIND: 1>, show_debug=False, clear_debug_text=True, screen_width=800, screen_height=600, host='localhost', port=None)[source]

Bases: object

RenderTool is a facade to a renderer. (This was introduced for the Browser / JS renderer which has now been removed.)

close_window()[source]
get_endpoint_URL()[source]

Returns a string URL for the root of the HTTP server TODO: Need to update this work work on a remote server! May be tricky…

get_image()[source]
render_env(show=False, show_agents=True, show_inactive_agents=False, show_observations=True, show_predictions=False, show_rowcols=False, frames=False, episode=None, step=None, selected_agent=None, return_image=False)[source]
reset()[source]
set_new_rail()[source]
update_background()[source]