Commit b604cad1 authored by Erik Nygren's avatar Erik Nygren
Browse files

code cleanup in step function

parent 404d650a
Pipeline #486 failed with stage
in 1 minute and 54 seconds
...@@ -35,13 +35,13 @@ env = RailEnv(width=20, ...@@ -35,13 +35,13 @@ env = RailEnv(width=20,
rail_generator=complex_rail_generator(nr_start_goal=20, min_dist=10, max_dist=99999, seed=0), rail_generator=complex_rail_generator(nr_start_goal=20, min_dist=10, max_dist=99999, seed=0),
number_of_agents=5) number_of_agents=5)
"""
env = RailEnv(width=20, env = RailEnv(width=20,
height=20, height=20,
rail_generator=rail_from_list_of_saved_GridTransitionMap_generator( rail_generator=rail_from_list_of_saved_GridTransitionMap_generator(
['../env-data/tests/circle.npy']), ['../notebooks/testing_11.npy']),
number_of_agents=1) number_of_agents=1)
"""
env_renderer = RenderTool(env, gl="QT") env_renderer = RenderTool(env, gl="QT")
handle = env.get_agent_handles() handle = env.get_agent_handles()
...@@ -61,7 +61,7 @@ action_prob = [0] * 4 ...@@ -61,7 +61,7 @@ action_prob = [0] * 4
agent = Agent(state_size, action_size, "FC", 0) agent = Agent(state_size, action_size, "FC", 0)
agent.qnetwork_local.load_state_dict(torch.load('../flatland/baselines/Nets/avoid_checkpoint14900.pth')) agent.qnetwork_local.load_state_dict(torch.load('../flatland/baselines/Nets/avoid_checkpoint14900.pth'))
demo = False demo = True
def max_lt(seq, val): def max_lt(seq, val):
......
...@@ -366,13 +366,9 @@ class RailEnv(Environment): ...@@ -366,13 +366,9 @@ class RailEnv(Environment):
is_deadend = True is_deadend = True
if np.sum(possible_transitions) == 1: if np.sum(possible_transitions) == 1:
# Checking for curves # Take only available transition
curv_dir = np.argmax(possible_transitions) movement = np.argmax(possible_transitions)
# valid_transition = self.rail.get_transition(
# (pos[0], pos[1], direction),
# movement)
movement = curv_dir
new_position = self._new_position(pos, movement) new_position = self._new_position(pos, movement)
# Is it a legal move? 1) transition allows the movement in the # Is it a legal move? 1) transition allows the movement in the
# cell, 2) the new cell is not empty (case 0), 3) the cell is # cell, 2) the new cell is not empty (case 0), 3) the cell is
......
...@@ -208,7 +208,7 @@ class RenderTool(object): ...@@ -208,7 +208,7 @@ class RenderTool(object):
xyDir = np.matmul(rcDir, rt.grc2xy) # agent direction in xy xyDir = np.matmul(rcDir, rt.grc2xy) # agent direction in xy
xyPos = np.matmul(rcPos - rcDir / 2, rt.grc2xy) + rt.xyHalf xyPos = np.matmul(rcPos - rcDir / 2, rt.grc2xy) + rt.xyHalf
print("Agent:", rcPos, iDir, rcDir, xyDir, xyPos) #print("Agent:", rcPos, iDir, rcDir, xyDir, xyPos)
self.gl.scatter(*xyPos, color=color, marker="o", s=100) # agent location self.gl.scatter(*xyPos, color=color, marker="o", s=100) # agent location
xyDirLine = array([xyPos, xyPos + xyDir/2]).T # line for agent orient. xyDirLine = array([xyPos, xyPos + xyDir/2]).T # line for agent orient.
......
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