You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/coloring.jl
+22-30Lines changed: 22 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -87,7 +87,9 @@ function star_coloring(
87
87
first_neighbor =fill((zero(T), zero(T), zero(T)), nv) # at first no neighbors have been encountered
88
88
treated =zeros(T, nv)
89
89
star =Vector{T}(undef, ne)
90
-
hub = T[] # one hub for each star, including the trivial ones
90
+
# duplicate the hub for non-trivial star -- store both vertices for trivial stars
91
+
# we always use the first component of the tuple as the hub for decompression
92
+
hub = Tuple{T,T}[]
91
93
vertices_in_order =vertices(g, order)
92
94
93
95
for v in vertices_in_order
@@ -108,7 +110,8 @@ function star_coloring(
108
110
for (x, index_wx) inneighbors_with_edge_indices(g, w)
109
111
!has_diagonal(g) || (w == x &&continue)
110
112
(x == v ||iszero(color[x])) &&continue
111
-
if x == hub[star[index_wx]] # potential Case 2 (which is always false for trivial stars with two vertices, since the associated hub is negative)
113
+
(h, h2) = hub[star[index_wx]]
114
+
if (h == h2) && (x == h) # potential Case 2 (which is always false for trivial stars with undefined hub)
112
115
forbidden_colors[color[x]] = v
113
116
end
114
117
end
@@ -153,7 +156,7 @@ end
153
156
function_update_stars!(
154
157
# modified
155
158
star::AbstractVector{<:Integer},
156
-
hub::AbstractVector{<:Integer},
159
+
hub::AbstractVector{<:Tuple},
157
160
# not modified
158
161
g::AdjacencyGraph,
159
162
v::Integer,
@@ -168,7 +171,7 @@ function _update_stars!(
168
171
!has_diagonal(g) || (w == x &&continue)
169
172
if x != v && color[x] == color[v] # vw, wx ∈ E
170
173
star_wx = star[index_wx]
171
-
hub[star_wx] =w# this may already be true
174
+
hub[star_wx] =(w, w)# this may already be true
172
175
star[index_vw] = star_wx
173
176
x_exists =true
174
177
break
@@ -178,10 +181,10 @@ function _update_stars!(
178
181
(p, q, index_pq) = first_neighbor[color[w]]
179
182
if p == v && q != w # vw, vq ∈ E and color[w] = color[q]
180
183
star_vq = star[index_pq]
181
-
hub[star_vq] =v# this may already be true
184
+
hub[star_vq] =(v, v)# this may already be true
182
185
star[index_vw] = star_vq
183
186
else# vw forms a new star
184
-
push!(hub, -max(v, w)) # star is trivial (composed only of two vertices) so we set the hub to a negative value, but it allows us to choose one of the two vertices
187
+
push!(hub, (v, w)) # star is trivial (composed only of two vertices)
185
188
star[index_vw] =length(hub)
186
189
end
187
190
end
@@ -201,8 +204,8 @@ $TYPEDFIELDS
201
204
struct StarSet{T}
202
205
"a mapping from edges (pair of vertices) to their star index"
203
206
star::Vector{T}
204
-
"a mapping from star indices to their hub (undefined hubs for single-edge stars are the negative value of one of the vertices, picked arbitrarily)"
205
-
hub::Vector{T}
207
+
"a mapping from star indices to their hub"
208
+
hub::Vector{Tuple{T,T}}
206
209
end
207
210
208
211
"""
@@ -546,9 +549,8 @@ function postprocess!(
546
549
nb_trivial_stars =0
547
550
548
551
# Iterate through all non-trivial stars
549
-
for s ineachindex(hub)
550
-
h = hub[s]
551
-
if h >0
552
+
for (h, h2) in hub
553
+
if h == h2
552
554
color_used[color[h]] =true
553
555
else
554
556
nb_trivial_stars +=1
@@ -557,25 +559,15 @@ function postprocess!(
557
559
558
560
# Process the trivial stars (if any)
559
561
if nb_trivial_stars >0
560
-
rvS =rowvals(S)
561
-
for j inaxes(S, 2)
562
-
for k innzrange(S, j)
563
-
i = rvS[k]
564
-
if i > j
565
-
index_ij = edge_to_index[k]
566
-
s = star[index_ij]
567
-
h = hub[s]
568
-
if h <0
569
-
h =abs(h)
570
-
spoke = h == j ? i : j
571
-
if color_used[color[spoke]]
572
-
# Switch the hub and the spoke to possibly avoid adding one more used color
573
-
hub[s] = spoke
574
-
else
575
-
# Keep the current hub
576
-
color_used[color[h]] =true
577
-
end
578
-
end
562
+
for s ineachindex(hub)
563
+
(h, h2) = hub[s]
564
+
if h != h2
565
+
if color_used[color[h2]]
566
+
# Switch the hub and the spoke to possibly avoid adding one more used color
0 commit comments