-1

当我尝试betweenness_centrality()使用 julia 的 LightGraphs 包计算我的 SimpleWeightedGraph 时,它会无限期地运行。它不断增加它的 RAM 使用量,直到在某个时候它崩溃而没有错误消息。我的图表有问题吗?或者找到此问题原因的最佳方法是什么?

我的图表不是由 LightGraphs 生成的,而是由另一个库 FlashWeave 生成​​的。我不知道这是否重要...

未加权的 SimpleGraph 或我在 LightGraphs 中创建的加权图不会出现此问题...

using BenchmarkTools
using FlashWeave
using ParserCombinator
using GraphIO.GML
using LightGraphs
using SimpleWeightedGraphs

data_path = /path/to/my/data

netw_results = FlashWeave.learn_network(data_path,                                          
                                        sensitive     = true,
                                        heterogeneous = false)

dummy_weighted_graph = SimpleWeightedGraph(smallgraph(:house))
# {5, 6} undirected simple Int64 graph with Float64 weights


my_weighted_graph = graph(netw_results_no_meta)
# {6558, 8484} undirected simple Int64 graph with Float64 weights

# load_graph() only loads unweighted graphs
save_network(gml_no_meta_path, netw_results_no_meta)
my_unweighted_graph = loadgraph(gml_no_meta_path, GMLFormat())
# {6558, 8484} undirected simple Int64 graph



@time betweenness_centrality(my_unweighted_graph)
# 12.467820 seconds (45.30 M allocations: 7.531 GiB, 2.73% gc time)

@time  betweenness_centrality(dummy_weighted_graph)
# 0.271050 seconds (282.41 k allocations: 13.838 MiB)

@time  betweenness_centrality(my_weighted_graph)
# steadily increasing RAM usage until RAM is full and julia crashes.
4

2 回答 2

2

您是否检查过您的图表是否包含负权重?LightGraphs.betweenness_centrality()使用 Dijkstra 的最短路径来计算中介中心性,因此期望非负权重。

LightGraphs.betweenness_centrality()不检查非法/无意义的图表。这就是它没有抛出错误的原因。该问题已在此处报告,但现在,如果您不确定它们是否合法,请检查您自己的图表。

A = Float64[
    0  4  2
    4  0  1
    2  1  0
]

B = Float64[
    0  4  2
    4  0  -1
    2  -1  0
]

graph_a = SimpleWeightedGraph(A)
# {3, 3} undirected simple Int64 graph with Float64 weights
graph_b = SimpleWeightedGraph(B)
# {3, 3} undirected simple Int64 graph with Float64 weights

minimum(graph_a.weights)
# 0.00
minimum(graph_b.weights)
# -1.00

@time betweenness_centrality(graph_a)
# 0.321796 seconds (726.13 k allocations: 36.906 MiB, 3.53% gc time)
# Vector{Float64} with 3 elements
# 0.00
# 0.00
# 1.00

@time betweenness_centrality(graph_b)
# reproduces your problem.
于 2021-02-18T09:55:09.210 回答
2

在此问题发布之前,这已在https://github.com/JuliaGraphs/LightGraphs.jl/issues/1531中得到解答。如决议中所述,您在图表中具有负权重。Dijkstra 不处理具有负权重的图,LightGraphs 中介中心性使用 Dijkstra。

于 2021-02-18T15:55:23.000 回答