Click here to Skip to main content
15,880,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to use Dijkstra's multi source algorithm to create a color map. Basically I have two source points and I want to color all nodes in the network in accordance to their distance to the 2 sources. If you can explain with only one source it will be more than enough. Can anyone help me?


In case you need it, the network was obtained through:

place = [{'city':'Lisbon', 'country':'Portugal'}]

G = ox.graph_from_place(place, network_type='drive')
G = ox.project_graph(G)

Thank you in advance.

What I have tried:

import networkx as nx
import matplotlib.pyplot as plt
import osmnx as ox
import pandas as pd
import geopandas as gpd

ox.config(log_console=True, use_cache=True)

place = {'city':'Lisbon', 'country':'Portugal'}
hospitals = ox.pois_from_place(place, amenities=['hospital'])


G = ox.load_graphml('rede_cidade_lisboa.graphml') ##network
# fig, ax = ox.plot_graph(G, node_size=7, edge_linewidth=0.5)
nodes = G.nodes
edges = G.edges

hosp_1 = (38.74817825481225, -9.160815118526642)  # Hospital Santa Maria
hosp_2 = (38.74110711410615, -9.152159572392323)  # Hospital Curry Cabral

source_1 = ox.get_nearest_node(G, hosp_1)
source_2 = ox.get_nearest_node(G, hosp_2)

for node in nodes:

   edge, path = nx.multi_source_dijkstra(node, {source_1, source_2}, weight=edges.data['length'])
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900