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

Inconsistence between out_edges and edge_index #196

Open
malbarbo opened this issue Aug 11, 2015 · 4 comments
Open

Inconsistence between out_edges and edge_index #196

malbarbo opened this issue Aug 11, 2015 · 4 comments

Comments

@malbarbo
Copy link

Let's consider this example

julia> g = simple_graph(2, is_directed=false)
Undirected Graph (2 vertices, 0 edges)

julia> add_edge!(g, 1, 2)
edge [1]: 1 -- 2

julia> out_edges(1, g)[1] == out_edges(2, g)[1]
false

julia> edge_index(out_edges(1, g)[1], g) == edge_index(out_edges(2, g)[1], g)
true

Conceptually the out edges in the example should be equal (g is undirected). It's inconsistent and confusing the index of different edges to be equal, modifying a map using the index of different edges could change the same value.

Networkx gives the same result...

@sbromberger
Copy link
Contributor

sbromberger commented Aug 11, 2015

I think the existing behavior is reasonable, since the edges are technically different. That is, out_edges(1,g)[1] is the edge 1->2, and out_edges(2,g)[1] is the edge 2->1. The only way you could determine equality is if == was supplied enough information to determine whether the edges were part of a directed graph (in which case 1->2 != 2->1), or undirected (in which case an argument could be made that 1->2 == 2->1). Absent that directedness information, there's no way for == to tell.

I also note that out_edges() is undefined for undirected graphs in NetworkX.

@malbarbo
Copy link
Author

A simple solution is to compare the index of the edges. This does not create a issue with directed graph, because the edges 1->2 and 2->1 will have different indexes.

Using edges method of undirect graphs in Networkx gives the same result. Interesting in graph-tool (https://graph-tool.skewed.de/) the edges are equals.

@sbromberger
Copy link
Contributor

A simple solution is to compare the index of the edges.

I've been struggling with this because in my implementation edges don't have indices (they're in a Set()). The other issue is that, in my case, edges are immutables and independent of graphs, so there's no way to define equality for undirected edges (that is, Edge(x,y) == Edge(y,x)) without relying on some information (directedness) contained within the graph type.

The concept of directedness of edges therefore is a new construct and introduces more complexity than benefit at this time in my case.

Interesting discussion though!

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

No branches or pull requests

3 participants