def edges(graph):
    """
    Retorna una lista con todos los arcos del grafo graph

    Args:
        graph: El grafo sobre el que se ejecuta la operacion

    Returns:
        Una lista con los arcos del grafo
    Raises:
        Exception
    """
    try:
        lstmap = map.valueSet(graph['vertices'])
        itervertex = it.newIterator(lstmap)
        lstresp = lt.newList('SINGLE_LINKED', e.compareedges)
        while it.hasNext(itervertex):
            lstedge = it.next(itervertex)
            iteredge = it.newIterator(lstedge)
            while (it.hasNext(iteredge)):
                edge = it.next(iteredge)
                if (graph['directed']):
                    lt.addLast(lstresp, edge)
                elif (not lt.isPresent(lstresp, edge)):
                    lt.addLast(lstresp, edge)
        return lstresp
    except Exception as exp:
        error.reraise(exp, 'ajlist:edges')
Exemple #2
0
def put(map, key, value):
    """ Ingresa una pareja llave,valor a la tabla de hash.
    Si la llave ya existe en la tabla, se reemplaza el valor

    Args:
        map: El map a donde se guarda la pareja
        key: la llave asociada a la pareja
        value: el valor asociado a la pareja
    Returns:
        El map
    Raises:
        Exception
    """
    if map['ints']:
        hashv = key % map['capacity']
    else:
        hashv = hashValue(map, key)
    bucket = lt.getElement(map['table'], hashv)
    entry = me.newMapEntry(key, value)
    pos = lt.isPresent(bucket, key)
    if pos > 0:    # La pareja ya exista, se reemplaza el valor
        lt.changeInfo(bucket, pos, entry)
    else:
        lt.addLast(bucket, entry)   # La llave no existia
        map['size'] += 1
    return map
Exemple #3
0
def dfsVertexCycles(search, graph, vertex, vertex1):
    try:
        adjlst = g.adjacents(graph, vertex)
        adjslstiter = it.newIterator(adjlst)

        pos = lt.isPresent(adjlst, vertex1)  # Posición del vértice fijo
        fixed_edge = lt.getElement(
            adjlst,
            pos)  # Elemento que contiene el vértice dentro de la adjlst

        totalcycles = 0  # Inicio contador
        path = {}

        while (it.hasNext(adjslstiter)):
            w = it.next(adjslstiter)  # entro al vertice a analizar
            visited = map.get(search['visited'],
                              w)  # Pido la entrada en el mapa de los marcados
            if visited is None:
                map.put(search['visited'], w, {
                    'marked': True,
                    'edgeTo': vertex
                })
                dfsVertex(search, graph, w)
                path[w] = vertex
            elif visited == fixed_edge:
                totalcycles += 1
                print(path)
                path = {}

        search['total'] = totalcycles

        return search
    except Exception as exp:
        error.reraise(exp, 'dfs:dfsVertex')
Exemple #4
0
def removeEdge(graph, vertexa, timeSt, timeEnd, cmp):
    try:
        entrya = map.get(graph['vertices'], vertexa)
        iterador = it.newIterator(entrya["value"])
        entrya["value"]["cmpfunction"] = cmp
        while it.hasNext(iterador):
            dato = it.next(iterador)
            num = lt.isPresent(entrya["value"], dato)
            if num != 0:
                if dato["timeStart"] < timeSt or dato["timeEnd"] > timeEnd:
                    lt.deleteElement(entrya["value"], num)
                    graph['edges'] -= 1
        return graph
    except Exception as exp:
        error.reraise(exp, 'ajlist:removeedge')
Exemple #5
0
def get(map, key):
    """ Retorna la pareja llave, valor, cuya llave sea igual a key
    Args:
        map: El map a donde se guarda la pareja
        key: la llave asociada a la pareja

    Returns:
        Una pareja <llave,valor>
    Raises:
        Exception
    """
    hash = hashValue(map, key)
    bucket = lt.getElement(map['table'], hash)
    pos = lt.isPresent(bucket, key)
    if pos > 0:
        return lt.getElement(bucket, pos)
    else:
        return None
Exemple #6
0
def contains(map, key):
    """ Retorna True si la llave key se encuentra en el map
        o False en caso contrario.
    Args:
        map: El map a donde se guarda la pareja
        key: la llave asociada a la pareja

    Returns:
        True / False
    Raises:
        Exception
    """
    hash = hashValue(map, key)
    bucket = lt.getElement(map['table'], hash)
    pos = lt.isPresent(bucket, key)
    if pos > 0:
        return True
    else:
        return False
Exemple #7
0
def isPresent(lst, element):
    """ Informa si el elemento element esta presente en la lista. 
    
    Informa si un elemento está en la lista.  Si esta presente, retorna la posición en la que se encuentra 
    o cero (0) si no esta presente. Se utiliza la función de comparación utilizada durante la creación 
    de la lista para comparar los elementos.

    Args:
        lst: La lista a examinar
        element: El elemento a buscar
    Returns:     
        
    Raises:
        Exception
    """
    try:
        return lt.isPresent(lst, element)
    except Exception as exp:
        error.reraise(exp, 'TADList->isPresent: ')
Exemple #8
0
def remove(map, key):
    """ Elimina la pareja llave,valor, donde llave == key.
    Args:
        map: El map a donde se guarda la pareja
        key: la llave asociada a la pareja

    Returns:
        El map
    Raises:
        Exception
    """
    hash = hashValue(map, key)
    bucket = lt.getElement(map['table'], hash)
    pos = lt.isPresent(bucket, key)
    if pos > 0:
        lt.deleteElement(bucket, pos)
        map['size'] -= 1
        return map
    else:
        return None