Ejemplo n.º 1
0
def test_dfo(graph):
    search = dfo.DepthFirstOrder(graph)
    assert stack.size(search['reversepost']) == 10
    print('')
    while not stack.isEmpty(search['reversepost']):
        top = stack.pop(search['reversepost'])
        print(top)
Ejemplo n.º 2
0
def KosarajuUnicoSCC(graph, vertex):
    """
    Implementa el algoritmo de Kosaraju
    para encontrar los componentes conectados
    de un grafo dirigido
    Args:
        graph: El grafo a examinar
    Returns:
        Una estructura con los componentes
        conectados
    Raises:
        Exception
    """
    try:
        scc_u = {
            'idscc': None,
            'marked': None,
            'grmarked': None,
            'components': 0
        }

        scc_u['idscc'] = map.newMap(g.numVertices(graph),
                                    maptype='PROBING',
                                    comparefunction=graph['comparefunction'])

        scc_u['marked'] = map.newMap(g.numVertices(graph),
                                     maptype='PROBING',
                                     comparefunction=graph['comparefunction'])
        scc_u['grmarked'] = map.newMap(
            g.numVertices(graph),
            maptype='PROBING',
            comparefunction=graph['comparefunction'])

        # Se calcula el grafo reverso de graph
        greverse = reverseGraph(graph)

        # Se calcula el DFO del reverso de graph
        dforeverse = dfo.DepthFirstOrder(greverse)
        grevrevpost = dforeverse['reversepost']

        # Se recorre el grafo en el orden dado por reversepost (G-reverso)
        scc_u['components'] = 0
        while (not stack.isEmpty(grevrevpost)):
            vert = stack.pop(grevrevpost)
            if vert == str(vertex):
                if not map.contains(scc_u['marked'], vert):
                    scc_u['components'] += 1
                    sccCount(graph, scc_u, vert)
        return scc_u
    except Exception as exp:
        error.reraise(exp, 'scc_u:Kosaraju')
Ejemplo n.º 3
0
def vertexNamesAge(grafo):
    N = dfo.DepthFirstOrder(grafo)
    return N["pre"]
Ejemplo n.º 4
0
def vertexNames(analyzer):
    N = dfo.DepthFirstOrder(analyzer["graph"])
    return N["pre"]