DirectedGraph equality testing

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

DirectedGraph equality testing

Aidan Delaney
Dear all,
        I've been trying to test for deep vertex & edge equality in a
DirectedGraph.  An example is below.  It appears that this fails
because, I think, DefaultEdge needs a non-default hashCode
implementation.  My GitHub pull-request is at [1], but it causes more
problems than it solves.

Am I just incorrect in trying to use JGraphT in this way to check graph
equality?  Is there some other way I should be doing this?

DirectedGraph<String, DefaultEdge> g1 =
            new SimpleDirectedGraph<String,
DefaultEdge>(DefaultEdge.class);
        DirectedGraph<String, DefaultEdge> g2 =
            new SimpleDirectedGraph<String,
DefaultEdge>(DefaultEdge.class);

        g1.addVertex("A");
        g2.addVertex("A");

        assertEquals(g1, g2);

        g1.addVertex("B");
        g2.addVertex("B");

        assertEquals(g1, g2);

[1] https://github.com/jgrapht/jgrapht/pull/148

--
Dr Aidan Delaney
Principal Lecturer
Computing, Engineering & Maths
University of Brighton

@aidandelaney

------------------------------------------------------------------------------
_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users
Reply | Threaded
Open this post in threaded view
|

Re: DirectedGraph equality testing

John Sichi
Administrator
For multigraphs, e1 and e2 may both have source v1 and target v2, and yet they are two distinct edges.

In general, "equality" for a graph isn't a very useful concept due to the fact that g1 and g2 may be isomorphic even though !g1.equals(g2).


On Wed, Aug 12, 2015 at 2:30 PM, Aidan Delaney <[hidden email]> wrote:
Dear all,
        I've been trying to test for deep vertex & edge equality in a
DirectedGraph.  An example is below.  It appears that this fails
because, I think, DefaultEdge needs a non-default hashCode
implementation.  My GitHub pull-request is at [1], but it causes more
problems than it solves.

Am I just incorrect in trying to use JGraphT in this way to check graph
equality?  Is there some other way I should be doing this?

DirectedGraph<String, DefaultEdge> g1 =
            new SimpleDirectedGraph<String,
DefaultEdge>(DefaultEdge.class);
        DirectedGraph<String, DefaultEdge> g2 =
            new SimpleDirectedGraph<String,
DefaultEdge>(DefaultEdge.class);

        g1.addVertex("A");
        g2.addVertex("A");

        assertEquals(g1, g2);

        g1.addVertex("B");
        g2.addVertex("B");

        assertEquals(g1, g2);

[1] https://github.com/jgrapht/jgrapht/pull/148

--
Dr Aidan Delaney
Principal Lecturer
Computing, Engineering & Maths
University of Brighton

@aidandelaney

------------------------------------------------------------------------------
_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users


------------------------------------------------------------------------------

_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users
Reply | Threaded
Open this post in threaded view
|

Re: DirectedGraph equality testing

Aidan Delaney

John,
Thanks a lot for the clarification. Of course I was too wrapped up in what I was trying to do to consider the multigraph case. I'll modify my approach.

--
Aidan Delaney

On Aug 13, 2015 12:56 AM, "John Sichi" <[hidden email]> wrote:
For multigraphs, e1 and e2 may both have source v1 and target v2, and yet they are two distinct edges.

In general, "equality" for a graph isn't a very useful concept due to the fact that g1 and g2 may be isomorphic even though !g1.equals(g2).


On Wed, Aug 12, 2015 at 2:30 PM, Aidan Delaney <[hidden email]> wrote:
Dear all,
        I've been trying to test for deep vertex & edge equality in a
DirectedGraph.  An example is below.  It appears that this fails
because, I think, DefaultEdge needs a non-default hashCode
implementation.  My GitHub pull-request is at [1], but it causes more
problems than it solves.

Am I just incorrect in trying to use JGraphT in this way to check graph
equality?  Is there some other way I should be doing this?

DirectedGraph<String, DefaultEdge> g1 =
            new SimpleDirectedGraph<String,
DefaultEdge>(DefaultEdge.class);
        DirectedGraph<String, DefaultEdge> g2 =
            new SimpleDirectedGraph<String,
DefaultEdge>(DefaultEdge.class);

        g1.addVertex("A");
        g2.addVertex("A");

        assertEquals(g1, g2);

        g1.addVertex("B");
        g2.addVertex("B");

        assertEquals(g1, g2);

[1] https://github.com/jgrapht/jgrapht/pull/148

--
Dr Aidan Delaney
Principal Lecturer
Computing, Engineering & Maths
University of Brighton

@aidandelaney

------------------------------------------------------------------------------
_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users


------------------------------------------------------------------------------

_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users