Commit 0a151b32 authored by hagrid67's avatar hagrid67
Browse files

split up rail_env.py into rail_env, generators and env_utils.py

parent cf1cc9b7
Pipeline #474 canceled with stage
in 1 minute and 7 seconds
from flatland.envs.rail_env import RailEnv, complex_rail_generator
from flatland.envs.rail_env import RailEnv
from flatland.envs.generators import complex_rail_generator
# from flatland.core.env_observation_builder import TreeObsForRailEnv
from flatland.utils.rendertools import RenderTool
from flatland.baselines.dueling_double_dqn import Agent
......
This diff is collapsed.
......@@ -167,26 +167,32 @@ class JupEditor(object):
# get the direction index for the 2 transitions
liTrans = []
for rcTrans in rc2Trans:
# gRCTrans - rcTrans gives an array of vector differences between our rcTrans
# and the 4 directions stored in gRCTrans.
# Where the vector difference is zero, we have a match...
# np.all detects where the whole row,col vector is zero.
# argwhere gives the index of the zero vector, ie the direction index
iTrans = np.argwhere(np.all(self.gRCTrans - rcTrans == 0, axis=1))
if len(iTrans) > 0:
iTrans = iTrans[0][0]
liTrans.append(iTrans)
# check that we have two transitions
if len(liTrans) == 2:
# Set the transition
# oEnv.rail.set_transition((*rcLast, iTransLast), iTrans, True) # does nothing
iValCell = env.rail.transitions.set_transition(
env.rail.grid[tuple(rcMiddle)], liTrans[0], liTrans[1], bTransition)
env.rail.set_transition((*rcMiddle, liTrans[0]), liTrans[1], True)
# iValCell = env.rail.transitions.set_transition(
# env.rail.grid[tuple(rcMiddle)], liTrans[0], liTrans[1], bTransition)
# Also set the reverse transition
iValCell = env.rail.transitions.set_transition(
iValCell,
(liTrans[1] + 2) % 4,
(liTrans[0] + 2) % 4,
bTransition)
# iValCell = env.rail.transitions.set_transition(
# iValCell,
# (liTrans[1] + 2) % 4, # use the reversed outbound transition for inbound
# (liTrans[0] + 2) % 4, # use the reversed inbound transition for outbound
# bTransition)
# Write the cell transition value back into the grid
env.rail.grid[tuple(rcMiddle)] = iValCell
# env.rail.grid[tuple(rcMiddle)] = iValCell
rcHistory.pop(0) # remove the last-but-one
......
......@@ -5,7 +5,8 @@ import numpy as np
from flatland.core.env_observation_builder import GlobalObsForRailEnv
from flatland.core.transition_map import GridTransitionMap, Grid4Transitions
from flatland.envs.rail_env import RailEnv, rail_from_GridTransitionMap_generator
from flatland.envs.rail_env import RailEnv
from flatland.envs.generators import rail_from_GridTransitionMap_generator
"""Tests for `flatland` package."""
......
......@@ -2,11 +2,13 @@
# -*- coding: utf-8 -*-
import numpy as np
from flatland.envs.rail_env import RailEnv, rail_from_GridTransitionMap_generator
from flatland.envs.rail_env import RailEnv
from flatland.envs.generators import rail_from_GridTransitionMap_generator
from flatland.core.transitions import Grid4Transitions
from flatland.core.transition_map import GridTransitionMap
from flatland.core.env_observation_builder import GlobalObsForRailEnv
"""Tests for `flatland` package."""
......
......@@ -3,7 +3,8 @@
"""Tests for `flatland` package."""
from flatland.core.transitions import RailEnvTransitions, Grid8Transitions
from flatland.envs.rail_env import validate_new_transition
# from flatland.envs.rail_env import validate_new_transition
from flatland.envs.env_utils import validate_new_transition
import numpy as np
......
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