# graph

Python API: `luxonis_ml.utils.graph`

## 函数

### is_acyclic

```python
def is_acyclic(graph: dict[str, list[str]]) -> bool:
```

测试图是否是无环的。

> **示例**
> ```pycon
>>> is_acyclic({"a": ["b"], "b": []})
True
>>> is_acyclic({"a": ["b"], "b": ["a"]})
False
>>> is_acyclic({})
True
```

参数

 * `graph` (`dict[str, list[str]]`): 表示为前驱字典的图。

返回

 * `bool`: 如果图是无环的，则为 `True`，否则为 `False`。

### traverse_graph

```python
def traverse_graph(graph: dict[str, list[str]], nodes: Mapping[str, T]) -> Iterator[tuple[str, T, list[str], list[str]]]:
```

以拓扑顺序遍历图，从没有前驱的节点开始。

> **示例**
> ```pycon
>>> graph = {"a": ["b"], "b": []}
>>> nodes = {"a": 1, "b": 2}
>>> for name, value, preds, rem in traverse_graph(graph, nodes):
...     print(name, value, preds, rem)
b 2 [] ['a']
a 1 ['b'] []
```

参数

 * `graph` (`dict[str, list[str]]`): 表示为前驱字典的图。键是节点名称，值是节点前驱。
 * `nodes` (`Mapping[str, T]`): 将节点名称映射到值的字典。

返回

 * `Iterator[tuple[str, T, list[str], list[str]]]`

生成

 * 包含节点名称、节点值、节点前驱和剩余未处理节点的元组。

引发

 * `RuntimeError`: 如果图格式不正确。

## 属性

### T
