Create Dijkstra's Shortest Path with Congestion Weights
Browse files
Dijkstra's Shortest Path with Congestion Weights
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import networkx as nx
|
| 2 |
+
|
| 3 |
+
G = nx.read_graphml("campus_map.graphml")
|
| 4 |
+
|
| 5 |
+
def get_weight(u, v, data):
|
| 6 |
+
congestion_factor = data.get("predicted_congestion", 1)
|
| 7 |
+
return data['distance'] * congestion_factor
|
| 8 |
+
|
| 9 |
+
path = nx.dijkstra_path(G, source='A', target='B', weight=get_weight)
|