Вы находитесь на странице: 1из 6

template <typename AuxGraph, typename AuxEmbeddingMap> void drawing(const AuxGraph& graph, const AuxEmbeddingMap& next, PointMap& point_map) { TEMPLATE_GRAPH_TYPEDEFS(AuxGraph);

typename AuxGraph::template ArcMap<Arc> prev(graph); for (NodeIt n(graph); n != INVALID; ++n) { Arc e = OutArcIt(graph, n); Arc p = e, l = e; e = next[e]; while (e != l) { prev[e] = p; p = e; e = next[e]; } prev[e] = p; } Node anode, bnode, cnode; { Arc e anode bnode cnode } IterableBoolMap<AuxGraph, Node> proper(graph, false); typename AuxGraph::template NodeMap<int> conn(graph, -1); conn[anode] = conn[bnode] = -2; { for (OutArcIt e(graph, anode); e != INVALID; ++e) { Node m = graph.target(e); if (conn[m] == -1) { conn[m] = 1; } } conn[cnode] = 2; for (OutArcIt e(graph, bnode); e != INVALID; ++e) { Node m = graph.target(e); 1 = = = = ArcIt(graph); graph.source(e); graph.target(e); graph.target(next[graph.oppositeArc(e)]);

if (conn[m] == -1) { conn[m] = 1; } else if (conn[m] != -2) { conn[m] += 1; Arc pe = graph.oppositeArc(e); if (conn[graph.target(next[pe])] == -2) { conn[m] -= 1; } if (conn[graph.target(prev[pe])] == -2) { conn[m] -= 1; } proper.set(m, conn[m] == 1); } } }

typename AuxGraph::template ArcMap<int> angle(graph, -1); while (proper.trueNum() != 0) { Node n = typename IterableBoolMap<AuxGraph, Node>::TrueIt(proper); proper.set(n, false); conn[n] = -2; for (OutArcIt e(graph, n); e != INVALID; ++e) { Node m = graph.target(e); if (conn[m] == -1) { conn[m] = 1; } else if (conn[m] != -2) { conn[m] += 1; Arc pe = graph.oppositeArc(e); if (conn[graph.target(next[pe])] == -2) { conn[m] -= 1; } if (conn[graph.target(prev[pe])] == -2) { conn[m] -= 1; } proper.set(m, conn[m] == 1); } } { Arc e = OutArcIt(graph, n); Arc p = e, l = e; 2

e = next[e]; while (e != l) { if (conn[graph.target(e)] == -2 && conn[graph.target(p)] == -2) { Arc f = e; angle[f] = 0; f = next[graph.oppositeArc(f)]; angle[f] = 1; f = next[graph.oppositeArc(f)]; angle[f] = 2; } p = e; e = next[e]; } if (conn[graph.target(e)] == -2 && conn[graph.target(p)] == -2) { Arc f = e; angle[f] = 0; f = next[graph.oppositeArc(f)]; angle[f] = 1; f = next[graph.oppositeArc(f)]; angle[f] = 2; } } } typename AuxGraph::template NodeMap<Node> apred(graph, INVALID); typename AuxGraph::template NodeMap<Node> bpred(graph, INVALID); typename AuxGraph::template NodeMap<Node> cpred(graph, INVALID); typename AuxGraph::template NodeMap<int> apredid(graph, -1); typename AuxGraph::template NodeMap<int> bpredid(graph, -1); typename AuxGraph::template NodeMap<int> cpredid(graph, -1); for (ArcIt e(graph); e != INVALID; ++e) { if (angle[e] == angle[next[e]]) { switch (angle[e]) { case 2: apred[graph.target(e)] = graph.source(e); apredid[graph.target(e)] = graph.id(graph.source(e)); break; case 1: bpred[graph.target(e)] = graph.source(e); bpredid[graph.target(e)] = graph.id(graph.source(e)); 3

break; case 0: cpred[graph.target(e)] = graph.source(e); cpredid[graph.target(e)] = graph.id(graph.source(e)); break; } } } cpred[anode] = INVALID; cpred[bnode] = INVALID; std::vector<Node> aorder, border, corder; { typename AuxGraph::template NodeMap<bool> processed(graph, false); std::vector<Node> st; for (NodeIt n(graph); n != INVALID; ++n) { if (!processed[n] && n != bnode && n != cnode) { st.push_back(n); processed[n] = true; Node m = apred[n]; while (m != INVALID && !processed[m]) { st.push_back(m); processed[m] = true; m = apred[m]; } while (!st.empty()) { aorder.push_back(st.back()); st.pop_back(); } } } } { typename AuxGraph::template NodeMap<bool> processed(graph, false); std::vector<Node> st; for (NodeIt n(graph); n != INVALID; ++n) { if (!processed[n] && n != cnode && n != anode) { st.push_back(n); processed[n] = true; Node m = bpred[n]; while (m != INVALID && !processed[m]) { st.push_back(m); processed[m] = true; 4

m = bpred[m]; } while (!st.empty()) { border.push_back(st.back()); st.pop_back(); } } } } { typename AuxGraph::template NodeMap<bool> processed(graph, false); std::vector<Node> st; for (NodeIt n(graph); n != INVALID; ++n) { if (!processed[n] && n != anode && n != bnode) { st.push_back(n); processed[n] = true; Node m = cpred[n]; while (m != INVALID && !processed[m]) { st.push_back(m); processed[m] = true; m = cpred[m]; } while (!st.empty()) { corder.push_back(st.back()); st.pop_back(); } } } } typename AuxGraph::template NodeMap<int> atree(graph, 0); for (int i = aorder.size() - 1; i >= 0; --i) { Node n = aorder[i]; atree[n] = 1; for (OutArcIt e(graph, n); e != INVALID; ++e) { if (apred[graph.target(e)] == n) { atree[n] += atree[graph.target(e)]; } } } typename AuxGraph::template NodeMap<int> btree(graph, 0); for (int i = border.size() - 1; i >= 0; --i) { Node n = border[i]; btree[n] = 1; 5

for (OutArcIt e(graph, n); e != INVALID; ++e) { if (bpred[graph.target(e)] == n) { btree[n] += btree[graph.target(e)]; } } } typename AuxGraph::template NodeMap<int> apath(graph, 0); apath[bnode] = apath[cnode] = 1; typename AuxGraph::template NodeMap<int> apath_btree(graph, 0); apath_btree[bnode] = btree[bnode]; for (int i = 1; i < int(aorder.size()); ++i) { Node n = aorder[i]; apath[n] = apath[apred[n]] + 1; apath_btree[n] = btree[n] + apath_btree[apred[n]]; } typename AuxGraph::template NodeMap<int> bpath_atree(graph, 0); bpath_atree[anode] = atree[anode]; for (int i = 1; i < int(border.size()); ++i) { Node n = border[i]; bpath_atree[n] = atree[n] + bpath_atree[bpred[n]]; } typename AuxGraph::template NodeMap<int> cpath(graph, 0); cpath[anode] = cpath[bnode] = 1; typename AuxGraph::template NodeMap<int> cpath_atree(graph, 0); cpath_atree[anode] = atree[anode]; typename AuxGraph::template NodeMap<int> cpath_btree(graph, 0); cpath_btree[bnode] = btree[bnode]; for (int i = 1; i < int(corder.size()); ++i) { Node n = corder[i]; cpath[n] = cpath[cpred[n]] + 1; cpath_atree[n] = atree[n] + cpath_atree[cpred[n]]; cpath_btree[n] = btree[n] + cpath_btree[cpred[n]]; } typename AuxGraph::template NodeMap<int> third(graph); for (NodeIt n(graph); n != INVALID; ++n) { point_map[n].x = bpath_atree[n] + cpath_atree[n] - atree[n] - cpath[n] + 1; point_map[n].y = cpath_btree[n] + apath_btree[n] - btree[n] - apath[n] + 1; } } 6

Вам также может понравиться