<filename>Proyecto_final/nx_dijkstra.py
import networkx as nx
from graph import G, cities

#st = nodo inicio
#end = nodo final
#mode = 'dist' o 'time'
def nx_dijkstra(st, end, mode):
    if mode == 'dist' or mode == 'time':
        if cities.index(st) and cities.index(end):
            path = nx.shortest_path(G, source=st, target=end, weight=mode)

            data = 0
            if len(path) < 3:
                data = G.get_edge_data(cities[0], cities[1])[mode]
            else:
                for i in range(0, len(path)-1):
                    data += G.get_edge_data(cities[i], cities[i+1])[mode]

            if mode == 'time':
                m = str(data%60)
                h = str(int(data/60))
                data = h+":"+m

            return (path, data)

#print(nx_dijkstra('Cali', 'Bucaramanga', 'time'))
<filename>Proyecto_final/nx_dijkstra.py
import networkx as nx
from graph import G, cities

#st = nodo inicio
#end = nodo final
#mode = 'dist' o 'time'
def nx_dijkstra(st, end, mode):
    if mode == 'dist' or mode == 'time':
        if cities.index(st) and cities.index(end):
            path = nx.shortest_path(G, source=st, target=end, weight=mode)

            data = 0
            if len(path) < 3:
                data = G.get_edge_data(cities[0], cities[1])[mode]
            else:
                for i in range(0, len(path)-1):
                    data += G.get_edge_data(cities[i], cities[i+1])[mode]

            if mode == 'time':
                m = str(data%60)
                h = str(int(data/60))
                data = h+":"+m

            return (path, data)

#print(nx_dijkstra('Cali', 'Bucaramanga', 'time'))
#st = nodo inicio #end = nodo final #mode = 'dist' o 'time' #print(nx_dijkstra('Cali', 'Bucaramanga', 'time'))