Returns a string describing how an edge from src to dst would create a cycle.
| 41 | // Returns a string describing how an edge from src to dst would |
| 42 | // create a cycle. |
| 43 | string DescribeCycle(const GraphCycles* cycles, const Graph& graph, int src, |
| 44 | int dst) { |
| 45 | int32 max_path_size = graph.num_node_ids() + 1; |
| 46 | std::vector<int32> path(max_path_size); |
| 47 | int32 path_size = cycles->FindPath(dst, src, max_path_size, path.data()); |
| 48 | if (path_size == 0) { |
| 49 | return ""; |
| 50 | } |
| 51 | |
| 52 | auto node_name = [&graph](int node_id) { |
| 53 | if (!FastBoundsCheck(node_id, graph.num_node_ids())) { |
| 54 | return string("(null)"); |
| 55 | } |
| 56 | auto* node = graph.FindNodeId(node_id); |
| 57 | if (node == nullptr) { |
| 58 | return string("(null)"); |
| 59 | } |
| 60 | return node->name(); |
| 61 | }; |
| 62 | |
| 63 | string description; |
| 64 | absl::StrAppend(&description, "Edge from ", node_name(src), " to ", |
| 65 | node_name(dst), " would create a cycle.\n"); |
| 66 | path.resize(path_size); |
| 67 | for (int32 node_id : path) { |
| 68 | string ascii_art; |
| 69 | if (node_id == dst) { |
| 70 | ascii_art = "+-> "; |
| 71 | } else if (node_id != src) { |
| 72 | ascii_art = "| "; |
| 73 | } else { |
| 74 | ascii_art = "+-- "; |
| 75 | } |
| 76 | absl::StrAppend(&description, ascii_art, node_name(node_id), "\n"); |
| 77 | } |
| 78 | return description; |
| 79 | } |
| 80 | |
| 81 | bool AlwaysForwardsRefInput(const Node& node) { return node.IsIdentity(); } |
| 82 |
nothing calls this directly
no test coverage detected