BFS for why self is equal to at least one member of each group.
(
self, groups: list[list[Node]], level: int
)
| 231 | return bfs_backtrack(self, others, parent) |
| 232 | |
| 233 | def why_equal_groups( |
| 234 | self, groups: list[list[Node]], level: int |
| 235 | ) -> tuple[list[Any], list[Node]]: |
| 236 | """BFS for why self is equal to at least one member of each group.""" |
| 237 | others = [None for _ in groups] |
| 238 | found = 0 |
| 239 | |
| 240 | parent = {} |
| 241 | queue = [self] |
| 242 | i = 0 |
| 243 | |
| 244 | while i < len(queue): |
| 245 | current = queue[i] |
| 246 | |
| 247 | for j, grp in enumerate(groups): |
| 248 | if others[j] is None and current in grp: |
| 249 | others[j] = current |
| 250 | found += 1 |
| 251 | |
| 252 | if found == len(others): |
| 253 | break |
| 254 | |
| 255 | i += 1 |
| 256 | |
| 257 | for neighbor in current.merge_graph: |
| 258 | if ( |
| 259 | level is not None |
| 260 | and current.merge_graph[neighbor].level is not None |
| 261 | and current.merge_graph[neighbor].level >= level |
| 262 | ): |
| 263 | continue |
| 264 | if neighbor not in parent: |
| 265 | queue.append(neighbor) |
| 266 | parent[neighbor] = current |
| 267 | |
| 268 | return bfs_backtrack(self, others, parent), others |
| 269 | |
| 270 | def why_val(self, level: int) -> list[Any]: |
| 271 | return self._val.why_equal([self.val], level) |
no test coverage detected