sbromberger / SimpleWeightedGraphs.jl

Simple weighted graphs. Requires LightGraphs.jl.
Other
49 stars 22 forks source link

Error: Non symmetric matrices created by repeated pairs #56

Open mathieuLacroix opened 4 years ago

mathieuLacroix commented 4 years ago

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,

sbromberger commented 4 years ago

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

matbesancon commented 4 years ago

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