Esempio n. 1
0
if __name__ ==  "__main__" :
    graph = g.newGraph(7,comparenames,True)

    g.insertVertex (graph, 'Bogota')
    g.insertVertex (graph, 'Yopal')
    g.insertVertex (graph, 'Cali')
    g.insertVertex (graph, 'Medellin')
    g.insertVertex (graph, 'Pasto')
    g.insertVertex (graph, 'Barranquilla')
    g.insertVertex (graph, 'Manizales')
    
    g.insertVertex (graph, 'Cucuta')
    g.insertVertex (graph, 'Bucaramanga')


    g.addEdge (graph, 'Bogota', 'Yopal', 1 )
    g.addEdge (graph, 'Bogota', 'Medellin', 1 )
    g.addEdge (graph, 'Bogota', 'Pasto', 1 )
    g.addEdge (graph, 'Bogota', 'Cali', 1 )
    g.addEdge (graph, 'Yopal', 'Medellin', 1 )
    g.addEdge (graph, 'Medellin', 'Pasto', 1 )
    g.addEdge (graph, 'Cali', 'Pasto', 1 )
    g.addEdge (graph, 'Cali', 'Barranquilla', 1 )
    g.addEdge (graph, 'Barranquilla','Manizales', 1 )
    g.addEdge (graph, 'Pasto','Manizales', 1 )
    g.addEdge (graph, 'Cucuta','Bucaramanga', 1 )

    search = newDFS(graph,'Bogota')
    
    print ('A Cali', hasPathTo(search, 'Cali'))
    print ('A Cucuta', hasPathTo(search,'Cucuta'))
Esempio n. 2
0
def addEdge(graph, vertexa, vertexb, weight):
    """
    Agrega un arco entre los vertices vertexa ---- vertexb, con peso weight
    """
    if (graph['type'] == "ADJ_LIST"):
        return alt.addEdge(graph, vertexa, vertexb, weight)