Get all nodes that can reach to the target_idx. Parameters ---------- target_idx : Set[int] The index of target node. start_at : Optional[int] = None This option is to check if a start point can reach any nodes in the target_idx se
(
self, target_idx: Set[int], start_at: Optional[int] = None
)
| 244 | return False |
| 245 | |
| 246 | def get_reachable( |
| 247 | self, target_idx: Set[int], start_at: Optional[int] = None |
| 248 | ) -> Set[int]: |
| 249 | """Get all nodes that can reach to the target_idx. |
| 250 | |
| 251 | Parameters |
| 252 | ---------- |
| 253 | target_idx : Set[int] |
| 254 | The index of target node. |
| 255 | start_at : Optional[int] = None |
| 256 | This option is to check if a start point can reach any nodes in the |
| 257 | target_idx set. |
| 258 | |
| 259 | Returns |
| 260 | ------- |
| 261 | Set[int] |
| 262 | A set of the index of the nodes that can reach to any of the target nodes. |
| 263 | """ |
| 264 | stack = list(target_idx) |
| 265 | reachable = set() |
| 266 | while len(stack) > 0: |
| 267 | idx = stack.pop(-1) |
| 268 | if idx in reachable: |
| 269 | continue |
| 270 | reachable.add(idx) |
| 271 | if start_at is not None and idx == start_at: |
| 272 | return reachable |
| 273 | stack.extend( |
| 274 | [self._name2index[inp] for inp in self._nodes[idx].input_nodes] |
| 275 | ) |
| 276 | if start_at is not None: |
| 277 | return set() |
| 278 | return reachable |
no test coverage detected