Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/coloring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -422,16 +422,31 @@ Encode a set of 2-colored trees resulting from the [`acyclic_coloring`](@ref) al
$TYPEDFIELDS
"""
struct TreeSet{T}
"""
For a tree index `1 <= k <= nt`, the list
`list = reverse_bfs_order[tree_edge_indices[k]:(tree_edge_indices[k+1]-1)]` is a list of edges
`list[i] = (leaf, inner)` of the `k`th tree such that `leaf` is a leaf of the tree containing
the edges `list[i:end]`.
From an other point of view, `reverse(list)` contains the edges in the order of a breadth first
(BFS) traversal order of the `k`th tree starting from a depth-minimizing root.
"""
reverse_bfs_orders::Vector{Tuple{T,T}}
"For a tree index `1 <= k <= nt`, `is_star[k]` indicates whether the `k`th three is a star."
is_star::Vector{Bool}
"""
`tree_edge_indices[1]` is one and `tree_edge_indices[k+1] - tree_edge_indices[k]` is the number of edges in the `k`th tree.
One can think of it as a kind of fused vector of offsets (similar to the `colptr` field of `SparseMatrixCSC`) of all trees together.
"""
tree_edge_indices::Vector{T}
"numbers of 2-colored trees for which trees sharing the same 2 colors have disjoint edges"
nt::T
end

function TreeSet(
g::AdjacencyGraph{T},
forest::Forest{T},
buffer::AbstractVector{T},
# The value of `reverse_bfs_orders` is ignored, we just provide the storage for it (or reuse memory allocated during acyclic coloring)
reverse_bfs_orders::Vector{Tuple{T,T}},
ne::Integer,
) where {T}
Expand Down Expand Up @@ -566,7 +581,15 @@ function TreeSet(
# Number of edges treated
num_edges_treated = zero(T)

# reverse_bfs_orders contains the reverse breadth first (BFS) traversal order for each tree in the forest
Copy link
Collaborator

@amontoison amontoison Jan 9, 2026

Choose a reason for hiding this comment

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

We should keep this comment.
What do think of:

# reverse_bfs_orders will contain the reverse breadth first (BFS) traversal order for each tree in the forest concatenated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I simply moved it into the comment of the field of the struct. I feel that the definition of what reverse_bfs_orders will be should go there and here we should comment on why what we do achieve this

Copy link
Contributor Author

@blegat blegat Jan 19, 2026

Choose a reason for hiding this comment

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

I added a new comment clarifying the confusion with the root of the Forest union-find datastructure that we thought we be useful during our discussion on the phone

# The `rank` of the `k`th tree encoded in `forest` does not correspond
# to the depth of the tree rooted as the root encoded in `forest` because
# `forest.parents[u] = v` only needs a path to exists from `u` to `v` but
# there may not be an edge `(u, v)`.
# We also want a root `r` that minimizes the depth of the tree rooted at
# `r`. To achieve this, we start from each leaf and remove the corresponding
# edges. We then look at all leaves of the corresponding graphs and repeat
# the process until there is only one vertex left. This vertex will then be
# a depth-minimizing root.
for k in 1:nt
# Initialize the queue to store the leaves
queue_start = 1
Expand Down
Loading