Skip to content

Undirected graph edges not adding successfully #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kenahoo opened this issue Mar 10, 2025 · 0 comments · Fixed by #88
Closed

Undirected graph edges not adding successfully #87

kenahoo opened this issue Mar 10, 2025 · 0 comments · Fixed by #88

Comments

@kenahoo
Copy link
Contributor

kenahoo commented Mar 10, 2025

Here's a chunk of code demonstrating what seems like a problem:

using Graphs, MetaGraphsNext

graph = MetaGraph(
    complete_graph(2),
    ["3" => nothing, "2" => nothing],
    [("3", "2") => nothing],
)

println("Has key \"2\"->\"3\"? $(haskey(graph, "2", "3"))")
# Output> Has key "2"->"3"? false

println("Has key \"3\"->\"2\"? $(haskey(graph, "3", "2"))")
# Output> Has key "3"->"2"? false

(from, to) = first(edge_labels(graph))
println("First edge: $from -> $to")
# Output> First edge: 3 -> 2

println(graph[from, to])
# ERROR: KeyError: key ("2", "3") not found
# Stacktrace:
# [1] getindex
#   @ ./dict.jl:498 [inlined]
# [2] getindex(meta_graph::MetaGraph{…}, label_1::String, label_2::String)
#   @ MetaGraphsNext ~/.julia/packages/MetaGraphsNext/Ofw3U/src/dict_utils.jl:25
# [3] top-level scope
#   @ REPL[37]:1

The graph seems to know that it should have an edge between "2" and "3", but getindex(graph, "2", "3") (and the reverse order too) fail. Is this a known problem?

A fix seems to be to sort all edge labels alphabetically in the third argument to the MetaGraph() constructor, but in my real application that's not very convenient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant