Check whether a path exists from vertex index `s_i` to `e_i`. Parameters ---------- s_i: Int The interal index of the start vertex e_i: Int The internal index of the end vertex Returns ------- path_exists : Bo
(self, s_i, e_i)
| 103 | return adj_dict |
| 104 | |
| 105 | def path_exists(self, s_i, e_i): |
| 106 | """ |
| 107 | Check whether a path exists from vertex index `s_i` to `e_i`. |
| 108 | |
| 109 | Parameters |
| 110 | ---------- |
| 111 | s_i: Int |
| 112 | The interal index of the start vertex |
| 113 | e_i: Int |
| 114 | The internal index of the end vertex |
| 115 | |
| 116 | Returns |
| 117 | ------- |
| 118 | path_exists : Boolean |
| 119 | Whether or not a valid path exists between `s_i` and `e_i`. |
| 120 | """ |
| 121 | queue = [(s_i, [s_i])] |
| 122 | while len(queue): |
| 123 | c_i, path = queue.pop(0) |
| 124 | nbrs_not_on_path = set(self.get_neighbors(c_i)) - set(path) |
| 125 | |
| 126 | for n_i in nbrs_not_on_path: |
| 127 | queue.append((n_i, path + [n_i])) |
| 128 | if n_i == e_i: |
| 129 | return True |
| 130 | return False |
| 131 | |
| 132 | def all_paths(self, s_i, e_i): |
| 133 | """ |
no test coverage detected