Skip to content

Implement IsCograph with bug fixes#904

Merged
mtorpey merged 25 commits intodigraphs:mainfrom
frankiegillis:IsCograph
Mar 19, 2026
Merged

Implement IsCograph with bug fixes#904
mtorpey merged 25 commits intodigraphs:mainfrom
frankiegillis:IsCograph

Conversation

@frankiegillis
Copy link
Contributor

@frankiegillis frankiegillis commented Mar 5, 2026

IsCograph

If merged, this implements the function IsCograph for a symmetric digraph without loops or multiple edges.

A symmetric digraph without loops or multiple edges is called a cograph if it does not contain a copy of the path graph P_4 on four vertices as an induced subgraph. Equivalently, cographs are those graphs which may be reached starting from a single vertex under the operations of series and parallel composition.

This function implements the algorithm for cograph recogntition given in "Habib, M., & Paul, C. (2005). A simple linear time algorithm for cograph recognition. Discrete Applied Mathematics, 145(2), 183-197."

This is a continuation of work done by @coraaked. I have rewritten the first half of the function (computing a factorising permutation) from scratch to avoid some bugs and conceptual errors. The second half of the function (the recognition test) remains the original code. There are no more bugs or errors, as far as I can tell.

I have also written tests and documentation for the function.

Please let me know if any further changes are required.

Testing

In addition to the test files, I have tested IsCograph on the following families of graphs:

  • All 1171 connected cographs on fewer than 10 vertices, obtained from the database of cographs at houseofgraphs.org/meta-directory/cographs. Returned true on all graphs, as expected.
  • Symmetric closures of cycle digraphs on 1-100 vertices. Returned true for n<=4 and false otherwise, as expected.
  • 1000 random symmetric digraphs without loops on 20 vertices. No errors.
  • Complete digraphs without loops on 1-100 vertices, and empty digraphs on 1-100 vertices. Returned true on all graphs, as expected.
  • The complete digraph without loops on 500 vertices. Returned true after about 33 seconds on my (not very fast) computer. The complete digraph on 1000 vertices exceeded the preset memory limit.
  • The symmetric closure of the cycle digraph on 1000 vertices. Returned false, as expected, in about 1 second.
  • The symmetric closure of the cycle digraph on 5000 vertices. Returned false, as expected, in about 25 seconds.
  • The digraph on 0 vertices. Returned true, as expected.

@codecov
Copy link

codecov bot commented Mar 5, 2026

Codecov Report

❌ Patch coverage is 98.37398% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.35%. Comparing base (f82c9f1) to head (93b8cbf).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
gap/prop.gi 98.36% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main     #904    +/-   ##
========================================
  Coverage   97.35%   97.35%            
========================================
  Files          50       50            
  Lines       20917    21040   +123     
  Branches      639      639            
========================================
+ Hits        20363    20484   +121     
- Misses        489      491     +2     
  Partials       65       65            

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@james-d-mitchell james-d-mitchell changed the title Implement IsCograph with bug fixes Implement IsCograph with bug fixes Mar 11, 2026
@mtorpey
Copy link
Collaborator

mtorpey commented Mar 18, 2026

I've made a PR to this branch on Frankie's fork, with a few suggestions of my own. If he merges that, I'll merge this! :)

Improvements to IsCograph branch
@mtorpey mtorpey merged commit b8adb8a into digraphs:main Mar 19, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants