Maps / Dijkstra's Shortest Path with Congestion Weights
BoojithDharshan's picture
Create Dijkstra's Shortest Path with Congestion Weights
52eca97 verified
import networkx as nx
G = nx.read_graphml("campus_map.graphml")
def get_weight(u, v, data):
congestion_factor = data.get("predicted_congestion", 1)
return data['distance'] * congestion_factor
path = nx.dijkstra_path(G, source='A', target='B', weight=get_weight)