sage icon indicating copy to clipboard operation
sage copied to clipboard

Module and Graph method for Projective planarity via forbidden minors

Open juan-mlr opened this issue 9 months ago • 7 comments

Addresses #37937 (to enable checking if a graph in projective planar) by

  1. creating a new module, src/sage/graphs/projective_planarity.py, that holds the relevant forbidden minors and a function to search for them in another graph.
  2. adding is_projective_planar method to Graph.

:memo: Checklist

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

:hourglass: Dependencies

juan-mlr avatar Mar 27 '25 14:03 juan-mlr

Documentation preview for this PR (built with commit 2849c51186a186aa74ab983e9ee2a9b9d72d0109; changes) is ready! :tada: This preview will update shortly after each push to this PR.

github-actions[bot] avatar Mar 29 '25 09:03 github-actions[bot]

@dcoudert can you comment on how we should declare this file in meson.build? It's just a python file with no cython or c to go with it.

you will have to declare the new file in src/sage/graphs/meson.build and in src/doc/en/reference/graphs/index.rst

steveschluchter avatar Apr 09 '25 01:04 steveschluchter

@dcoudert can you comment on how we should declare this file in meson.build? It's just a python file with no cython or c to go with it.

you will have to declare the new file in src/sage/graphs/meson.build and in src/doc/en/reference/graphs/index.rst

open file src/sage/graphs/meson.build and add the name of the file in the block py.install_sources(...)

dcoudert avatar Apr 09 '25 08:04 dcoudert

@dcoudert

Can you help us avoid the circular import problem?

These lines appear in projective_planarity.py, and we're trying to keep the bulk of the code for the projective planarity check in a separate file.

from sage.graphs.graph import Graph from sage.graphs.generators.basic import ( CompleteGraph, CompleteBipartiteGraph, CompleteMultipartiteGraph, CycleGraph )

We could also presumably put the code in the graph.py file, but that's presumably not the way you want it done.

steveschluchter avatar Apr 16 '25 02:04 steveschluchter

@dcoudert thank you for your comments. We have made a new merge into this PR.

steveschluchter avatar May 03 '25 04:05 steveschluchter

@dcoudert We addressed your latest comments. Thank you for your thoughts.

steveschluchter avatar May 07 '25 02:05 steveschluchter

@dcoudert We have acted on your latest comments. Thank you for your thoughts.

steveschluchter avatar May 12 '25 03:05 steveschluchter

@dimpase Do you need anything else from us?

steveschluchter avatar May 25 '25 05:05 steveschluchter

@dcoudert sorry, I didn't mean to approve this.

dimpase avatar May 25 '25 05:05 dimpase

@dimpase, can you try again to trigger CI runs ?

dcoudert avatar May 31 '25 09:05 dcoudert

I cannot - @roed or @saraedum can, but they are busy, and on the other hand reluctant to give such rights to e.g. me or you.

dimpase avatar May 31 '25 15:05 dimpase

My main concern is that method is_projective_planar is extremely slow (that's why we must add a # long time tag to a doctest). Searching for minors is a difficult problem. Do you know any (faster) combinatorial algorithm ?

sage: P = graphs.PetersenGraph()
sage: %time P.is_projective_planar()
CPU times: user 2min 51s, sys: 642 ms, total: 2min 52s
Wall time: 2min 52s
True
sage: K44 = graphs.CompleteBipartiteGraph(4, 4)
sage: %time K44.is_projective_planar(return_map=True)
CPU times: user 2.12 s, sys: 11.5 ms, total: 2.13 s
Wall time: 2.13 s
(False, {0: [0], 1: [1], 2: [2], 3: [3], 4: [4], 5: [5], 6: [6], 7: [7]})

dcoudert avatar Jun 01 '25 09:06 dcoudert

can this be computed via combinatorial embeddings?

dimpase avatar Jun 01 '25 17:06 dimpase

@dcoudert @dimpase

I don't know of any other implemented projective planarity algorithm.

This work is related to a research project that @juan-mlr and I are doing, which is a continuation of https://combinatorialpress.com/article/jcmcc/Some-Excluded-Minors-for-the-Spindle-Surface.pdf for the projective plane.

Thank you very much for your thoughtfulness.

steveschluchter avatar Jun 01 '25 21:06 steveschluchter

https://doc.sagemath.org/html/en/reference/graphs/sage/graphs/genus.html lets you compute the (oriented) genus of a graph, and it's reasonably fast on small graphs. If I understand this well, it's helpful in deciding the non-oriented genus, as it gives you Euler characteristic.

dimpase avatar Jun 01 '25 23:06 dimpase

There is also this paper by Mohar https://doi.org/10.1006/jagm.1993.1050 https://www.sfu.ca/~mohar/Reprints/1993/BM93_JA15_Mohar_ProjectivePlanarity.pdf However, it might not be easy to implement.

Let us finish this PR. We can let the implementation of a faster method in the TODO list.

dcoudert avatar Jun 02 '25 16:06 dcoudert

Is there anything else we need to do? @dcoudert

steveschluchter avatar Jun 15 '25 16:06 steveschluchter

@dcoudert thank you for staying with me on this PR through each commit. I'd like to see the Mojar paper get implemented. Perhaps I'll have time in the future. That sounds like a nice challenge.

steveschluchter avatar Jun 18 '25 17:06 steveschluchter

sage -t --warn-long 30.0 --random-seed=123 src/sage/graphs/generators/families.py  # 2 doctests failed

vbraun avatar Jun 20 '25 23:06 vbraun

For some reason, the code of method p2_forbidden_minors is inside de code of method petersen_family. Indeed, method DeltaYTrans and YDeltaTrans are sub-methods of petersen_family and are followed by some code of that method. Please move the code of method p2_forbidden_minors at a correct place, i.e., outside.

Sorry Volker for not seing that before. Not easy to work without CIs.

dcoudert avatar Jun 21 '25 07:06 dcoudert

I'm sorry about the mistake. I should have caught that one. I've made another push. Thank you for your comments and support.

steveschluchter avatar Jul 04 '25 06:07 steveschluchter

Thank you @dcoudert for helping us through this. Is there anything else you need?

steveschluchter avatar Jul 14 '25 05:07 steveschluchter

Now that this PR is done, it would be nice to implement a faster algorithm (in a future follow up PR)

dcoudert avatar Jul 14 '25 06:07 dcoudert

Thanks for the vote of confidence @dcoudert. I thought this wasn't done becuase it was still open. We'll see about implementing Mojar's algorithm. That's going to be quite a haul.

steveschluchter avatar Jul 17 '25 07:07 steveschluchter