我从OSMNX获取了一个网络,并试图检查更改边的属性(即one_way
属性)是否会更改我在计算一个节点与网络其余部分之间的所有最短路径时获得的结果
但是在测试之后,我注意到,即使我洗牌了属性的值,结果也是一样的。换句话说,最短路径的长度从未改变
我从构建网络和创建GeodataFrame开始:
import osmnx as ox
import igraph as ig
import networkx as nx
ox.config(log_console=True, use_cache=True)
cities = ox.geocode_to_gdf(['Município de Lisboa', 'Município de Oeiras', 'Município da Amadora', 'Município de Loures', 'Município de Odivelas'])
whole_polygon = cities.unary_union #unary union of both geometries
city_pol = cities['geometry'].iloc[0] #geometry of just the city
G_1 = ox.graph_from_polygon(city_pol, network_type='drive', simplify=True)
nodes_1, edges_1 = ox.graph_to_gdfs(G_1, nodes=True, edges=True)
G = ox.graph_from_polygon(whole_polygon, network_type='drive', simplify=True)
G_nx = nx.relabel.convert_node_labels_to_integers(G)
nodes, edges = ox.graph_to_gdfs(G_nx, nodes=True, edges=True)
然后将边按单向属性洗牌:
edges['oneway'] = np.random.permutation(edges['oneway'].values)
创建了一个igraph:
weight = 'length'
G_ig = ig.Graph(directed=True)
G_ig.add_vertices(list(G_nx.nodes()))
G_ig.add_edges(list(G_nx.edges()))
G_ig.vs['osmid'] = list(nx.get_node_attributes(G_nx, 'osmid').values())
G_ig.es[weight] = list(nx.get_edge_attributes(G_nx, weight).values())
最后计算路径的长度:
len_path = G_ig.shortest_paths(origin, target, weight = 'length)[0][0]
这个len_path
在一个循环内,循环遍历网络中的所有节点。请注意,原点是相同的,每次迭代中发生的更改都是目标
为什么我得到的结果与我计算最短路径时得到的结果相同,而不洗牌one_way
属性
目前没有回答
相关问题 更多 >
编程相关推荐