@@ -18,13 +18,13 @@ Color graph `g` according to an order specified by `seq` using a greedy heuristi
1818"""
1919function perm_greedy_color (g:: AbstractGraph , seq:: Vector{T} ) where {T <: Integer }
2020 nvg:: T = nv (g)
21- cols = Vector {T} (undef, nvg)
21+ cols = Vector {T} (undef, nvg)
2222 seen = zeros (Bool, nvg + 1 )
2323
24+ has_self_loops (g) && throw (ArgumentError (" graph must not have self loops" ))
25+
2426 for v in seq
25- seen[v] = true
2627 colors_used = zeros (Bool, nvg)
27-
2828 for w in neighbors (g, v)
2929 if seen[w]
3030 colors_used[cols[w]] = true
@@ -37,6 +37,8 @@ function perm_greedy_color(g::AbstractGraph, seq::Vector{T}) where {T <: Integer
3737 break ;
3838 end
3939 end
40+
41+ seen[v] = true
4042 end
4143
4244 return Coloring {T} (maximum (cols), cols)
4749
4850Color graph `g` iteratively in the descending order of the degree of the vertices.
4951"""
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 ))
5254 return perm_greedy_color (g, seq)
5355end
5456
5961Color the graph `g` iteratively in a random order using a greedy heuristic
6062and choose the best coloring out of `reps` such random colorings.
6163"""
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 }
6365
6466 seq = shuffle (vertices (g))
6567 best = perm_greedy_color (g, seq)
7678
7779Color graph `g` based on [Greedy Coloring Heuristics](https://en.wikipedia.org/wiki/Greedy_coloring)
7880
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
8082lowest color index available iteratively in that order.
8183
8284If `sort_degree` is true then the permutation is chosen in reverse sorted order of the degree of the vertices.
0 commit comments