Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
8 changes: 6 additions & 2 deletions src/directedness.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/graphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/metagraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading