diff --git a/Project.toml b/Project.toml index cb49704..14c2347 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "MetaGraphsNext" uuid = "fa8bd995-216d-47f1-8a91-f3b68fbeb377" -version = "0.7.1" +version = "0.7.2" [deps] Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" diff --git a/src/directedness.jl b/src/directedness.jl index 8a79ee5..4353cb5 100644 --- a/src/directedness.jl +++ b/src/directedness.jl @@ -17,11 +17,15 @@ to be robust to vertex re-coding, so the labels need to support `<`. """ function arrange end -@traitfn function arrange(::MG, label_1, label_2) where {MG <: MetaGraph; IsDirected{MG}} +@traitfn function arrange( + ::MG, label_1, label_2 +) where {MG <: AbstractGraph; IsDirected{MG}} return label_1, label_2 end -@traitfn function arrange(::MG, label_1, label_2) where {MG <: MetaGraph; !IsDirected{MG}} +@traitfn function arrange( + ::MG, label_1, label_2 +) where {MG <: AbstractGraph; !IsDirected{MG}} if label_1 < label_2 (label_1, label_2) else diff --git a/src/graphs.jl b/src/graphs.jl index 4a10c50..fc34fb0 100644 --- a/src/graphs.jl +++ b/src/graphs.jl @@ -315,7 +315,9 @@ end edge_data = meta_graph.edge_data reverse_edge_data = empty(edge_data) for (label_1, label_2) in keys(edge_data) - reverse_edge_data[(label_2, label_1)] = edge_data[(label_1, label_2)] + reverse_edge_data[arrange(meta_graph, label_2, label_1)] = edge_data[arrange( + meta_graph, label_1, label_2 + )] end return MetaGraph( reverse(meta_graph.graph), diff --git a/src/metagraph.jl b/src/metagraph.jl index 49c9bbc..57e1179 100644 --- a/src/metagraph.jl +++ b/src/metagraph.jl @@ -185,7 +185,7 @@ function MetaGraph( end edge_data = Dict{Tuple{Label,Label},EdgeData}() for ((label_1, label_2), data) in edges_description - edge_data[label_1, label_2] = data + edge_data[arrange(graph, label_1, label_2)] = data end return MetaGraph( graph, diff --git a/test/misc.jl b/test/misc.jl index 8faa752..67f0bb0 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -72,3 +72,13 @@ end # compare @test mg == mg2 end + +@testset "Undirected edges" begin + graph = MetaGraph( + complete_graph(2), ["3" => nothing, "2" => nothing], [("3", "2") => 1] + ) + @test haskey(graph, "2", "3") + @test haskey(graph, "3", "2") + (from, to) = first(edge_labels(graph)) + @test graph[from, to] === 1 +end