Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
bool SGSmallRepeatResolveVisitor::visit(StringGraph* /*pGraph*/, Vertex* pX)
{
    bool changed = false;

    // If the vertex has more than MAX_EDGES, do not
    // attempt to resolve
    size_t MAX_EDGES = 10;

    for(size_t idx = 0; idx < ED_COUNT; idx++)
    {
        EdgeDir dir = EDGE_DIRECTIONS[idx];
        EdgePtrVec x_edges = pX->getEdges(dir); // These edges are already sorted

        if(x_edges.size() < 2 || x_edges.size() > MAX_EDGES)
            continue;

        // Try to eliminate the shortest edge from this vertex (let this be X->Y)
        // If Y has a longer edge than Y->X in the same direction, we remove X->Y

        // Edges are sorted by length so the last edge is the shortest
        Edge* pXY = x_edges.back();
        size_t xy_len = pXY->getOverlap().getOverlapLength(0);
        size_t x_longest_len = x_edges.front()->getOverlap().getOverlapLength(0);
        if(xy_len == x_longest_len)
            continue;

        Edge* pYX = pXY->getTwin();
        Vertex* pY = pXY->getEnd();

        EdgePtrVec y_edges = pY->getEdges(pYX->getDir());
        if(y_edges.size() > MAX_EDGES)
            continue;

        size_t yx_len = pYX->getOverlap().getOverlapLength(0);

        size_t y_longest_len = 0;
        for(size_t i = 0; i < y_edges.size(); ++i)
        {
            Edge* pYZ = y_edges[i];
            if(pYZ == pYX)
                continue; // skip Y->X

            size_t yz_len = pYZ->getOverlap().getOverlapLength(0);
            if(yz_len > y_longest_len)
                y_longest_len = yz_len;
        }


        if(y_longest_len > yx_len)
        {
            // Delete the edge if the difference between the shortest and longest is greater than minDiff
            int x_diff = x_longest_len - xy_len;
            int y_diff = y_longest_len - yx_len;

            if(x_diff > m_minDiff && y_diff > m_minDiff)
            {
                pX->deleteEdge(pXY);
                pY->deleteEdge(pYX);
                changed = true;
            }
        }
    }

    return changed;
}