Graph search algorithm takes into account train's direction.