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

Contraction of edges in a graph. #13239

Open
sagetrac-lkeough mannequin opened this issue Jul 12, 2012 · 9 comments
Open

Contraction of edges in a graph. #13239

sagetrac-lkeough mannequin opened this issue Jul 12, 2012 · 9 comments

Comments

@sagetrac-lkeough
Copy link
Mannequin

sagetrac-lkeough mannequin commented Jul 12, 2012

Contracts edges in a graph so that we can compute the Tutte polynomial (#1314)

This version of contracting edges is different from #7304 (this code will keep resulting multiedges and remove contracted edge).

CC: @sagetrac-jeremy-l-martin @dcoudert

Component: graph theory

Keywords: SD40

Author: Lauren Keough, Jeremy Martin

Reviewer: Marshall Hampton, David Coudert

Issue created by migration from https://trac.sagemath.org/ticket/13239

@sagetrac-lkeough sagetrac-lkeough mannequin added this to the sage-5.11 milestone Jul 12, 2012
@sagetrac-lkeough
Copy link
Mannequin Author

sagetrac-lkeough mannequin commented Jul 12, 2012

Author: Lauren Keough, Jeremy Martin

@sagetrac-lkeough
Copy link
Mannequin Author

sagetrac-lkeough mannequin commented Jul 12, 2012

Attachment: trac_13239.patch.gz

@sagetrac-lkeough
Copy link
Mannequin Author

sagetrac-lkeough mannequin commented Jul 12, 2012

Changed keywords from none to SD40

@sagetrac-mhampton
Copy link
Mannequin

sagetrac-mhampton mannequin commented Jul 12, 2012

Reviewer: Marshall Hampton

@dcoudert
Copy link
Contributor

Changed reviewer from Marshall Hampton to Marshall Hampton, David Coudert

@dcoudert
Copy link
Contributor

comment:4

Hello,

I don't understand this new patch. If the behavior of the contract_edge function proposed in patch #7304 is not adapted to your purpose, you could add extra parameters (inplace = False, keep_multiedges, etc.)

Furthermore, it works only for undirected graphs. So it should at least be in graph.py and not in generic_graph.py.

In the following example, arc (3,0) becomes arc (0,3)

sage: D = digraphs.RandomDirectedGNP(5,.5)
sage: h = D.contraction((0,1))
sage: D.edges(labels=None)
[(0, 1), (0, 2), (0, 3), (1, 0), (1, 3), (1, 4), (2, 0), (3, 0), (3, 1), (3, 4), (4, 2)]
sage: h.edges(labels=None)
[(0, 0), (0, 2), (0, 2), (0, 3), (0, 3), (0, 3), (0, 3), (0, 4), (2, 4), (3, 4)]

D.

@sagetrac-lkeough
Copy link
Mannequin Author

sagetrac-lkeough mannequin commented Jul 13, 2012

comment:5

Replying to @dcoudert:

Hello,

I don't understand this new patch. If the behavior of the contract_edge function proposed in patch #7304 is not adapted to your purpose, you could add extra parameters (inplace = False, keep_multiedges, etc.)

#7304 will keep multiedges if you do G.allow_multiedges . However, we also need to do G.allow_loops (for the tutte polynomial), but if we do that then the patch leaves the contracted edge (rather than deleting it which is what we want). I suppose I could use their code and then add a line to mine that deletes that loop.

I'm not really sure what the best option is here. 7304 already has a lot of parameters and adding another might be very confusing. And I'm also not sure what most people mean by contracting an edge - I thought the definition I have written in this code was "the" definition, but it's becoming more apparent that it isn't at all! Perhaps I could just include this code in the Tutte polynomial code and not as a separate function? I'm very open to advice on this!

Furthermore, it works only for undirected graphs. So it should at least be in graph.py and not in generic_graph.py.

Okay, I will definitely move to graph.py unless I can figure out how to make it work for digraphs.

In the following example, arc (3,0) becomes arc (0,3)

sage: D = digraphs.RandomDirectedGNP(5,.5)
sage: h = D.contraction((0,1))
sage: D.edges(labels=None)
[(0, 1), (0, 2), (0, 3), (1, 0), (1, 3), (1, 4), (2, 0), (3, 0), (3, 1), (3, 4), (4, 2)]
sage: h.edges(labels=None)
[(0, 0), (0, 2), (0, 2), (0, 3), (0, 3), (0, 3), (0, 3), (0, 4), (2, 4), (3, 4)]

D.

@dcoudert
Copy link
Contributor

comment:6

If the #7304 function is not adapted to your purpose, it could be better to include the code in your function instead of creating a new one.

May be some people from Sage Days could give good advise.

@sagetrac-lkeough
Copy link
Mannequin Author

sagetrac-lkeough mannequin commented Jul 13, 2012

comment:7

Replying to @dcoudert:

If the #7304 function is not adapted to your purpose, it could be better to include the code in your function instead of creating a new one.

May be some people from Sage Days could give good advise.

A couple of graph theorists at Sage Days said they would prefer to have a function by the name of contraction that does what I described in the documentation for this one. It is very easy to adapt their code and call it contraction. I'm going to try both things and time them to see which is faster. Thanks!

@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@mkoeppe mkoeppe removed this from the sage-6.4 milestone Dec 29, 2022
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

4 participants