Skip to content

Commit 1ea0c41

Browse files
authored
Fix undirected edges (#88)
1 parent 64990ba commit 1ea0c41

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
lines changed

Diff for: Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "MetaGraphsNext"
22
uuid = "fa8bd995-216d-47f1-8a91-f3b68fbeb377"
3-
version = "0.7.1"
3+
version = "0.7.2"
44

55
[deps]
66
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"

Diff for: src/directedness.jl

+6-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ to be robust to vertex re-coding, so the labels need to support `<`.
1717
"""
1818
function arrange end
1919

20-
@traitfn function arrange(::MG, label_1, label_2) where {MG <: MetaGraph; IsDirected{MG}}
20+
@traitfn function arrange(
21+
::MG, label_1, label_2
22+
) where {MG <: AbstractGraph; IsDirected{MG}}
2123
return label_1, label_2
2224
end
2325

24-
@traitfn function arrange(::MG, label_1, label_2) where {MG <: MetaGraph; !IsDirected{MG}}
26+
@traitfn function arrange(
27+
::MG, label_1, label_2
28+
) where {MG <: AbstractGraph; !IsDirected{MG}}
2529
if label_1 < label_2
2630
(label_1, label_2)
2731
else

Diff for: src/graphs.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,9 @@ end
315315
edge_data = meta_graph.edge_data
316316
reverse_edge_data = empty(edge_data)
317317
for (label_1, label_2) in keys(edge_data)
318-
reverse_edge_data[(label_2, label_1)] = edge_data[(label_1, label_2)]
318+
reverse_edge_data[arrange(meta_graph, label_2, label_1)] = edge_data[arrange(
319+
meta_graph, label_1, label_2
320+
)]
319321
end
320322
return MetaGraph(
321323
reverse(meta_graph.graph),

Diff for: src/metagraph.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ function MetaGraph(
185185
end
186186
edge_data = Dict{Tuple{Label,Label},EdgeData}()
187187
for ((label_1, label_2), data) in edges_description
188-
edge_data[label_1, label_2] = data
188+
edge_data[arrange(graph, label_1, label_2)] = data
189189
end
190190
return MetaGraph(
191191
graph,

Diff for: test/misc.jl

+10
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,13 @@ end
7272
# compare
7373
@test mg == mg2
7474
end
75+
76+
@testset "Undirected edges" begin
77+
graph = MetaGraph(
78+
complete_graph(2), ["3" => nothing, "2" => nothing], [("3", "2") => 1]
79+
)
80+
@test haskey(graph, "2", "3")
81+
@test haskey(graph, "3", "2")
82+
(from, to) = first(edge_labels(graph))
83+
@test graph[from, to] === 1
84+
end

0 commit comments

Comments
 (0)