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

CP-65877: Edge equality backwards? #159

Open
fubar-coder opened this issue Jun 11, 2018 · 0 comments
Open

CP-65877: Edge equality backwards? #159

fubar-coder opened this issue Jun 11, 2018 · 0 comments

Comments

@fubar-coder
Copy link
Contributor

From unknown CodePlex user on Sunday, 05 February 2017 06:34:15

I am using an UndirectedGraph with a default TEdge of UndirectedEdge. I set AllowParallelEdges to false. However, I was surprised to find that I could still create an edge between two existing verticies that already had an edge between them as long as I created the edge in the opposite direction as before. This seemed wrong to me since this is an undirected graph so direction shouldn't matter. I then looked at your source to see what the default edge equality was done. I was surprised to see this:

        /// <summary>
        /// Returns the most efficient comporer for the particular type of TEdge.
        /// If TEdge implements IUndirectedEdge, then only the (source,target) pair
        /// has to be compared; if not, (source, target) and (target, source) have to be compared.
        /// </summary>
        /// <typeparam name="TVertex">type of the vertices</typeparam>
        /// <typeparam name="TEdge">type of the edges</typeparam>
        /// <returns></returns>
        public static EdgeEqualityComparer<TVertex, TEdge> GetUndirectedVertexEquality<TVertex, TEdge>()
            where TEdge : IEdge<TVertex>
        {
            if (typeof(IUndirectedEdge<TVertex>).IsAssignableFrom(typeof(TEdge)))
                return new EdgeEqualityComparer<TVertex, TEdge>(SortedVertexEquality<TVertex, TEdge>);
            else
                return new EdgeEqualityComparer<TVertex, TEdge>(UndirectedVertexEquality<TVertex, TEdge>);
        }

Isn't that backwards? If an edge is IUndirectedEdge, then we should use the UndirectedVertexEquality NOT the SortedVertexEquality? If I manually set the equality to UndirectedVertexEquality, then I get the behavior I expected.

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

No branches or pull requests

1 participant