// // Flip a vertex // void Bigraph::flip(VertexID /*id*/) { assert(false); #if 0 // TODO: update this code Vertex* pVertex = getVertex(id); EdgePtrVec edges = pVertex->getEdges(); for(EdgePtrVecIter iter = edges.begin(); iter != edges.end(); ++iter) { // Get the old twin GraphEdgeType twin = iter->getTwin(); GraphEdgeType flipped = *iter; flipped.flip(); // Remove the edge from the source ver pVertex->removeEdge(*iter); pVertex->addEdge(flipped); // Update the partner by deleting the old twin and Vertex* pV2 = getVertex(twin.getStart()); pV2->removeEdge(twin); pV2->addEdge(flipped.getTwin()); } #endif }
// // Merge two vertices along the specified edge // void Bigraph::merge(Vertex* pV1, Edge* pEdge) { Vertex* pV2 = pEdge->getEnd(); //std::cout << "Merging " << pV1->getID() << " with " << pV2->getID() << "\n"; // Merge the data pV1->merge(pEdge); // Get the twin edge (the edge in v2 that points to v1) Edge* pTwin = pEdge->getTwin(); // Ensure v2 has the twin edge assert(pV2->hasEdge(pTwin)); // Get the edge set opposite of the twin edge (which will be the new edges in this direction for V1) EdgePtrVec transEdges = pV2->getEdges(!pTwin->getDir()); // Move the edges from pV2 to pV1 for(EdgePtrVecIter iter = transEdges.begin(); iter != transEdges.end(); ++iter) { Edge* pTransEdge = *iter; // Remove the edge from V2, this does not destroy the edge pV2->removeEdge(pTransEdge); // Join pEdge to the start of transEdge // This updates the starting point of pTransEdge to be V1 // This calls Edge::extend on the twin edge pTransEdge->join(pEdge); assert(pTransEdge->getDir() == pEdge->getDir()); pV1->addEdge(pTransEdge); // add to V1 // Notify the edges they have been updated pTransEdge->update(); pTransEdge->getTwin()->update(); } // Remove the edge from pV1 to pV2 pV1->removeEdge(pEdge); delete pEdge; pEdge = 0; // Remove the edge from pV2 to pV1 pV2->removeEdge(pTwin); delete pTwin; pEdge = 0; // Remove V2 // It is guarenteed to not be connected removeIslandVertex(pV2); //validate(); }
bool SGMaximalOverlapVisitor::visit(StringGraph* /*pGraph*/, Vertex* pVertex) { bool modified = false; typedef bool(*PredicateEdge)(const Edge*); PredicateEdge predicateEdgeArray[ED_COUNT] = {SGMaximalOverlapVisitor::isSenseEdge, SGMaximalOverlapVisitor::isAntiSenseEdge}; for(size_t idx = 0; idx < ED_COUNT; idx++) { EdgeDir dir = EDGE_DIRECTIONS[idx]; EdgePtrVec edges = pVertex->getEdges(dir); // These edges are already sorted by overlap length if(edges.empty()) continue; //return false; for(size_t i = 1; i < edges.size(); ++i) { if (edges[i]->getMatchLength() == edges[0]->getMatchLength()) continue; bool valid = false; //EdgePtrVec redges = edges[i]->getEnd()->getEdges(EDGE_DIRECTIONS[ED_COUNT - idx - 1]); EdgePtrVec redges = edges[i]->getEnd()->getEdges(); EdgePtrVec::iterator last = std::remove_if(redges.begin(), redges.end(), predicateEdgeArray[idx]); redges.resize(std::distance(redges.begin(), last)); assert(!redges.empty()); for(size_t j = 0; j < redges.size(); ++j) { if (redges[j]->getEndID() == pVertex->getID() && edges[0]->getMatchLength() - edges[i]->getMatchLength() <= _delta) { valid = true; } } if (!valid) { edges[i]->setColor(GC_BLACK); edges[i]->getTwin()->setColor(GC_BLACK); modified = true; } } } return modified; }
bool SGContainRemoveVisitor::visit(StringGraph* pGraph, Vertex* pVertex) { if(!pVertex->isContained()) return false; //cout << pVertex->getID() << endl; // debug // Add any new irreducible edges that exist when pToRemove is deleted // from the graph EdgePtrVec neighborEdges = pVertex->getEdges(); // If the graph has been transitively reduced, we have to check all // the neighbors to see if any new edges need to be added. If the graph is a // complete overlap graph we can just remove the edges to the deletion vertex if(!pGraph->hasTransitive() && !pGraph->isExactMode()) { // This must be done in order of edge length or some transitive edges // may be created EdgeLenComp comp; std::sort(neighborEdges.begin(), neighborEdges.end(), comp); for(size_t j = 0; j < neighborEdges.size(); ++j) { Vertex* pRemodelVert = neighborEdges[j]->getEnd(); Edge* pRemodelEdge = neighborEdges[j]->getTwin(); SGAlgorithms::remodelVertexForExcision(pGraph, pRemodelVert, pRemodelEdge); } } // Delete the edges from the graph for(size_t j = 0; j < neighborEdges.size(); ++j) { Vertex* pRemodelVert = neighborEdges[j]->getEnd(); Edge* pRemodelEdge = neighborEdges[j]->getTwin(); pRemodelVert->deleteEdge(pRemodelEdge); pVertex->deleteEdge(neighborEdges[j]); } pVertex->setColor(GC_BLACK); return false; }
// Construct the walk structure from a vector of edges SGWalk::SGWalk(const EdgePtrVec& edgeVec, bool bIndexWalk) : m_extensionDistance(0), m_extensionFinished(false) { assert(!edgeVec.empty()); if(bIndexWalk) m_pWalkIndex = new WalkIndex; else m_pWalkIndex = NULL; // The start vector is the start vertex of the first edge Edge* first = edgeVec.front(); m_pStartVertex = first->getStart(); for(EdgePtrVec::const_iterator iter = edgeVec.begin(); iter != edgeVec.end(); ++iter) { addEdge(*iter); } }