Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Property of edge lost when going from MetaDiGraph with inversed edge direction to MetaGraph #109

@Hofsmo

Description

@Hofsmo

Hi,
I just discovered some unexpected behaviour when converting a MetaDiGraph to MetaGraph. In my MetaDiGraph I have one edge that is directed from a high number to a lower number, i.e. 3->2 instead of 2->3. When I convert the MetaDiGraph to a MetaGraph the property is lost on the edge directed in the "wrong" direction, but on another edge directed in the opposite direction the property is kept.

Would it maybe make more sense if the property was kept for both edges?

Below is a code example demonstrating the behaviour.

using LightGraphs
using MetaGraphs

G = MetaDiGraph(3)

add_edge!(G, 1, 2)
add_edge!(G, 3, 2)

set_prop!(G, 1, 2, :name, "a")
set_prop!(G, 3, 2, :name, "b")

Confirm that the property was correctly set.

get_prop(G, 3, 2, :name)
"b"

Convert the directed graph to an undirected graph.

G2 = MetaGraph(G)

Check that the property on the first edge is still there.

get_prop(G2, 1, 2, :name)
"a"

Try to get the property of the second edge.

get_prop(G2, 3, 2, :name)
KeyError: key :name not found

  Stacktrace:

 [1] getindex at .\dict.jl:477 [inlined]

 [2] get_prop at C:\Users\user\.julia\packages\MetaGraphs\SUjFO\src\MetaGraphs.jl:256 [inlined]

 [3] get_prop(::MetaGraph{Int64,Float64}, ::Int64, ::Int64, ::Symbol) at C:\Users\user\.julia\packages\MetaGraphs\SUjFO\src\MetaGraphs.jl:258

 [4] top-level scope at In[10]:1

Try to get the property with inversed vertex order

get_prop(G2, 2, 3, :name)
KeyError: key :name not found
Stacktrace:

 [1] getindex at .\dict.jl:477 [inlined]

 [2] get_prop at C:\Users\user\.julia\packages\MetaGraphs\SUjFO\src\MetaGraphs.jl:256 [inlined]

 [3] get_prop(::MetaGraph{Int64,Float64}, ::Int64, ::Int64, ::Symbol) at C:\Users\user\.julia\packages\MetaGraphs\SUjFO\src\MetaGraphs.jl:258

 [4] top-level scope at In[11]:1

Check if the edge is in the graph

has_edge(G2, 2, 3)
true

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions