日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python networkx.algorithms.approximation.steinertree 介绍

發(fā)布時(shí)間:2024/3/26 python 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python networkx.algorithms.approximation.steinertree 介绍 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

【未標(biāo)明的翻譯皆出自‘有道翻譯’】

1、python 包 官方文檔鏈接 :

Approximations and Heuristics — NetworkX 2.6rc1.dev0 documentation

復(fù)雜網(wǎng)絡(luò)軟件 — NetworkX 2.5 文檔 (osgeo.cn)

2、官方文檔里Steiner Tree所在位置如圖:

3、Steiner Tree 函數(shù)的介紹

metric_closure(G[,?weight])

Return the metric closure of a graph.

steiner_tree(G,?terminal_nodes[,?weight])

Return an approximation to the minimum Steiner tree of a graph.

  • networkx.algorithms.approximation.steinertree.metric_closure

metric_closure(G,?weight='weight')[source]

Return the metric closure of a graph. 返回一個(gè)圖的度量閉包

The metric closure of a graph?G?is the complete graph in which each edge is weighted by the shortest path distance between the nodes in?G?.

圖G的度量閉包是一個(gè)完全圖,其中每條邊都被G中節(jié)點(diǎn)之間的最短路徑距離加權(quán)。

Parameters

G :NetworkX graph

Returns :NetworkX graph? ? Metric closure of the graph?G.

?

  • networkx.algorithms.approximation.steinertree.steiner_tree

steiner_tree(G,?terminal_nodes,?weight='weight')[source]

Return an approximation to the minimum Steiner tree of a graph.?。返回圖的最小斯坦納樹的近似值。

The minimum Steiner tree of?G?w.r.t a set of?terminal_nodes?is a tree within?G?that spans those nodes and has minimum size (sum of edge weights) among all such trees.

G的最小Steiner樹(一組terminal_nodes)是G內(nèi)部跨越這些節(jié)點(diǎn)且在所有這些樹中具有最小大小(邊權(quán)和)的樹。

G的最小Steiner樹是一組G內(nèi)的樹,該樹跨越這些節(jié)點(diǎn)并且在所有此類樹中具有最小的大小(邊緣權(quán)重之和)。【谷歌翻譯】

The minimum Steiner tree can be approximated by computing the minimum spanning tree of the subgraph of the metric closure of?G?induced by the terminal nodes, where the metric closure of?G?is the complete graph in which each edge is weighted by the shortest path distance between the nodes in?G?. This algorithm produces a tree whose weight is within a (2 - (2 / t)) factor of the weight of the optimal Steiner tree where?t?is number of terminal nodes.

最小Steiner樹可以近似計(jì)算子圖的最小生成樹的度規(guī)關(guān)閉終端節(jié)點(diǎn),引發(fā)的G, G的度量閉包是完全圖中每條邊的節(jié)點(diǎn)之間的最短路徑距離加權(quán)的G。該算法生成的樹的權(quán)值在最優(yōu)Steiner樹權(quán)值的(2 - (2 / t))因子之內(nèi),其中t為終端節(jié)點(diǎn)數(shù)。

可以通過計(jì)算由終端節(jié)點(diǎn)terminal nodes引起的G度量封閉的子圖的最小生成樹來近似最小Steiner樹,其中G度量封閉是完整的圖,其中每個(gè)邊都由之間的最短路徑距離加權(quán) G中的節(jié)點(diǎn) 。該算法生成的樹的權(quán)重在最佳Steiner樹的權(quán)重的(2-(2 / t))因子之內(nèi),其中t是終端節(jié)點(diǎn)的數(shù)量。【谷歌翻譯】

Parameters

G :?NetworkX graph

terminal_nodes :?list? ? ? ? ?A list of terminal nodes for which minimum steiner tree is to be found.?要為其找到最小斯坦納樹的終端節(jié)點(diǎn)列表。

Returns?: NetworkX graph? ? ? ? Approximation to the minimum steiner tree of?G?induced by?terminal_nodes?.?由終端節(jié)點(diǎn)誘導(dǎo)的G最小steiner樹的逼近。

  • Notes

For multigraphs, the edge between two nodes with minimum weight is the edge put into the Steiner tree.

對于多重圖,權(quán)值最小的兩個(gè)節(jié)點(diǎn)之間的邊是放入Steiner樹的邊。

  • References

Steiner_tree_problem on Wikipedia.?https://en.wikipedia.org/wiki/Steiner_tree_problem

4、函數(shù)源碼 :?networkx.algorithms.approximation.steinertree — NetworkX 2.6rc1.dev0 documentation

from itertools import chainfrom networkx.utils import pairwise, not_implemented_for import networkx as nx__all__ = ["metric_closure", "steiner_tree"][docs]@not_implemented_for("directed") def metric_closure(G, weight="weight"):"""Return the metric closure of a graph.The metric closure of a graph *G* is the complete graph in which each edgeis weighted by the shortest path distance between the nodes in *G* .Parameters----------G : NetworkX graphReturns-------NetworkX graphMetric closure of the graph `G`."""M = nx.Graph()Gnodes = set(G)# check for connected graph while processing first nodeall_paths_iter = nx.all_pairs_dijkstra(G, weight=weight)u, (distance, path) = next(all_paths_iter)if Gnodes - set(distance):msg = "G is not a connected graph. metric_closure is not defined."raise nx.NetworkXError(msg)Gnodes.remove(u)for v in Gnodes:M.add_edge(u, v, distance=distance[v], path=path[v])# first node done -- now process the restfor u, (distance, path) in all_paths_iter:Gnodes.remove(u)for v in Gnodes:M.add_edge(u, v, distance=distance[v], path=path[v])return M @not_implemented_for("directed") def steiner_tree(G, terminal_nodes, weight="weight"):"""Return an approximation to the minimum Steiner tree of a graph.The minimum Steiner tree of `G` w.r.t a set of `terminal_nodes`is a tree within `G` that spans those nodes and has minimum size(sum of edge weights) among all such trees.The minimum Steiner tree can be approximated by computing the minimumspanning tree of the subgraph of the metric closure of *G* induced by theterminal nodes, where the metric closure of *G* is the complete graph inwhich each edge is weighted by the shortest path distance between thenodes in *G* .This algorithm produces a tree whose weight is within a (2 - (2 / t))factor of the weight of the optimal Steiner tree where *t* is number ofterminal nodes.Parameters----------G : NetworkX graphterminal_nodes : listA list of terminal nodes for which minimum steiner tree isto be found.Returns-------NetworkX graphApproximation to the minimum steiner tree of `G` induced by`terminal_nodes` .Notes-----For multigraphs, the edge between two nodes with minimum weight is theedge put into the Steiner tree.References----------.. [1] Steiner_tree_problem on Wikipedia.https://en.wikipedia.org/wiki/Steiner_tree_problem"""# H is the subgraph induced by terminal_nodes in the metric closure M of G.M = metric_closure(G, weight=weight)H = M.subgraph(terminal_nodes)# Use the 'distance' attribute of each edge provided by M.mst_edges = nx.minimum_spanning_edges(H, weight="distance", data=True)# Create an iterator over each edge in each shortest path; repeats are okayedges = chain.from_iterable(pairwise(d["path"]) for u, v, d in mst_edges)# For multigraph we should add the minimal weight edge keysif G.is_multigraph():edges = ((u, v, min(G[u][v], key=lambda k: G[u][v][k][weight])) for u, v in edges)T = G.edge_subgraph(edges)return T

5、函數(shù)使用

(待補(bǔ)充)

總結(jié)

以上是生活随笔為你收集整理的python networkx.algorithms.approximation.steinertree 介绍的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。