SimpleWeightedGraphs.jl icon indicating copy to clipboard operation
SimpleWeightedGraphs.jl copied to clipboard

Error: Non symmetric matrices created by repeated pairs

Open mathieuLacroix opened this issue 5 years ago • 2 comments

Hi,

Creating a simpleWeigthedGraph with repeated pairs may raise the error "Adjacency / distance matrices must be symmetric" due to numerical imprecision, even when using + as combine function.

For instance, the sparse matrix constructed when creating the weighted graph using the following data is not symmetric.

sources = [3, 3, 3, 3, 4, 1, 3, 3, 3, 4, 1, 3, 4]
destinations = [2, 4, 1, 1, 1, 4, 4, 2, 4, 2, 2, 1, 3]
weights = [0.22279, 0.287542, 0.461288, 0.222349, 0.838298, 0.295453, 0.995701, 0.878216, 0.0935724, 0.184148, 0.397035, 0.601133, 0.873484]
s = sparse(vcat(sources,destinations), vcat(destinations,sources), vcat(weights,weights),4, 4, +)
println(issymmetric(s))

Hence, g = SimpleWeightedGraph(sources, destinations, weights) raises an error.

Is it possible to find another way to construct the sparse matrix? Or indicate in the doc that repeated pairs should not be used with float weights?

Best,

mathieuLacroix avatar Nov 21 '19 16:11 mathieuLacroix

you shouldn't be repeating (s,d) pairs in any constructor. That's definitely good cause for undefined behavior.

sbromberger avatar Nov 21 '19 16:11 sbromberger

Or indicate in the doc that repeated pairs should not be used with float weights?

Yes we should do that, add a warning for UBehavior in the docs

matbesancon avatar Nov 21 '19 16:11 matbesancon