wting / python-graph

Automatically exported from code.google.com/p/python-graph
Other
5 stars 3 forks source link

Linking, unlinking and relinking a hypernode to a hyperedge will fail #86

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Steps to reproduce the problem

a = hypergraph()

a.add_nodes([1,2,3])
a.add_edges([4,5])

a.link(3,5)
a.unlink(3,5)
a.link(3,5)

I expected no exception but I got an exception instead

the reason can be easily be seen from the source of hypergraph.py:

    def link(self, node, hyperedge):
        """
        Link given node and hyperedge.

        @type  node: node
        @param node: Node.

        @type  hyperedge: node
        @param hyperedge: Hyperedge.
        """
        if (hyperedge not in self.node_links[node]):
            self.edge_links[hyperedge].append(node)
            self.node_links[node].append(hyperedge)
            self.graph.add_edge(((node,'n'), (hyperedge,'h')))
        else:
            raise AdditionError("Link (%s, %s) already in graph" % (node, hyperedge))

    def unlink(self, node, hyperedge):
        """
        Unlink given node and hyperedge.

        @type  node: node
        @param node: Node.

        @type  hyperedge: hyperedge
        @param hyperedge: Hyperedge.
        """
        self.node_links[node].remove(hyperedge)
        self.edge_links[hyperedge].remove(node)

unlink should have something like:

self.graph.del_edge(((node,'n'), (hyperedge,'h')))

Original issue reported on code.google.com by emanuelez@gmail.com on 1 Feb 2011 at 3:49

GoogleCodeExporter commented 9 years ago
Accepted. Thanks for your report.

Original comment by pmatiello on 1 Feb 2011 at 10:28

GoogleCodeExporter commented 9 years ago
Would you be willing to generate a patch & an additional test case? I'd be 
happy to validate & merge in any changes you propose. You can submit your 
changes as a SVN diff if you are familiar with that.

Original comment by s...@stodge.org on 1 Feb 2011 at 11:14

GoogleCodeExporter commented 9 years ago
I can surely generate a patch and add a test case... as for the svn diff I'll 
see what I can do :) I never used SVN before (I only interfaced to an SVN 
server throw Git before).

Will work on it tomorrow. 

Original comment by emanuelez@gmail.com on 1 Feb 2011 at 11:29

GoogleCodeExporter commented 9 years ago
That was easier than I expected so here it is!

Original comment by emanuelez@gmail.com on 1 Feb 2011 at 11:48

Attachments:

GoogleCodeExporter commented 9 years ago
Great, would you also include a unit-test. Ideally it should be nothing more 
than the code you've already found - we just want to show in test-form that the 
formerly broken test is now working. 

Thanks for the diff!

Original comment by s...@stodge.org on 1 Feb 2011 at 11:51

GoogleCodeExporter commented 9 years ago
the diff I provided already includes an additional testcase for 
unittests-hypergraph.py

Original comment by emanuelez@gmail.com on 1 Feb 2011 at 11:53

GoogleCodeExporter commented 9 years ago
Any news on this?

Original comment by emanuelez@gmail.com on 21 Feb 2011 at 12:57

GoogleCodeExporter commented 9 years ago
Maybe other devs are busy at the moment so I took the courtesy and applied your 
patch to trunk after verifying and testing it on my local copy. The patch 
itself was a no-brainer. Thank you for your contribution!

See r726

Original comment by tomaz.ko...@gmail.com on 27 Feb 2011 at 2:26

GoogleCodeExporter commented 9 years ago
Thank you Tomaz :)

Original comment by emanuelez@gmail.com on 27 Feb 2011 at 4:40

GoogleCodeExporter commented 9 years ago
emanuelez, can you provide us your first name, last name and email address so 
we can give you credit for the fix?

Original comment by pmatiello on 14 Mar 2011 at 1:27

GoogleCodeExporter commented 9 years ago
Emanuele Zattin, emanuelez@gmail.com

Original comment by emanuelez@gmail.com on 14 Mar 2011 at 1:30

GoogleCodeExporter commented 9 years ago
It's done. Thanks.

Original comment by pmatiello on 14 Mar 2011 at 10:00