
'''simple docstring'''


from __future__ import annotations

import time

__lowercase							:   Union[str, Any]					=     list[tuple[int, int]]

__lowercase							:   Optional[int]					=     [
    [0, 0, 0, 0, 0, 0, 0],
    [0, 1, 0, 0, 0, 0, 0],  # 0 are free path whereas 1's are obstacles
    [0, 0, 0, 0, 0, 0, 0],
    [0, 0, 1, 0, 0, 0, 0],
    [1, 0, 1, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 1, 0, 0],
]

__lowercase							:   Optional[Any]					=     [[-1, 0], [0, -1], [1, 0], [0, 1]]  # up, left, down, right

class 	__lowercase				:

			def __init__(self			,   A			,   A			,   A			,   A			,   A      ):
								lowerCamelCase_					:      int     =		pos_x
								lowerCamelCase_					:      Dict     =		pos_y
								lowerCamelCase_					:      Dict     =		(pos_y, pos_x)
								lowerCamelCase_					:      Any     =		goal_x
								lowerCamelCase_					:      Tuple     =		goal_y
								lowerCamelCase_					:      Union[str, Any]     =		parent

class 	__lowercase				:

			def __init__(self			,   A			,   A      ):
								lowerCamelCase_					:      int     =		Node(start[1]			,   start[0]			,   goal[1]			,   goal[0]			,   A      )
								lowerCamelCase_					:      Union[str, Any]     =		Node(goal[1]			,   goal[0]			,   goal[1]			,   goal[0]			,   A      )

								lowerCamelCase_					:      Optional[int]     =		[self.start]
								lowerCamelCase_					:      int     =		False

			def        UpperCAmelCase__ (self      ):
								while self.node_queue:
													lowerCamelCase_					:      List[Any]     =		self.node_queue.pop(0      )

													if current_node.pos == self.target.pos:
																		lowerCamelCase_					:      Optional[int]     =		True
																		return self.retrace_path(A      )

													lowerCamelCase_					:      Optional[Any]     =		self.get_successors(A      )

													for node in successors:
																		self.node_queue.append(A      )

								if not self.reached:
													return [self.start.pos]
								return None

			def        UpperCAmelCase__ (self			,   A      ):
								lowerCamelCase_					:      Union[str, Any]     =		[]
								for action in delta:
													lowerCamelCase_					:      int     =		parent.pos_x + action[1]
													lowerCamelCase_					:      Any     =		parent.pos_y + action[0]
													if not (0 <= pos_x <= len(grid[0]      ) - 1 and 0 <= pos_y <= len(A      ) - 1):
																		continue

													if grid[pos_y][pos_x] != 0:
																		continue

													successors.append(
													    Node(A			,   A			,   self.target.pos_y			,   self.target.pos_x			,   A      )      )
								return successors






			def        UpperCAmelCase__ (self			,   A      ):
								lowerCamelCase_					:      Any     =		node
								lowerCamelCase_					:      Optional[int]     =		[]
								while current_node is not None:
													path.append((current_node.pos_y, current_node.pos_x)      )
													lowerCamelCase_					:      Any     =		current_node.parent
								path.reverse()
								return path

class 	__lowercase				:

			def __init__(self			,   A			,   A      ):
								lowerCamelCase_					:      Optional[int]     =		BreadthFirstSearch(A			,   A      )
								lowerCamelCase_					:      List[str]     =		BreadthFirstSearch(A			,   A      )
								lowerCamelCase_					:      List[str]     =		False

			def        UpperCAmelCase__ (self      ):
								while self.fwd_bfs.node_queue or self.bwd_bfs.node_queue:
													lowerCamelCase_					:      Optional[Any]     =		self.fwd_bfs.node_queue.pop(0      )
													lowerCamelCase_					:      str     =		self.bwd_bfs.node_queue.pop(0      )

													if current_bwd_node.pos == current_fwd_node.pos:
																		lowerCamelCase_					:      Union[str, Any]     =		True
																		return self.retrace_bidirectional_path(
																		    A			,   A      )

													lowerCamelCase_					:      str     =		current_bwd_node
													lowerCamelCase_					:      int     =		current_fwd_node

													lowerCamelCase_					:      Optional[Any]     =		{
													    self.fwd_bfs: self.fwd_bfs.get_successors(A      ),
													    self.bwd_bfs: self.bwd_bfs.get_successors(A      ),
													}

													for bfs in [self.fwd_bfs, self.bwd_bfs]:
																		for node in successors[bfs]:
																							bfs.node_queue.append(A      )

								if not self.reached:
													return [self.fwd_bfs.start.pos]
								return None






			def        UpperCAmelCase__ (self			,   A			,   A      ):
								lowerCamelCase_					:      int     =		self.fwd_bfs.retrace_path(A      )
								lowerCamelCase_					:      Union[str, Any]     =		self.bwd_bfs.retrace_path(A      )
								bwd_path.pop()
								bwd_path.reverse()
								lowerCamelCase_					:      Any     =		fwd_path + bwd_path
								return path


if __name__ == "__main__":
					# all coordinates are given in format [y,x]
					import doctest

					doctest.testmod()
					__lowercase							:   Optional[int]					=     (0, 0)
					__lowercase							:   int					=     (len(grid) - 1, len(grid[0]) - 1)
					for elem in grid:
										print(elem)

					__lowercase							:   List[str]					=     time.time()
					__lowercase							:   Dict					=     BreadthFirstSearch(init, goal)
					__lowercase							:   Tuple					=     bfs.search()
					__lowercase							:   Optional[Any]					=     time.time() - start_bfs_time

					print('''Unidirectional BFS computation time : ''', bfs_time)

					__lowercase							:   List[Any]					=     time.time()
					__lowercase							:   List[Any]					=     BidirectionalBreadthFirstSearch(init, goal)
					__lowercase							:   Any					=     bd_bfs.search()
					__lowercase							:   Tuple					=     time.time() - start_bd_bfs_time

					print('''Bidirectional BFS computation time : ''', bd_bfs_time)




'''simple docstring'''


from typing import TYPE_CHECKING

from ....utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__lowercase							:   str					=     {
    '''configuration_mctct''': ['''MCTCT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''MCTCTConfig'''],
    '''feature_extraction_mctct''': ['''MCTCTFeatureExtractor'''],
    '''processing_mctct''': ['''MCTCTProcessor'''],
}


try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					__lowercase							:   str					=     [
					    '''MCTCT_PRETRAINED_MODEL_ARCHIVE_LIST''',
					    '''MCTCTForCTC''',
					    '''MCTCTModel''',
					    '''MCTCTPreTrainedModel''',
					]


if TYPE_CHECKING:
					from .configuration_mctct import MCTCT_PRETRAINED_CONFIG_ARCHIVE_MAP, MCTCTConfig
					from .feature_extraction_mctct import MCTCTFeatureExtractor
					from .processing_mctct import MCTCTProcessor

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_mctct import MCTCT_PRETRAINED_MODEL_ARCHIVE_LIST, MCTCTForCTC, MCTCTModel, MCTCTPreTrainedModel

else:
					import sys

					__lowercase							:   Union[str, Any]					=     _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)


