# nodes_queue = [] # list of tuples (row, col, direction, distance); direction is the direction of movement, meaning that at least a possible orientation of an agent in cell (row,col) allows a movement in direction `direction'
# nodes_queue = [] # list of tuples (row, col, direction, distance);
@@ -56,8 +60,11 @@ class TreeObsForRailEnv(ObservationBuilder):
...
@@ -56,8 +60,11 @@ class TreeObsForRailEnv(ObservationBuilder):
ifnode_idnotinvisited:
ifnode_idnotinvisited:
visited.add(node_id)
visited.add(node_id)
# From the list of possible neighbors that have at least a path to the current node, only keep those whose new orientation in the current cell would allow a transition to direction node[2]
# From the list of possible neighbors that have at least a path to the
# Check if the two cells are connected by a valid transition
# Check if the two cells are connected by a valid transition
transitionValid=False
transitionValid=False
fororientationinrange(4):
fororientationinrange(4):
...
@@ -86,12 +94,17 @@ class TreeObsForRailEnv(ObservationBuilder):
...
@@ -86,12 +94,17 @@ class TreeObsForRailEnv(ObservationBuilder):
ifnottransitionValid:
ifnottransitionValid:
continue
continue
# Check if a transition in direction node[2] is possible if an agent lands in the current cell with orientation `direction'; this only applies to cells that are not dead-ends!
# Check if a transition in direction node[2] is possible if an agent
# lands in the current cell with orientation `direction'; this only
# If transition is found to invalid, check if perhaps it is a dead-end, in which case the direction of movement is rotated 180 degrees (moving forward turns the agents and makes it step in the previous cell)
# If transition is found to invalid, check if perhaps it
# is a dead-end, in which case the direction of movement is rotated
# 180 degrees (moving forward turns the agents and makes it step in the previous cell)
ifnotdirectionMatch:
ifnotdirectionMatch:
# If cell is a dead-end, append previous node with reversed
# If cell is a dead-end, append previous node with reversed
# orientation!
# orientation!
...
@@ -102,11 +115,14 @@ class TreeObsForRailEnv(ObservationBuilder):
...
@@ -102,11 +115,14 @@ class TreeObsForRailEnv(ObservationBuilder):
tmp=tmp>>1
tmp=tmp>>1
ifnbits==1:
ifnbits==1:
# Dead-end!
# Dead-end!
# Check if transition is possible in new_cell with orientation (direction+2)%4 in direction `direction'