提交 d5785541 编写于 作者: L Li Xinqi 提交者: Jinhui Yuan

carefully handle depth of act_node (#1003)

* carefully handle depth of act_node

* bfs topo instead of dfs topo
上级 96ca9d84
......@@ -401,7 +401,11 @@ void ActGraph::InitEdges() {
void ActGraph::TopoForEachActNode(const std::list<ActNode*>& starts,
const std::function<void(ActNode*)>& Handler) const {
TopoForEachNode(starts, &ActNode::ForEachNodeOnInEdge, &ActNode::ForEachNodeOnOutEdge, Handler);
std::list<ActNode*> sorted_starts(starts);
sorted_starts.sort(
[](const ActNode* lhs, const ActNode* rhs) { return lhs->act_id() < rhs->act_id(); });
TopoForEachNode(sorted_starts, &ActNode::ForEachNodeOnInEdge, &ActNode::ForEachNodeOnOutEdge,
Handler);
}
void ActGraph::InitDepth() {
......@@ -409,13 +413,16 @@ void ActGraph::InitDepth() {
ForEachNode([&](ActNode* node) {
if (node->in_edges().empty()) { sources.push_back(node); }
});
int64_t max_depth = -1;
TopoForEachActNode(sources, [&](ActNode* act_node) {
int64_t depth = -1;
act_node->ForEachNodeOnInEdge(
[&](const ActNode* in_node) { depth = std::max(depth, in_node->depth()); });
[&](ActNode* in_node) { depth = std::max(depth, in_node->depth()); });
if (depth == -1) { depth = max_depth; }
++depth;
act_node->set_depth(depth);
depth2nodes_[depth].push_back(act_node);
max_depth = std::max(max_depth, depth);
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册