// Recursive call for testing c-planarity of the clustered graph // that is induced by cluster act bool CconnectClusterPlanar::planarityTest(ClusterGraph &C, cluster &act, Graph &G) { // Test children first ListConstIterator<cluster> it; for (it = act->cBegin(); it.valid();) { ListConstIterator<cluster> succ = it.succ(); cluster next = (*it); if (!planarityTest(C,next,G)) return false; it = succ; } // Get induced subgraph of cluster act and test it for planarity List<node> subGraphNodes; ListIterator<node> its; for (its = act->nBegin(); its.valid(); its++) subGraphNodes.pushBack(*its); Graph subGraph; NodeArray<node> table; inducedSubGraph(G,subGraphNodes.begin(),subGraph,table); // Introduce super sink and add edges corresponding // to outgoing edges of the cluster node superSink = subGraph.newNode(); EdgeArray<node> outgoingTable(subGraph,0); for (its = act->nBegin(); its.valid(); its++) { node w = (*its); adjEntry adj = w->firstAdj(); forall_adj(adj,w) { edge e = adj->theEdge(); edge cor = 0; if (table[e->source()] == 0) // edge is connected to a node outside the cluster { cor = subGraph.newEdge(table[e->target()],superSink); outgoingTable[cor] = e->source(); } else if (table[e->target()] == 0) // dito { cor = subGraph.newEdge(table[e->source()],superSink); outgoingTable[cor] = e->target(); } // else edge connects two nodes of the cluster } }
static void writeCluster( std::ostream &out, int depth, const ClusterArray < std::vector<edge> > &edgeMap, const ClusterGraph &C, const ClusterGraphAttributes *CA, const cluster &c, int &clusterId) { if(C.rootCluster() == c) { writeHeader(out, depth++, CA); } else { GraphIO::indent(out, depth++) << "subgraph cluster" << clusterId << " {\n"; } clusterId++; bool whitespace; // True if a whitespace should printed (readability). whitespace = false; if(CA) { writeAttributes(out, depth, *CA, c); whitespace = true; } if(whitespace) { out << "\n"; } // Recursively export all subclusters. whitespace = false; for(ListConstIterator<cluster> cit = c->cBegin(); cit.valid(); ++cit) { writeCluster(out, depth, edgeMap, C, CA, *cit, clusterId); whitespace = true; } if(whitespace) { out << "\n"; } // Then, print all nodes whithout an adjacent edge. whitespace = false; for(ListConstIterator<node> nit = c->nBegin(); nit.valid(); ++nit) { whitespace |= writeNode(out, depth, CA, *nit); } if(whitespace) { out << "\n"; } // Finally, we print all edges for this cluster (ugly version for now). const std::vector<edge> &edges = edgeMap[c]; whitespace = false; for(size_t i = 0; i < edges.size(); i++) { whitespace |= writeEdge(out, depth, CA, edges[i]); } GraphIO::indent(out, --depth) << "}\n"; }
//returns list of all clusters in subtree at c in bottom up order void MaximumCPlanarSubgraph::getBottomUpClusterList(const cluster c, List< cluster > & theList) { ListConstIterator<cluster> it = c->cBegin(); while (it.valid()) { getBottomUpClusterList((*it), theList); it++; } theList.pushBack(c); }
void ClusterGraphCopy::createClusterTree(cluster cOrig) { cluster c = m_copy[cOrig]; ListConstIterator<cluster> itC; for(itC = cOrig->cBegin(); itC.valid(); ++itC) { cluster child = newCluster(c); m_copy [*itC] = child; m_original[child] = *itC; createClusterTree(*itC); } ListConstIterator<node> itV; for(itV = cOrig->nBegin(); itV.valid(); ++itV) { reassignNode(m_pH->copy(*itV), c); } }
static void writeCluster( std::ostream &out, int depth, const ClusterGraph &C, const ClusterGraphAttributes *CA, cluster c) { if(C.rootCluster() != c) { GraphIO::indent(out, depth) << "<node " << "id=\"cluster" << c->index() << "\"" << ">\n"; } else { const std::string dir = (CA && !CA->directed()) ? "undirected" : "directed"; GraphIO::indent(out, depth) << "<graph " << "mode=\"static\"" << "defaultedgetype=\"" << dir << "\"" << ">\n"; if(CA) { defineAttributes(out, depth + 1, *CA); } } GraphIO::indent(out, depth + 1) << "<nodes>\n"; for(ListConstIterator<cluster> cit = c->cBegin(); cit.valid(); ++cit) { writeCluster(out, depth + 2, C, CA, *cit); } for(ListConstIterator<node> nit = c->nBegin(); nit.valid(); ++nit) { writeNode(out, depth + 2, CA, *nit); } GraphIO::indent(out, depth + 1) << "</nodes>\n"; if(C.rootCluster() != c) { GraphIO::indent(out, depth) << "</node>\n"; } else { writeEdges(out, C.constGraph(), CA); GraphIO::indent(out, depth) << "</graph>\n"; } }
// Recursive call for testing c-planarity of the clustered graph // that is induced by cluster act bool CconnectClusterPlanar::planarityTest( ClusterGraph &C, cluster &act, Graph &G) { // Test children first ListConstIterator<cluster> it; for (it = act->cBegin(); it.valid();) { ListConstIterator<cluster> succ = it.succ(); cluster next = (*it); if (!planarityTest(C,next,G)) return false; it = succ; } // Get induced subgraph of cluster act and test it for planarity List<node> subGraphNodes; for (node s : act->nodes) subGraphNodes.pushBack(s); Graph subGraph; NodeArray<node> table; inducedSubGraph(G,subGraphNodes.begin(),subGraph,table); // Introduce super sink and add edges corresponding // to outgoing edges of the cluster node superSink = subGraph.newNode(); EdgeArray<node> outgoingTable(subGraph,nullptr); for (node w : act->nodes) { //adjEntry adj = w->firstAdj(); for(adjEntry adj : w->adjEntries) { edge e = adj->theEdge(); edge cor = nullptr; if (table[e->source()] == nullptr) // edge is connected to a node outside the cluster { cor = subGraph.newEdge(table[e->target()],superSink); outgoingTable[cor] = e->source(); } else if (table[e->target()] == nullptr) // dito { cor = subGraph.newEdge(table[e->source()],superSink); outgoingTable[cor] = e->target(); } // else edge connects two nodes of the cluster } } if (superSink->degree() == 0) // root cluster is not connected to outside clusters { subGraph.delNode(superSink); superSink = nullptr; } bool cPlanar = preparation(subGraph,act,superSink); if (cPlanar && act != C.rootCluster()) { // Remove induced subgraph and the cluster act. // Replace it by a wheel graph while (!subGraphNodes.empty()) { node w = subGraphNodes.popFrontRet(); // C.unassignNode(w); G.delNode(w); } cluster parent = act->parent(); if (superSink && m_clusterPQTree[act]) constructWheelGraph(C,G,parent,m_clusterPQTree[act],outgoingTable); C.delCluster(act); if (m_clusterPQTree[act] != nullptr) // if query necessary for clusters with just one child { m_clusterPQTree[act]->emptyAllPertinentNodes(); delete m_clusterPQTree[act]; } } else if (!cPlanar) { m_errorCode = nonCPlanar; }//if not cplanar return cPlanar; }