def addEdge(graph, vertexa, vertexb, weight=0):
    """
    Agrega un arco entre los vertices vertexa ---- vertexb, con peso weight.
    Si el grafo es no dirigido se adiciona dos veces el mismo arco,
    en el mismo orden
    Si el grafo es dirigido se adiciona solo el arco vertexa --> vertexb

    Args:
        graph: El grafo sobre el que se ejecuta la operacion
        vertexa: Vertice de inicio
        vertexb: Vertice de destino
        wight: peso del arco

    Returns:
       El grafo con el nuevo arco
    Raises:
        Exception
    """
    try:
        # Se crea el arco
        edge = e.newEdge(vertexa, vertexb, weight)
        # Se obtienen las listas de adyacencias de cada vertice
        # Se anexa a cada lista el arco correspondiente
        entrya = map.get(graph['vertices'], vertexa)
        lt.addLast(entrya['value'], edge)
        if (not graph['directed']):
            entryb = map.get(graph['vertices'], vertexb)
            lt.addLast(entryb['value'], edge)
        else:
            degree = map.get(graph['indegree'], vertexb)
            map.put(graph['indegree'], vertexb, degree['value'] + 1)
        graph['edges'] += 1
        return graph
    except Exception as exp:
        error.reraise(exp, 'ajlist:addedge')
Exemple #2
0
def test_edgeMethods(graph):
    edge = e.newEdge('Bogota', 'Cali')
    assert 'Bogota' == e.either(edge)
    assert 'Cali' == e.other(edge, e.either(edge))
    assert e.weight(edge) == 0
def test_newEdge():
    edge = e.newEdge(1, 1, 1)
    assert edge is not None