Chordal coloring algorithm.#202
Conversation
|
Oops! I'll rerun & update the benchmarks. |
|
Hi @samuelsonric, thank you for this suggestion! Indeed, I had skipped the experimental section when reading Efficient Computation of Sparse Hessians Using Coloring and Automatic Differentiation (Gebremehdin et al., 2008), but such special cases deserve our attention. Banded matrices in particular are very relevant for SciML applications, and they generate are a special case of chordal graphs. Here are a few remarks:
|
|
Yes: |
I had the vague notion that this was an NP-hard problem? |
|
Ok: I think a package extension makes sense. A chordal routine could easily be integrated into an |
This is a bit subtle. This is the standard strategy for chordality testing. Computing a PEO for general graphs is NP hard! |
|
My suggestion would be to
This seems like a minimum-effort way to add this functionality without fully solving #67, because it would be inserted within the existing |
|
Added a LargestFirst julia> algorithm = GreedyColoringAlgorithm(LargestFirst());
julia> ncolors(coloring(matrix, problem, algorithm))
13PerfectEliminationOrder julia> import CliqueTrees
julia> algorithm = GreedyColoringAlgorithm(PerfectEliminationOrder());
julia> ncolors(coloring(matrix, problem, algorithm))
11julia> using SimpleGraphs, SimpleGraphAlgorithms
julia> chromatic_number(UndirectedGraph(matrix))
6 |
|
|
|
Added tests! |
gdalle
left a comment
There was a problem hiding this comment.
Thanks for this initiative! Here are a few remarks of mine ;)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #202 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 13 14 +1
Lines 1628 1635 +7
=========================================
+ Hits 1628 1635 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Should be everything. |
|
The docs should build successfully, now! |
|
Wait, on second thought I'm not sure the order-based approach is right. It would get us an optimal distance-1 coloring if we applied a greedy distance-1 algorithm after, but we actually apply a greedy acyclic algorithm after. I struggle to see whether we have any optimality guarantees that way. EDIT: actually I think it's fine, because Lemma 4.2 of the 2008 paper states
|
|
Thanks @samuelsonric for this PR! |
Chordal graphs can be minimally colored in linear time, and every such coloring is acyclic. This paper discusses chordal graphs in §4 and suggests that they arise in practice. This patch adds an algorithm
ChordalColoringAlgorithmthat handles this case. Here are benchmarks for acyclic coloring of a band graph (defined in the paper).greedy coloring
chordal coloring
The algorithm errors if the graph is not chordal.
If you like the algorithm then I can add tests and so forth.