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

line_graph for multigraphs #39518

Merged
merged 8 commits into from
Feb 21, 2025
Merged

Conversation

fabien-vignes
Copy link
Contributor

@fabien-vignes fabien-vignes commented Feb 13, 2025

We generalize the line_graph method to graphs possibly with multiple edges and/or loops.
It is useful in order to compute the line-graph of a multigraph but also to generate the edge-colorings of a multigraph from the all_graph_coloring method.

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

Copy link

github-actions bot commented Feb 13, 2025

Documentation preview for this PR (built with commit 34bece3; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@vneiger vneiger added the sd128 tickets of Sage Days 128 Le Teich label Feb 13, 2025
@fchapoton
Copy link
Contributor

one failing doctest in

sage -t --long --warn-long 30.0 --random-seed=286735480429121101562228604801325644303 src/sage/graphs/generic_graph.py

to be investigated

Copy link
Contributor

@dcoudert dcoudert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have other possible changes in mind, to get a faster code and to avoid calls to hash, but we can do that a future PR. Let us first finalize this one.

A more important question is if we should directly label the vertices of the line-graph with integers instead of tuples.

@fabien-vignes
Copy link
Contributor Author

one failing doctest in

sage -t --long --warn-long 30.0 --random-seed=286735480429121101562228604801325644303 src/sage/graphs/generic_graph.py

to be investigated

In constast with the current version of line_graph, the new proposed method makes a copy of the graph g given as an input. The vertices and edges of the copy are sorted. This makes the order of the output of coarsest_equitable_refinement in the failing doctest to be slightly different (but fundamentally the same).
A way to solve this would be to modify the example of coarsest_equitable_refinement (in sage/src/sage/graphs/generic_graph.py) as follows:

sage: ss = (graphs.WheelGraph(5)).line_graph(labels=False)
sage: L = ss.coarsest_equitable_refinement(prt)
sage: sorted(sorted(parts) for parts in L)
[[(0, 1)], [(0, 2), (0, 4)], [(0, 3)], [(1, 2), (1, 4)], [(2, 3), (3, 4)]]

@fabien-vignes
Copy link
Contributor Author

one failing doctest in
sage -t --long --warn-long 30.0 --random-seed=286735480429121101562228604801325644303 src/sage/graphs/generic_graph.py
to be investigated

In constast with the current version of line_graph, the new proposed method makes a copy of the graph g given as an input. The vertices and edges of the copy are sorted. This makes the order of the output of coarsest_equitable_refinement in the failing doctest to be slightly different (but fundamentally the same). A way to solve this would be to modify the example of coarsest_equitable_refinement (in sage/src/sage/graphs/generic_graph.py) as follows:

sage: ss = (graphs.WheelGraph(5)).line_graph(labels=False) sage: L = ss.coarsest_equitable_refinement(prt) sage: sorted(sorted(parts) for parts in L) [[(0, 1)], [(0, 2), (0, 4)], [(0, 3)], [(1, 2), (1, 4)], [(2, 3), (3, 4)]]

With the modifications proposed by @dcoudert, the PR should pass the doctests without modification.

Copy link
Contributor

@dcoudert dcoudert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to integrate all the changes I proposed.

Also, you may add the definition you use for the line graph of a multigraph. As we discussed, we have 2 cases: connect 2 vertices if the corresponding edges are incident in $g$, or connect 2 edges if the corresponding edges have exactly one extremity in common in $g$. You use the first definition. We may add the second later.

Copy of the input graph g only if g.has_multiple_edges().
New copy is called g as the input.
In case return_labels == True, the returned dictionary is different from
a previous version. An example output had to be modified accordingly.
@dcoudert
Copy link
Contributor

LGTM. The only remaining issue is that comments should be formatted in 80 columns mode (should node exceed the 80th columns of the text).
@fchapoton should we do the change now or let it for a future cleaning of the file (which will happen soon I think) ?

@fchapoton
Copy link
Contributor

Given that this is the first Pull Request of Fabien, I suggest that this is approved right now.

Copy link
Contributor

@dcoudert dcoudert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Thank you for this improvement.

@vbraun vbraun merged commit bd626ef into sagemath:develop Feb 21, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: graph theory sd128 tickets of Sage Days 128 Le Teich
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants