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

feat(kernel): implement DSATUR coloring algorithm for vertices #245

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

imrn99
Copy link
Collaborator

@imrn99 imrn99 commented Dec 3, 2024

Description

Associated issue: closes #236

Content description:

  • add add_attribute_storage method to CMap2 for convenience
  • implement the DSATUR coloring algorithm. ref: https://fr.wikipedia.org/wiki/DSATUR. FR page has better step descriptions

Follow-up

Aside from using it, I think the algorithm implementation can be modified to handle coloring on all types of I-cells, using a trait and the enum_dispatch crate to avoid dyn object lookup costs.

@codecov-commenter
Copy link

codecov-commenter commented Dec 3, 2024

Codecov Report

Attention: Patch coverage is 97.40260% with 6 lines in your changes missing coverage. Please review.

Project coverage is 79.77%. Comparing base (c43fd51) to head (e7dbe28).

Files with missing lines Patch % Lines
honeycomb-kernels/src/coloring/mod.rs 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #245      +/-   ##
==========================================
+ Coverage   78.97%   79.77%   +0.80%     
==========================================
  Files          52       55       +3     
  Lines        6834     7065     +231     
==========================================
+ Hits         5397     5636     +239     
+ Misses       1437     1429       -8     

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

@imrn99
Copy link
Collaborator Author

imrn99 commented Dec 3, 2024

TODO:

  • doc
  • test
  • deal with ephemeral allocations

@imrn99 imrn99 changed the title feat(kernel): implement a vertex coloring algorithm feat(kernel): implement DSATUR coloring algorithm for vertices Dec 4, 2024
@imrn99 imrn99 marked this pull request as ready for review December 4, 2024 13:58
Copy link
Member

@cedricchevalier19 cedricchevalier19 left a comment

Choose a reason for hiding this comment

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

I am not fully convinced by the implementation.

/// # Return
///
/// The function will return the maximal used color, i.e. the `n_color_used - 1`.
pub fn color<T: CoordsFloat>(cmap: &mut CMap2<T>) -> u8 {
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if it is a good name. Perhaps the algorithm name will be better. Add to the description it is a distance-1 coloring of the vertices.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I re-export the function as color_dsatur in the coloring module. I can switch it to dsatur if you want

pub fn color<T: CoordsFloat>(cmap: &mut CMap2<T>) -> u8 {
cmap.add_attribute_storage::<Color>();

// build graph data as a collection of (Vertex, Vec<Neighbors>)
Copy link
Member

Choose a reason for hiding this comment

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

Could this part be helpful elsewhere?
You can add a way to create a graph from a CMap. And use things like Coupe later ;).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Could this part be helpful elsewhere? You can add a way to create a graph from a CMap.

Yeah, I think I can also make it generic enough to handle all possible adjacency types (e.g. here we're using vertex-vertex, but we could fetch incident faces for another usage).

And use things like Coupe later ;).

I actually wanted to try and use it, but I think all coloring algorithms of coupe are focused on balancing weights, rather than making independent subsets. Is that right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm actually going to implement my idea for graphes in another Pr, and I'll sync this branch with master to use it after.

// - not colored
// - of highest saturation
// - if there are multiple, take the one of highest degree
crt_node = nodes
Copy link
Member

Choose a reason for hiding this comment

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

Can you comment on the complexity?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll add it to the doc, but it's O(n²)

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.

[Improvement]: implement a coloring algorithm
3 participants