Skip to content
Snippets Groups Projects
Commit f1b63471 authored by Erik Nygren's avatar Erik Nygren
Browse files

updated orientation of initial tree branch in env_observation_builder.py

parent 1e1a1282
No related branches found
No related tags found
No related merge requests found
...@@ -82,8 +82,7 @@ class TreeObsForRailEnv(ObservationBuilder): ...@@ -82,8 +82,7 @@ class TreeObsForRailEnv(ObservationBuilder):
""" """
# Returns max distance to target, from the farthest away node, while filling in distance_map # Returns max distance to target, from the farthest away node, while filling in distance_map
for ori in range(4): self.distance_map[target_nr, position[0], position[1], :] = 0
self.distance_map[target_nr, position[0], position[1], ori] = 0
# Fill in the (up to) 4 neighboring nodes # Fill in the (up to) 4 neighboring nodes
# nodes_queue = [] # list of tuples (row, col, direction, distance); # nodes_queue = [] # list of tuples (row, col, direction, distance);
...@@ -237,14 +236,18 @@ class TreeObsForRailEnv(ObservationBuilder): ...@@ -237,14 +236,18 @@ class TreeObsForRailEnv(ObservationBuilder):
position = self.env.agents_position[handle] position = self.env.agents_position[handle]
orientation = self.env.agents_direction[handle] orientation = self.env.agents_direction[handle]
possible_transitions = self.env.rail.get_transitions((position[0], position[1], orientation)) possible_transitions = self.env.rail.get_transitions((position[0], position[1], orientation))
num_transitions = np.count_nonzero(possible_transitions)
# Root node - current position # Root node - current position
observation = [0, 0, 0, 0, self.distance_map[handle, position[0], position[1], orientation]] observation = [0, 0, 0, 0, self.distance_map[handle, position[0], position[1], orientation]]
root_observation = observation[:] root_observation = observation[:]
# Start from the current orientation, and see which transitions are available; # Start from the current orientation, and see which transitions are available;
# organize them as [left, forward, right, back], relative to the current orientation # organize them as [left, forward, right, back], relative to the current orientation
# TODO: Adjust this to the novel movement dynamics --> Only Forward present when one transition is possible. # If only one transition is possible, the tree is oriented with this transition as the forward branch.
# TODO: Test if this works as desired!
if num_transitions == 1:
orientation == np.argmax(possible_transitions)
for branch_direction in [(orientation + 4 + i) % 4 for i in range(-1, 3)]: for branch_direction in [(orientation + 4 + i) % 4 for i in range(-1, 3)]:
if possible_transitions[branch_direction]: if possible_transitions[branch_direction]:
new_cell = self._new_position(position, branch_direction) new_cell = self._new_position(position, branch_direction)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment