| 1051 | } |
| 1052 | |
| 1053 | void GraphConstructor::DFS(int cur_node, std::vector<int>* cur_branch, |
| 1054 | std::vector<bool>* is_on_cur_branch, |
| 1055 | absl::flat_hash_set<int>* unvisited) { |
| 1056 | cur_branch->push_back(cur_node); |
| 1057 | is_on_cur_branch->at(cur_node) = true; |
| 1058 | for (auto next_node : outputs_[cur_node]) { |
| 1059 | if (unvisited->find(next_node) != unvisited->end()) { |
| 1060 | if (is_on_cur_branch->at(next_node)) { |
| 1061 | auto iter = |
| 1062 | std::find(cur_branch->begin(), cur_branch->end(), next_node); |
| 1063 | LOG(WARNING) << "Cycle detected:"; |
| 1064 | while (iter != cur_branch->end()) { |
| 1065 | LOG(WARNING) << *iter; |
| 1066 | ++iter; |
| 1067 | } |
| 1068 | LOG(WARNING) << "End of cycle"; |
| 1069 | } else { |
| 1070 | DFS(next_node, cur_branch, is_on_cur_branch, unvisited); |
| 1071 | } |
| 1072 | } |
| 1073 | } |
| 1074 | cur_branch->pop_back(); |
| 1075 | is_on_cur_branch->at(cur_node) = false; |
| 1076 | unvisited->erase(cur_node); |
| 1077 | } |
| 1078 | |
| 1079 | void GraphConstructor::PrintCycles() { |
| 1080 | int num_nodes = outputs_.size(); |