Skip to content

ENH: Add is_perfect_graph using SPGT (follow-up to #8111) - #8318

Merged
dschult merged 13 commits into
networkx:mainfrom
Aka2210:enh-is-perfect-graph
Oct 16, 2025
Merged

dschult merged 13 commits into
networkx:mainfrom
Aka2210:enh-is-perfect-graph

Conversation

@Aka2210

@Aka2210 Aka2210 commented Oct 9, 2025

Copy link
Copy Markdown
Contributor

Implements is_perfect_graph(G) based on the Strong Perfect Graph Theorem (SPGT).

The function returns True if and only if neither the graph nor its complement contains an induced odd chordless cycle (odd hole) of length ≥ 5.

This refines and completes the earlier proposal in #8111.

The current implementation runs in exponential time in the worst case, while the full SPGT recognition algorithm is polynomial (O(n⁹)) but too intricate to include here.

sourabh-sudesh-paradeshi and others added 4 commits June 25, 2025 14:11
…string

Refactors the `is_perfect_graph` function (originally proposed in PR networkx#8111)
to use `nx.chordless_cycles` for induced odd-hole detection instead of the
path-based enumeration approach. This improves clarity and efficiency while
keeping the implementation faithful to the Strong Perfect Graph Theorem (SPGT).
Adds a third "Related Specialized Algorithms" section to the docstring of
`is_perfect_graph`, mentioning existing recognition functions for chordal and
bipartite. This clarifies the relationship between these subclasses and the
general SPGT-based check.
Comment thread networkx/algorithms/perfect_graph.py Resolved
Comment thread networkx/algorithms/perfect_graph.py Resolved
Comment thread networkx/algorithms/perfect_graph.py Resolved
@Aka2210

Aka2210 commented Oct 10, 2025

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed style feedback!
I’ve reviewed all of your suggestions and applied the changes accordingly.
Please let me know if there’s anything I might have missed or misapplied—much appreciated!

@rossbar rossbar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This LGTM , thanks for picking this one up @Aka2210 !

dschult
dschult previously approved these changes Oct 14, 2025

@dschult dschult left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @Aka2210 !

@dschult
dschult dismissed their stale review October 14, 2025 12:49

forgot to check docs

@dschult

dschult commented Oct 14, 2025

Copy link
Copy Markdown
Member

Oops... forgot to check the docs.
Can you connect this to the docs by adding a file doc/reference/algorithms/perfect_graph.rst? Maybe look at doc/reference/algorithms/moral.rst as a similarly simple case.

@Aka2210

Aka2210 commented Oct 14, 2025

Copy link
Copy Markdown
Contributor Author

Thanks for catching that!
I’ve added doc/reference/algorithms/perfect_graph.rst

@dschult

dschult commented Oct 16, 2025

Copy link
Copy Markdown
Member

Sorry -- I seem to have forgotten another step:
We need to add the line perfect_graph to the algorithms index.rst file: doc/reference/algorithms/index.rst (the lines are alphabetically ordered)

The CI documentation artifact webpages still don't show the is_perfect_graph docs. and the Ci documentation (under build docs section log) says that perfect_graph.rst is not referred to anywhere so it doesn't have any links to it.

Easy fix.

@Aka2210

Aka2210 commented Oct 16, 2025

Copy link
Copy Markdown
Contributor Author

Sorry -- I seem to have forgotten another step: We need to add the line perfect_graph to the algorithms index.rst file: doc/reference/algorithms/index.rst (the lines are alphabetically ordered)

The CI documentation artifact webpages still don't show the is_perfect_graph docs. and the Ci documentation (under build docs section log) says that perfect_graph.rst is not referred to anywhere so it doesn't have any links to it.

Easy fix.

I’ve added perfect_graph to doc/reference/algorithms/index.rst .
I rebuilt the docs locally with make html, and the is_perfect_graph page now appears correctly in the algorithms index.

@dschult
dschult merged commit 1660ac3 into networkx:main Oct 16, 2025
@dschult dschult added this to the 3.6 milestone Oct 16, 2025
@Aka2210
Aka2210 deleted the enh-is-perfect-graph branch October 22, 2025 05:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants