[Bug] Initial direction of agents may not be valid.
There is chance that the initial direction of agents is not valid! For example, when agent.initial_position
is a east-west rail, the agent.initial_direction
may be NORTH sometimes, although the chance is very small.
Following script can reproduce the bug within several hundred of loops.
from flatland.envs.rail_env import RailEnv
from flatland.envs.rail_generators import SparseRailGen
import numpy as np
env = RailEnv(
width=60,
height=60,
number_of_agents=4,
rail_generator=SparseRailGen(max_num_cities=6, max_rails_between_cities=3),
)
cnt = 0
while True:
env.reset()
for agent in env.agents:
possible_transitions = env.rail.get_transitions(
*agent.initial_position, agent.initial_direction
)
if all(np.array(possible_transitions) == 0):
print("Wrong initial direction!!!!! No possible transition from it!!!")
cnt += 1
print(f"\r{cnt}", end="")
My test environment:
- OS: Ubuntu 20.04 LTS (GNU/Linux 5.10.16.3-microsoft-standard-WSL2 x86_64)
- python==3.6.13
- flatland==3.0.15