Skip to content

Commit 3ae469e

Browse files
authored
Merge branch 'main' into similar
2 parents 1f08edb + 921c7a0 commit 3ae469e

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

src/coloring.jl

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,16 +417,31 @@ Encode a set of 2-colored trees resulting from the [`acyclic_coloring`](@ref) al
417417
$TYPEDFIELDS
418418
"""
419419
struct TreeSet{T}
420+
"""
421+
For a tree index `1 <= k <= nt`, the list
422+
`list = reverse_bfs_order[tree_edge_indices[k]:(tree_edge_indices[k+1]-1)]` is a list of edges
423+
`list[i] = (leaf, inner)` of the `k`th tree such that `leaf` is a leaf of the tree containing
424+
the edges `list[i:end]`.
425+
From an other point of view, `reverse(list)` contains the edges in the order of a breadth first
426+
(BFS) traversal order of the `k`th tree starting from a depth-minimizing root.
427+
"""
420428
reverse_bfs_orders::Vector{Tuple{T,T}}
429+
"For a tree index `1 <= k <= nt`, `is_star[k]` indicates whether the `k`th three is a star."
421430
is_star::Vector{Bool}
431+
"""
432+
`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.
433+
One can think of it as a kind of fused vector of offsets (similar to the `colptr` field of `SparseMatrixCSC`) of all trees together.
434+
"""
422435
tree_edge_indices::Vector{T}
436+
"numbers of 2-colored trees for which trees sharing the same 2 colors have disjoint edges"
423437
nt::T
424438
end
425439

426440
function TreeSet(
427441
g::AdjacencyGraph{T},
428442
forest::Forest{T},
429443
buffer::AbstractVector{T},
444+
# The value of `reverse_bfs_orders` is ignored, we just provide the storage for it (or reuse memory allocated during acyclic coloring)
430445
reverse_bfs_orders::Vector{Tuple{T,T}},
431446
ne::Integer,
432447
) where {T}
@@ -561,7 +576,15 @@ function TreeSet(
561576
# Number of edges treated
562577
num_edges_treated = zero(T)
563578

564-
# reverse_bfs_orders contains the reverse breadth first (BFS) traversal order for each tree in the forest
579+
# The `rank` of the `k`th tree encoded in `forest` does not correspond
580+
# to the depth of the tree rooted as the root encoded in `forest` because
581+
# `forest.parents[u] = v` only needs a path to exists from `u` to `v` but
582+
# there may not be an edge `(u, v)`.
583+
# We also want a root `r` that minimizes the depth of the tree rooted at
584+
# `r`. To achieve this, we start from each leaf and remove the corresponding
585+
# edges. We then look at all leaves of the corresponding graphs and repeat
586+
# the process until there is only one vertex left. This vertex will then be
587+
# a depth-minimizing root.
565588
for k in 1:nt
566589
# Initialize the queue to store the leaves
567590
queue_start = 1

0 commit comments

Comments
 (0)