void StateGraph::writeDOT(const SubDigraph& T, const ArcList& F, std::ostream& out) const { out << "digraph S {" << std::endl; for (SubNodeIt v(T); v != lemon::INVALID; ++v) { out << "\t" << T.id(v) << " [label=\"(" << _x[v] << "," << _y[v] << "," << _xbar[v] << "," << _ybar[v] << ")\"]" << std::endl; } for (ArcListIt it = F.begin(); it != F.end(); ++it) { Arc st = *it; Node t = _G.target(st); out << "\t" << T.id(t) << " [label=\"(" << _x[t] << "," << _y[t] << "," << _xbar[t] << "," << _ybar[t] << ")\",color=red]" << std::endl; } for (SubArcIt a(T); a != lemon::INVALID; ++a) { out << "\t" << T.id(T.source(a)) << " -> " << T.id(T.target(a)) << std::endl; } for (ArcListIt it = F.begin(); it != F.end(); ++it) { Arc st = *it; out << "\t" << _G.id(_G.source(st)) << " -> " << _G.id(_G.target(st)) << " [color=red]" << std::endl; } out << "}" << std::endl; }
int TarjanHD::constructCondensedGraph(const Digraph& g, const DoubleArcMap& w, const NodeNodeMap& mapToOrgG, const NodeNodeMap& G2T, const ArcList& sortedArcs, const IntNodeMap& comp, const NodeSetVector& components, const NodeVector& roots, const int j, Digraph& c, DoubleArcMap& ww, NodeNodeMap& mapCToOrgG, NodeNodeMap& C2T, ArcList& newSortedArcs) { // construct the condensed graph: // each strongly connected component is collapsed into a single node, and // from the resulting sets of multiple arcs retain only those with minimum weight lemon::DynArcLookUp<Digraph> lookUpArc(c); // first construct the nodes const size_t numSCC = components.size(); NodeVector nodesOfC(numSCC, lemon::INVALID); for (size_t k = 0; k < numSCC; ++k) { Node v = nodesOfC[k] = c.addNode(); if (components[k].size() == 1) { mapCToOrgG[v] = mapToOrgG[*components[k].begin()]; C2T[v] = G2T[*components[k].begin()]; } else { mapCToOrgG[v] = lemon::INVALID; C2T[v] = roots[k]; } } // next construct the arcs: O(m) time for (ArcListIt arcIt = sortedArcs.begin(); arcIt != sortedArcs.end(); ++arcIt) { Arc a = *arcIt; Node u = g.source(a); Node v = g.target(a); Node uu = nodesOfC[comp[u]]; Node vv = nodesOfC[comp[v]]; if (uu != vv) { Arc aa = lookUpArc(uu, vv); if (aa == lemon::INVALID) { aa = c.addArc(uu, vv); newSortedArcs.push_back(aa); ww[aa] = w[a]; } #ifdef DEBUG else { assert(w[a] > ww[aa]); } #endif } } return get_i(newSortedArcs, ww, w[getArcByRank(sortedArcs, j)]); }
void StateGraph::grow(const IntPairSet& L, const StlBoolMatrix& LL, bool includeMutationEdge, SubDigraph& G, SubDigraph& T, ArcList& F, StlIntMatrix& V, Arc& mutationEdge) { if (isValid(L, LL, T, V) && mutationEdge != lemon::INVALID) { // report finalize(L, LL, T, V); // writeDOT(T, std::cout); } else { if (isValid(L, LL, T, V)) { // report finalize(L, LL, T, V); // writeDOT(T, std::cout); } ArcList FF; while (!F.empty()) { assert(!F.empty()); Arc uv = F.back(); F.pop_back(); Node u = G.source(uv); Node v = G.target(uv); int x_v = _x[v]; int y_v = _y[v]; // mutation edge => V[x_v][y_v] == 0 assert(mutationEdge == lemon::INVALID || V[x_v][y_v] == 0); assert(V[x_v][y_v] <= 1); // update V ++V[x_v][y_v]; if (_type[uv] == MUTATION) { mutationEdge = uv; } assert(T.status(u)); assert(!T.status(v)); assert(!T.status(uv)); // add uv to T T.enable(v); T.enable(uv); ArcList newF = F; // remove arcs from F for (ArcListNonConstIt it = newF.begin(); it != newF.end();) { Arc st = *it; Node s = T.source(st); Node t = T.target(st); int x_t = _x[t]; int y_t = _y[t]; if (v == t || (v != s && x_v == x_t && y_v == y_t) || (mutationEdge == uv && V[x_t][y_t] == 1)) { assert(T.status(s)); it = newF.erase(it); } else { ++it; } } // push each arc vw where w not in V(T) onto F for (SubOutArcIt vw(G, v); vw != lemon::INVALID; ++vw) { Node w = G.target(vw); if (T.status(w)) continue; int x_w = _x[w]; int y_w = _y[w]; if ((includeMutationEdge && mutationEdge == lemon::INVALID && x_v == x_w && y_v == y_w) || V[x_w][y_w] == 0) { newF.push_back(vw); } } // writeDOT(T, newF, std::cout); grow(L, LL, includeMutationEdge, G, T, newF, V, mutationEdge); G.disable(uv); if (uv == mutationEdge) { assert(includeMutationEdge); mutationEdge = lemon::INVALID; } T.disable(uv); T.disable(v); --V[x_v][y_v]; FF.push_back(uv); } for (ArcListRevIt it = FF.rbegin(); it != FF.rend(); ++it) { Arc a = *it; assert(!G.status(a)); F.push_back(*it); G.enable(a); } } }