sbromberger / SimpleWeightedGraphs.jl

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

Direction of edges inverted when going from `SimpleWeightedDiGraph` to `SimpleDiGraph` #67

Closed Antomek closed 3 years ago

Antomek commented 3 years ago

Hello everyone,

Thanks for your work on SimpleWeightedGraphs.jl~

I recently noticed that converting from a SimpleWeightedDiGraph to a SimpleDiGraph inverts the direction of the edges.

using SimpleWeightedGraphs, LightGraphs

# Create lists of sources and destination vertices
sources = [i for i in 1:3]
destinations = [4 for _ in 1:length(sources)]
weights = [1. for _ in 1:length(sources)]

# Construct the weighted and directed graph
g_weighted = SimpleWeightedDiGraph(sources, destinations, weights)
edge_weights = getfield.(collect(edges(g_weighted)), :weight)

# Convert the weighted graph to a simple directed graph
g_directed = SimpleDiGraph(g_weighted)

However:

julia> collect(edges(g_weighted))
3-element Array{SimpleWeightedEdge{Int64,Float64},1}:
 Edge 1 => 4 with weight 1.0
 Edge 2 => 4 with weight 1.0
 Edge 3 => 4 with weight 1.0

and

julia> collect(edges(g_directed))
3-element Array{LightGraphs.SimpleGraphs.SimpleEdge{Int64},1}:
 Edge 4 => 1
 Edge 4 => 2
 Edge 4 => 3

Of course this is easily fixed by doing reverse(g_directed), but it is confusing nevertheless.

Thanks!

sbromberger commented 3 years ago

Closed via #68 .

lindnemi commented 3 years ago

Great single symbol fix! Love to see those :+1: