python disable path length_Python networkx.shortest_path_length方法代码示例
本文整理汇总了Python中networkx.shortest_path_length方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.shortest_path_length方法的具体用法?Python networkx.shortest_path_length怎么用?Python networkx.shortest_path_length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块networkx的用法示例。
在下文中一共展示了networkx.shortest_path_length方法的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: calculate_max_depth_over_max_width
点赞 6
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def calculate_max_depth_over_max_width(comment_tree):
comment_tree_nx = nx.from_scipy_sparse_matrix(comment_tree, create_using=nx.Graph())
if len(comment_tree_nx) == 0:
max_depth_over_max_width = 0.0
else:
node_to_depth = nx.shortest_path_length(comment_tree_nx, 0)
depth_to_nodecount = collections.defaultdict(int)
for k, v in node_to_depth.items():
depth_to_nodecount[v] += 1
max_depth = max(node_to_depth.values())
max_width = max(depth_to_nodecount.values())
max_depth_over_max_width = max_depth/max_width
return max_depth_over_max_width
开发者ID:MKLab-ITI,项目名称:news-popularity-prediction,代码行数:20,
示例2: calculate_comment_tree_hirsch
点赞 6
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def calculate_comment_tree_hirsch(comment_tree):
comment_tree_nx = nx.from_scipy_sparse_matrix(comment_tree, create_using=nx.Graph())
if len(comment_tree_nx) == 0:
comment_tree_hirsch = 0.0
else:
node_to_depth = nx.shortest_path_length(comment_tree_nx, 0)
depth_to_nodecount = collections.defaultdict(int)
for k, v in node_to_depth.items():
depth_to_nodecount[v] += 1
comment_tree_hirsch = max(node_to_depth.values())
while True:
if depth_to_nodecount[comment_tree_hirsch] >= comment_tree_hirsch:
break
else:
comment_tree_hirsch -= 1
return comment_tree_hirsch
开发者ID:MKLab-ITI,项目名称:news-popularity-prediction,代码行数:23,
示例3: get_topic_distance
点赞 6
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def get_topic_distance(self, sg, topic):
"""
:param sg: an egocentric subgraph in networkx format
:param topic: a networkx graph of nodes representing the topic
:return: a dictionary of key node name and value distance as integer
"""
distances = dict()
# get all the distances
for tnode in topic.nodes():
if tnode in sg.nodes():
distances[tnode] = nx.shortest_path_length(sg, source=tnode)
# get the smallest distance per key
min_dist = dict()
for key in distances:
for node in distances[key]:
if node not in min_dist:
min_dist[node] = distances[key][node]
elif distances[key][node] < min_dist[node]:
min_dist[node] = distances[key][node]
# Return the dict
return min_dist
开发者ID:vz-risk,项目名称:Verum,代码行数:27,
示例4: add_cycle_edges_by_path
点赞 6
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def add_cycle_edges_by_path(g,number_of_edges,path_length = 5):
number = 0
num_nodes = g.number_of_nodes()
nodes = g.nodes()
extra_edges = []
while number < number_of_edges:
u,v = np.random.randint(0,num_nodes,2)
u = nodes[u]
v = nodes[v]
if nx.has_path(g,u,v):
length = nx.shortest_path_length(g,source = u,target = v)
if length <= path_length:
extra_edges.append((v,u))
number += 1
if nx.has_path(g,v,u):
length = nx.shortest_path_length(g,source = v,target = u)
if length <= path_length:
extra_edges.append((u,v))
number += 1
print("# extra edges added with path length <= %d: %d" % (path_length,len(extra_edges)))
return extra_edges
开发者ID:zhenv5,项目名称:breaking_cycles_in_noisy_hierarchies,代码行数:23,
示例5: distance
点赞 6
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def distance(self, type, node1, node2):
if node1 in self.Dual[type].nodes() and node2 in self.Dual[type].nodes():
return nx.shortest_path_length(self.Dual[type], node1, node2)
elif node1 in self.Dual[type].nodes() and node2 not in self.Dual[type].nodes():
node2 = self.External[type][node2]['measure']
return nx.shortest_path_length(self.Dual[type], node1, node2) + 1
elif node1 not in self.Dual[type].nodes() and node2 in self.Dual[type].nodes():
node1 = self.External[type][node1]['measure']
return nx.shortest_path_length(self.Dual[type], node1, node2) + 1
else:
node1 = self.External[type][node1]['measure']
node2 = self.External[type][node2]['measure']
return nx.shortest_path_length(self.Dual[type], node1, node2) + 2
# Re-initializes Measurement qubits
开发者ID:jacobmarks,项目名称:QTop,代码行数:18,
示例6: dendritic_graph
点赞 6
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def dendritic_graph(self):
"""
Builds skeleton of the topological representation (used internally)
"""
diam = networkx.diameter(self.gl)
g3 = networkx.Graph()
dicdend = {}
for n in range(diam-1):
nodedist = []
for k in self.pl:
dil = networkx.shortest_path_length(self.gl, self.root, k)
if dil == n:
nodedist.append(str(k))
g2 = self.gl.subgraph(nodedist)
dicdend[n] = sorted(networkx.connected_components(g2))
for n2, yu in enumerate(dicdend[n]):
g3.add_node(str(n) + '_' + str(n2))
if n > 0:
for n3, yu2 in enumerate(dicdend[n-1]):
if networkx.is_connected(self.gl.subgraph(list(yu)+list(yu2))):
g3.add_edge(str(n) + '_' + str(n2), str(n-1) + '_' + str(n3))
return g3, dicdend
开发者ID:CamaraLab,项目名称:scTDA,代码行数:24,
示例7: node_distance
点赞 6
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def node_distance(G):
"""
Return an NxN matrix that consists of histograms of shortest path
lengths between nodes i and j. This is useful for eventually taking
information theoretic distances between the nodes.
Parameters
----------
G (nx.Graph): the graph in question.
Returns
-------
out (np.ndarray): a matrix of binned node distance values.
"""
N = G.number_of_nodes()
a = np.zeros((N, N))
dists = nx.shortest_path_length(G)
for idx, row in enumerate(dists):
counts = Counter(row[1].values())
a[idx] = [counts[l] for l in range(1, N + 1)]
return a / (N - 1)
开发者ID:netsiphd,项目名称:netrd,代码行数:27,
示例8: furtherest_node_miles
点赞 6
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def furtherest_node_miles(self, *args):
"""
Returns the maximum eccentricity from the source, in miles.
.. warning:: Not working....
"""
if args:
if len(args) == 1:
_net = args[0]
_src = self.source
elif len(args) == 2:
_net, _src = args
else:
_net = self.G.graph
_src = self.source
dist = {}
_net = _net.copy()
if not _net.has_node(_src):
_sp = nx.shortest_path(self.G.graph, _src, list(_net.nodes())[0])
for n1, n2 in zip(_sp[:-1], _sp[1:]):
_net.add_edge(n1, n2, length=self.G.graph[n1][n2]["length"])
for node in _net.nodes():
dist[node] = nx.shortest_path_length(_net, _src, node, weight="length")
return np.max(list(dist.values())) * 0.000621371 # Convert length to miles
开发者ID:NREL,项目名称:ditto,代码行数:26,
示例9: bell_reweighting
点赞 6
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def bell_reweighting(tree, root, sublinear=False):
# convert the hierarchy to a tree if make_bfs_tree is true
distance_by_target = nx.shortest_path_length(tree, source=root)
level_count = defaultdict(int)
for val in distance_by_target.values():
level_count[val] += 1
for edge in tree.edges():
parent, child = edge
if sublinear:
# use smoothed logarithm
tree[parent][child]['weight'] = 1.0 / log(1 + level_count[distance_by_target[child]], 10)
else:
tree[parent][child]['weight'] = 1.0 / level_count[distance_by_target[child]]
return tree
开发者ID:quadflor,项目名称:Quadflor,代码行数:20,
示例10: find_best_mapping
点赞 6
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def find_best_mapping(alignments, query_length, parent, coords_to_exclude, children_dict, previous_gene_start, copy_tag):
children = children_dict[parent.id]
children_coords = liftoff_utils.merge_children_intervals(children)
node_dict, aln_graph = intialize_graph()
head_nodes = add_single_alignments(node_dict, aln_graph, alignments, children_coords, parent, coords_to_exclude,
previous_gene_start)
chain_alignments(head_nodes, node_dict, aln_graph, coords_to_exclude, parent, children_coords)
add_target_node(aln_graph, node_dict, query_length, children_coords, parent)
shortest_path = nx.shortest_path(aln_graph, source=0, target=len(node_dict) - 1,
weight=lambda u, v, d: get_weight(u, v, d, aln_graph))
shortest_path_weight = nx.shortest_path_length(aln_graph, source=0, target=len(node_dict) - 1,
weight=lambda u, v, d: get_weight(u, v, d, aln_graph))
shortest_path_nodes = []
for i in range (1,len(shortest_path)-1):
node_name = shortest_path[i]
shortest_path_nodes.append(node_dict[node_name])
if len(shortest_path_nodes) == 0:
return {}, shortest_path_weight, 0,0
mapped_children, alignment_coverage, seq_id = convert_all_children_coords(shortest_path_nodes, children, parent, copy_tag)
return mapped_children, shortest_path_weight, alignment_coverage, seq_id
开发者ID:agshumate,项目名称:Liftoff,代码行数:24,
示例11: descendants
点赞 6
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def descendants(G, source):
"""Return all nodes reachable from `source` in G.
Parameters
----------
G : NetworkX DiGraph
source : node in G
Returns
-------
des : set()
The descendants of source in G
"""
if not G.has_node(source):
raise nx.NetworkXError("The node %s is not in the graph." % source)
des = set(nx.shortest_path_length(G, source=source).keys()) - set([source])
return des
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:19,
示例12: ancestors
点赞 6
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def ancestors(G, source):
"""Return all nodes having a path to `source` in G.
Parameters
----------
G : NetworkX DiGraph
source : node in G
Returns
-------
ancestors : set()
The ancestors of source in G
"""
if not G.has_node(source):
raise nx.NetworkXError("The node %s is not in the graph." % source)
anc = set(nx.shortest_path_length(G, target=source).keys()) - set([source])
return anc
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:19,
示例13: test_eccentricity
点赞 6
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def test_eccentricity(self):
assert_equal(networkx.eccentricity(self.G,1),6)
e=networkx.eccentricity(self.G)
assert_equal(e[1],6)
sp=networkx.shortest_path_length(self.G)
e=networkx.eccentricity(self.G,sp=sp)
assert_equal(e[1],6)
e=networkx.eccentricity(self.G,v=1)
assert_equal(e,6)
e=networkx.eccentricity(self.G,v=[1,1]) #This behavior changed in version 1.8 (ticket #739)
assert_equal(e[1],6)
e=networkx.eccentricity(self.G,v=[1,2])
assert_equal(e[1],6)
# test against graph with one node
G=networkx.path_graph(1)
e=networkx.eccentricity(G)
assert_equal(e[0],0)
e=networkx.eccentricity(G,v=0)
assert_equal(e,0)
assert_raises(networkx.NetworkXError, networkx.eccentricity, G, 1)
# test against empty graph
G=networkx.empty_graph()
e=networkx.eccentricity(G)
assert_equal(e,{})
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:26,
示例14: descendants
点赞 6
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def descendants(G, source):
"""Returns all nodes reachable from `source` in `G`.
Parameters
----------
G : NetworkX DiGraph
A directed acyclic graph (DAG)
source : node in `G`
Returns
-------
set()
The descendants of `source` in `G`
"""
if not G.has_node(source):
raise nx.NetworkXError("The node %s is not in the graph." % source)
des = set(n for n, d in nx.shortest_path_length(G, source=source).items())
return des - {source}
开发者ID:holzschu,项目名称:Carnets,代码行数:20,
示例15: ancestors
点赞 6
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def ancestors(G, source):
"""Returns all nodes having a path to `source` in `G`.
Parameters
----------
G : NetworkX DiGraph
A directed acyclic graph (DAG)
source : node in `G`
Returns
-------
set()
The ancestors of source in G
"""
if not G.has_node(source):
raise nx.NetworkXError("The node %s is not in the graph." % source)
anc = set(n for n, d in nx.shortest_path_length(G, target=source).items())
return anc - {source}
开发者ID:holzschu,项目名称:Carnets,代码行数:20,
示例16: test_all_pairs_shortest_path_length
点赞 6
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def test_all_pairs_shortest_path_length(self):
ans = dict(nx.shortest_path_length(self.cycle))
assert_equal(ans[0], {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1})
assert_equal(ans, dict(nx.all_pairs_shortest_path_length(self.cycle)))
ans = dict(nx.shortest_path_length(self.grid))
assert_equal(ans[1][16], 6)
# now with weights
ans = dict(nx.shortest_path_length(self.cycle, weight='weight'))
assert_equal(ans[0], {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1})
assert_equal(ans, dict(nx.all_pairs_dijkstra_path_length(self.cycle)))
ans = dict(nx.shortest_path_length(self.grid, weight='weight'))
assert_equal(ans[1][16], 6)
# weights and method specified
ans = dict(nx.shortest_path_length(self.cycle, weight='weight',
method='dijkstra'))
assert_equal(ans[0], {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1})
assert_equal(ans, dict(nx.all_pairs_dijkstra_path_length(self.cycle)))
ans = dict(nx.shortest_path_length(self.cycle, weight='weight',
method='bellman-ford'))
assert_equal(ans[0], {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1})
assert_equal(ans,
dict(nx.all_pairs_bellman_ford_path_length(self.cycle)))
开发者ID:holzschu,项目名称:Carnets,代码行数:24,
示例17: test_eccentricity
点赞 6
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def test_eccentricity(self):
assert_equal(networkx.eccentricity(self.G, 1), 6)
e = networkx.eccentricity(self.G)
assert_equal(e[1], 6)
sp = dict(networkx.shortest_path_length(self.G))
e = networkx.eccentricity(self.G, sp=sp)
assert_equal(e[1], 6)
e = networkx.eccentricity(self.G, v=1)
assert_equal(e, 6)
# This behavior changed in version 1.8 (ticket #739)
e = networkx.eccentricity(self.G, v=[1, 1])
assert_equal(e[1], 6)
e = networkx.eccentricity(self.G, v=[1, 2])
assert_equal(e[1], 6)
# test against graph with one node
G = networkx.path_graph(1)
e = networkx.eccentricity(G)
assert_equal(e[0], 0)
e = networkx.eccentricity(G, v=0)
assert_equal(e, 0)
assert_raises(networkx.NetworkXError, networkx.eccentricity, G, 1)
# test against empty graph
G = networkx.empty_graph()
e = networkx.eccentricity(G)
assert_equal(e, {})
开发者ID:holzschu,项目名称:Carnets,代码行数:27,
示例18: descendants
点赞 6
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def descendants(G, source):
"""Return all nodes reachable from `source` in `G`.
Parameters
----------
G : NetworkX DiGraph
A directed acyclic graph (DAG)
source : node in `G`
Returns
-------
set()
The descendants of `source` in `G`
"""
if not G.has_node(source):
raise nx.NetworkXError("The node %s is not in the graph." % source)
spl = nx.shortest_path_length(G, source=source)
des = set(spl) - set([source])
return des
开发者ID:aws-samples,项目名称:aws-kube-codesuite,代码行数:21,
示例19: ancestors
点赞 6
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def ancestors(G, source):
"""Return all nodes having a path to `source` in `G`.
Parameters
----------
G : NetworkX DiGraph
A directed acyclic graph (DAG)
source : node in `G`
Returns
-------
set()
The ancestors of source in G
"""
if not G.has_node(source):
raise nx.NetworkXError("The node %s is not in the graph." % source)
spl = nx.shortest_path_length(G, target=source)
anc = set(spl) - set([source])
return anc
开发者ID:aws-samples,项目名称:aws-kube-codesuite,代码行数:21,
示例20: calculate_max_depth
点赞 5
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def calculate_max_depth(comment_tree):
comment_tree_nx = nx.from_scipy_sparse_matrix(comment_tree, create_using=nx.Graph())
if len(comment_tree_nx) == 0:
max_depth = 0.0
else:
node_to_depth = nx.shortest_path_length(comment_tree_nx, 0)
max_depth = max(node_to_depth.values())
return max_depth
开发者ID:MKLab-ITI,项目名称:news-popularity-prediction,代码行数:12,
示例21: calculate_avg_depth
点赞 5
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def calculate_avg_depth(comment_tree):
comment_tree_nx = nx.from_scipy_sparse_matrix(comment_tree, create_using=nx.Graph())
if len(comment_tree_nx) == 0:
avg_depth = 0.0
else:
node_to_depth = nx.shortest_path_length(comment_tree_nx, 0)
avg_depth = statistics.mean(node_to_depth.values())
return avg_depth
开发者ID:MKLab-ITI,项目名称:news-popularity-prediction,代码行数:12,
示例22: calculate_max_width
点赞 5
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def calculate_max_width(comment_tree):
comment_tree_nx = nx.from_scipy_sparse_matrix(comment_tree, create_using=nx.Graph())
if len(comment_tree_nx) == 0:
max_width = 1.0
else:
node_to_depth = nx.shortest_path_length(comment_tree_nx, 0)
depth_to_nodecount = collections.defaultdict(int)
for k, v in node_to_depth.items():
depth_to_nodecount[v] += 1
max_width = max(depth_to_nodecount.values())
return max_width
开发者ID:MKLab-ITI,项目名称:news-popularity-prediction,代码行数:17,
示例23: calculate_avg_width
点赞 5
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def calculate_avg_width(comment_tree):
comment_tree_nx = nx.from_scipy_sparse_matrix(comment_tree, create_using=nx.Graph())
if len(comment_tree_nx) == 0:
avg_width = 1.0
else:
node_to_depth = nx.shortest_path_length(comment_tree_nx, 0)
depth_to_nodecount = collections.defaultdict(int)
for k, v in node_to_depth.items():
depth_to_nodecount[v] += 1
avg_width = statistics.mean(depth_to_nodecount.values())
return avg_width
开发者ID:MKLab-ITI,项目名称:news-popularity-prediction,代码行数:17,
示例24: create_profile_graph
点赞 5
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def create_profile_graph(self, y_values):
self.regenerate_network(load_names=False, gen_names=False)
swing_bus = self.swing_bus
bus_distance_matrix_df = pd.DataFrame(nx.shortest_path_length(self.graph))
pos = dict()
for k, v in bus_distance_matrix_df.loc[swing_bus].sort_values().to_dict().items():
pos[k] = (v, y_values[k])
self.positions = pos
开发者ID:power-system-simulation-toolbox,项目名称:psst,代码行数:13,
示例25: get_syntactical_distance_from_graph
点赞 5
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def get_syntactical_distance_from_graph(graph, token_a, token_b, debug=False):
return nx.shortest_path_length(graph,
source='{}-{}'.format(token_a.word if hasattr(token_a, 'word') else token_a.text, token_a.i),
target='{}-{}'.format(token_b.word if hasattr(token_b, 'word') else token_b.text, token_b.i))
开发者ID:sattree,项目名称:gap,代码行数:6,
示例26: get_topic_distance
点赞 5
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def get_topic_distance(sg, topic):
"""
:param sg: an egocentric subgraph in networkx format
:param topic: a networkx graph of nodes representing the topic
:return: a dictionary of key node name and value distance as integer
"""
distances = dict()
# get all the distances
for tnode in topic.nodes():
if tnode in sg.nodes():
distances[tnode] = nx.shortest_path_length(sg, source=tnode)
# get the smallest distance per key
min_dist = dict()
for key in distances:
for node in distances[key]:
if node not in min_dist:
min_dist[node] = distances[key][node]
elif distances[key][node] < min_dist[node]:
min_dist[node] = distances[key][node]
# Return the dict
return min_dist
开发者ID:vz-risk,项目名称:Verum,代码行数:28,
示例27: _lowest_common_anscestor
点赞 5
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def _lowest_common_anscestor(T, u, v, root):
# Find a least common anscestors
v_branch = nx.ancestors(T, v).union({v})
u_branch = nx.ancestors(T, u).union({u})
common = v_branch & u_branch
if len(common) == 0:
lca = None
else:
lca = max(
(nx.shortest_path_length(T, root, c), c)
for c in common
)[1]
return lca
开发者ID:Erotemic,项目名称:ibeis,代码行数:15,
示例28: create_length_dict
点赞 5
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def create_length_dict(points_on_line, tranches):
G_complete = nx.Graph()
for idx, node in points_on_line.iterrows():
node_type = node['Type']
G_complete.add_node(idx, type=node_type)
for idx, tranch in tranches.iterrows():
start_node_index = tranch['Startnode'][4::]
end_node_index = tranch['Endnode'][4::]
tranch_length = tranch['Length']
G_complete.add_edge(int(start_node_index), int(end_node_index),
weight=tranch_length,
gene=idx,
startnode=start_node_index,
endnode=end_node_index)
idx_nodes_sub = points_on_line[points_on_line['Type'] == 'PLANT'].index
idx_nodes_consum = points_on_line[points_on_line['Type'] == 'CONSUMER'].index
idx_nodes = idx_nodes_sub.append(idx_nodes_consum)
dict_length = {}
dict_path = {}
for idx_node1 in idx_nodes:
dict_length[idx_node1] = {}
dict_path[idx_node1] = {}
for idx_node2 in idx_nodes:
if idx_node1 == idx_node2:
dict_length[idx_node1][idx_node2] = 0.0
else:
nx.shortest_path(G_complete, 0, 1)
dict_path[idx_node1][idx_node2] = nx.shortest_path(G_complete,
source=idx_node1,
target=idx_node2,
weight='weight')
dict_length[idx_node1][idx_node2] = nx.shortest_path_length(G_complete,
source=idx_node1,
target=idx_node2,
weight='weight')
return dict_length, dict_path
开发者ID:architecture-building-systems,项目名称:CityEnergyAnalyst,代码行数:42,
示例29: create_length_complete_dict
点赞 5
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def create_length_complete_dict(points_on_line, tranches):
G_complete = nx.Graph()
for idx, node in points_on_line.iterrows():
node_type = node['Type']
G_complete.add_node(idx, type=node_type)
for idx, tranch in tranches.iterrows():
start_node_index = tranch['Startnode'][4::]
end_node_index = tranch['Endnode'][4::]
tranch_length = tranch['Length']
G_complete.add_edge(int(start_node_index), int(end_node_index),
weight=tranch_length,
gene=idx,
startnode=start_node_index,
endnode=end_node_index)
# idx_nodes_sub = points_on_line[points_on_line['Type'] == 'PLANT'].index
# idx_nodes_consum = points_on_line[points_on_line['Type'] == 'CONSUMER'].index
idx_nodes = points_on_line.index
dict_length = {}
dict_path = {}
for idx_node1 in idx_nodes:
dict_length[idx_node1] = {}
dict_path[idx_node1] = {}
for idx_node2 in idx_nodes:
if idx_node1 == idx_node2:
dict_length[idx_node1][idx_node2] = 0.0
else:
nx.shortest_path(G_complete, 0, 1)
dict_path[idx_node1][idx_node2] = nx.shortest_path(G_complete,
source=idx_node1,
target=idx_node2,
weight='weight')
dict_length[idx_node1][idx_node2] = nx.shortest_path_length(G_complete,
source=idx_node1,
target=idx_node2,
weight='weight')
return dict_length, dict_path
开发者ID:architecture-building-systems,项目名称:CityEnergyAnalyst,代码行数:42,
示例30: compute_distance
点赞 5
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import shortest_path_length [as 别名]
def compute_distance(k):
return nx.shortest_path_length(G,str(k[0]),str(k[1]))
开发者ID:acsicuib,项目名称:YAFS,代码行数:4,
注:本文中的networkx.shortest_path_length方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
