@@ -18,13 +18,13 @@ Color graph `g` according to an order specified by `seq` using a greedy heuristi
18
18
"""
19
19
function perm_greedy_color (g:: AbstractGraph , seq:: Vector{T} ) where {T <: Integer }
20
20
nvg:: T = nv (g)
21
- cols = Vector {T} (undef, nvg)
21
+ cols = Vector {T} (undef, nvg)
22
22
seen = zeros (Bool, nvg + 1 )
23
23
24
+ has_self_loops (g) && throw (ArgumentError (" graph must not have self loops" ))
25
+
24
26
for v in seq
25
- seen[v] = true
26
27
colors_used = zeros (Bool, nvg)
27
-
28
28
for w in neighbors (g, v)
29
29
if seen[w]
30
30
colors_used[cols[w]] = true
@@ -37,6 +37,8 @@ function perm_greedy_color(g::AbstractGraph, seq::Vector{T}) where {T <: Integer
37
37
break ;
38
38
end
39
39
end
40
+
41
+ seen[v] = true
40
42
end
41
43
42
44
return Coloring {T} (maximum (cols), cols)
47
49
48
50
Color graph `g` iteratively in the descending order of the degree of the vertices.
49
51
"""
50
- function degree_greedy_color (g:: AbstractGraph{T} ) where {T <: Integer }
51
- seq = convert (Vector{T}, sortperm (degree (g), rev= true ))
52
+ function degree_greedy_color (g:: AbstractGraph{T} ) where {T <: Integer }
53
+ seq = convert (Vector{T}, sortperm (degree (g), rev= true ))
52
54
return perm_greedy_color (g, seq)
53
55
end
54
56
59
61
Color the graph `g` iteratively in a random order using a greedy heuristic
60
62
and choose the best coloring out of `reps` such random colorings.
61
63
"""
62
- function random_greedy_color (g:: AbstractGraph{T} , reps:: Integer ) where {T <: Integer }
64
+ function random_greedy_color (g:: AbstractGraph{T} , reps:: Integer ) where {T <: Integer }
63
65
64
66
seq = shuffle (vertices (g))
65
67
best = perm_greedy_color (g, seq)
76
78
77
79
Color graph `g` based on [Greedy Coloring Heuristics](https://en.wikipedia.org/wiki/Greedy_coloring)
78
80
79
- The heuristics can be described as choosing a permutation of the vertices and assigning the
81
+ The heuristics can be described as choosing a permutation of the vertices and assigning the
80
82
lowest color index available iteratively in that order.
81
83
82
84
If `sort_degree` is true then the permutation is chosen in reverse sorted order of the degree of the vertices.
0 commit comments