Skip to content
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

Comparison of WeightedEdge should take into consideration whether the edges are directed #82

Open
tbbruno opened this issue Feb 26, 2022 · 1 comment

Comments

@tbbruno
Copy link

tbbruno commented Feb 26, 2022

Let's say I have two weighted and not directed edges, connecting the same vertices, as follows:

let edgeA = WeightedEdge<Int> = WeightedEdge(u: 0, v: 1, directed: false, weight: 10)
let edgeB = WeightedEdge<Int> = WeightedEdge(u: 1, v: 0, directed: false, weight: 10)

Currently we have so that edgeA == edgeB returns false.

Shouldn't the ==(_:_:) operator take into consideration whether they're directed? Or am I missing something?
So in this particular scenario I would expect edgeA == edgeB to return true, as they are not directed.


In summary we would have:

let directedEdgeA = WeightedEdge<Int> = WeightedEdge(u: 0, v: 1, directed: false, weight: 10)
let directedEdgeB = WeightedEdge<Int> = WeightedEdge(u: 1, v: 0, directed: false, weight: 10)
directedEdgeA == directedEdgeB // returns `true`


let undirectedEdgeC = WeightedEdge<Int> = WeightedEdge(u: 0, v: 1, directed: true, weight: 10)
let undirectedEdgeD = WeightedEdge<Int> = WeightedEdge(u: 1, v: 0, directed: true, weight: 10)
undirectedEdgeC == undirectedEdgeD // returns `false`

If there are any worries about how changing the ==(_:_:) implementation would affect other features, should we have a separate method to compare two edges?
Any thoughts on this?

@davecom
Copy link
Owner

davecom commented Feb 28, 2022

It's a fair question. I don't know if this would break anyone's existing code. Is it causing a particular problem for you? Since I wouldn't really call it a bug, but more of a vagary we would make the change in a new point release not a bug fix release. i.e. 3.2 not 3.1.1

If the edges were not directed, we would then have to check if they were between the same two vertices, which would have a very slight performance cost if an algorithm was doing a ton of equality checks.

One could also argue, that maybe the data matters more than the graph theory in some circumstances. For example, imagine a program that was marking which vertex the edge was created from and to even though it allowed traversal in both directions.

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

No branches or pull requests

2 participants