diff --git a/flatland/envs/agent_utils.py b/flatland/envs/agent_utils.py index 40bca7e35e97374e0e3ab11f3161f184cbf56298..2d07eeebf50c9eeb1f6aa0b06afb7c28bef5e032 100644 --- a/flatland/envs/agent_utils.py +++ b/flatland/envs/agent_utils.py @@ -34,7 +34,12 @@ class EnvAgentStatic(object): # cell if speed=1, as default) speed_data = attrib(default=dict({'position_fraction': 0.0, 'speed': 1.0, 'transition_action_on_cellexit': 0})) - def __init__(self, position, direction, target, moving=False, speed_data={'position_fraction': 0.0, 'speed': 1.0, 'transition_action_on_cellexit': 0}): + def __init__(self, + position, + direction, + target, + moving=False, + speed_data={'position_fraction': 0.0, 'speed': 1.0, 'transition_action_on_cellexit': 0}): self.position = position self.direction = direction self.target = target @@ -47,7 +52,7 @@ class EnvAgentStatic(object): """ speed_datas = [] for i in range(len(positions)): - speed_datas.append( {'position_fraction': 0.0, 'speed': 1.0, 'transition_action_on_cellexit': 0} ) + speed_datas.append({'position_fraction': 0.0, 'speed': 1.0, 'transition_action_on_cellexit': 0}) return list(starmap(EnvAgentStatic, zip(positions, directions, targets, [False] * len(positions), speed_datas))) def to_list(self): diff --git a/flatland/envs/rail_env.py b/flatland/envs/rail_env.py index 090e0cce499ea30b51d9e69f7004d22c10d94f12..43a076664fd264022f333f54c36a378e6460f958 100644 --- a/flatland/envs/rail_env.py +++ b/flatland/envs/rail_env.py @@ -227,9 +227,13 @@ class RailEnv(Environment): if action != RailEnvActions.DO_NOTHING and action != RailEnvActions.STOP_MOVING: # Now perform a movement. # If the agent is in an initial position within a new cell (agent.speed_data['position_fraction']<eps) - # store the desired action in `transition_action_on_cellexit' (only if the desired transition is allowed! otherwise DO_NOTHING!) - # Then in any case (if agent.moving) and the `transition_action_on_cellexit' is valid, increment the position_fraction by the speed of the agent (regardless of action taken, as long as no STOP_MOVING, but that makes agent.moving=False) - # If the new position fraction is >= 1, reset to 0, and perform the stored transition_action_on_cellexit + # store the desired action in `transition_action_on_cellexit' (only if the desired transition is + # allowed! otherwise DO_NOTHING!) + # Then in any case (if agent.moving) and the `transition_action_on_cellexit' is valid, increment the + # position_fraction by the speed of the agent (regardless of action taken, as long as no + # STOP_MOVING, but that makes agent.moving=False) + # If the new position fraction is >= 1, reset to 0, and perform the stored + # transition_action_on_cellexit if agent.speed_data['position_fraction'] < 0.01: # Is the desired transition valid? @@ -266,7 +270,8 @@ class RailEnv(Environment): # Perform stored action to transition to the next cell - # Now 'transition_action_on_cellexit' will be guaranteed to be valid; it was checked on entering the cell + # Now 'transition_action_on_cellexit' will be guaranteed to be valid; it was checked on entering + # the cell cell_isFree, new_cell_isValid, new_direction, new_position, transition_isValid = \ self._check_action_on_agent(agent.speed_data['transition_action_on_cellexit'], agent) agent.old_direction = agent.direction