-1

When I try to calculate the betweenness_centrality() of my SimpleWeightedGraph with julia's LightGraphs package it runs indefinitely. It keeps on increasing it's RAM usage until at some point it crashes without an error message. Is the something wrong with my graph? Or what would be the best way to find the cause of this problem?

My graphs are not generated by LightGraphs but by another library, FlashWeave. I'm don't know if that matters...

The problem does not occur for unweighted SimpleGraph's or for the weighted graph I created in 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.
desertnaut
  • 57,590
  • 26
  • 140
  • 166
Jonas
  • 1,401
  • 9
  • 25

2 Answers2

2

Did you check if your graph contains negative weights? LightGraphs.betweenness_centrality() uses Dijkstra's shortest paths to calculate betweenness centrality, and thus expect non-negative weights.

LightGraphs.betweenness_centrality() doesn't check for illegal/nonsensical graphs. That's why it didn't throw an error. The issue is already reported here, but for now, check your own graphs if your not sure they are legal.

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.
Jonas
  • 1,401
  • 9
  • 25
2

This was answered already in https://github.com/JuliaGraphs/LightGraphs.jl/issues/1531, before this question was posted here. As mentioned in the resolution, you have negative weights in the graph. Dijkstra does not handle graphs with negative weights, and LightGraphs betweenness centrality uses Dijkstra.

sbromberger
  • 1,026
  • 6
  • 12