1
1
"""
2
- struct coloring {T}
2
+ struct Coloring {T}
3
3
4
- Store number of colors used and mapping from vertex to color
4
+ Store the number of colors used and mapping from vertex to color
5
5
"""
6
- struct coloring {T <: Integer } <: Any
6
+ struct Coloring {T <: Integer }
7
7
num_colors:: T
8
8
colors:: Vector{T}
9
9
end
10
10
11
- best_color (c1:: coloring , c2:: coloring ) = c1. num_colors < c2. num_colors ? c1 : c2
11
+ best_color (c1:: Coloring , c2:: Coloring ) = c1. num_colors < c2. num_colors ? c1 : c2
12
12
13
13
"""
14
14
perm_greedy_color(g, seq)
15
15
16
16
Color graph `g` according to an order specified by `seq` using a greedy heuristic.
17
- seq[i] = v imples that vertex v is the i<sup>th</sup> vertex to be colored.
17
+ ` seq[i] = v` implies that vertex v is the ``i^{th}`` vertex to be colored.
18
18
"""
19
- function perm_greedy_color (g:: AbstractGraph , seq:: Vector{T} ) where T <: Integer
19
+ function perm_greedy_color (g:: AbstractGraph , seq:: Vector{T} ) where { T <: Integer }
20
20
nvg:: T = nv (g)
21
21
cols = Vector {T} (undef, nvg)
22
22
seen = zeros (Bool, nvg + 1 )
@@ -39,28 +39,27 @@ function perm_greedy_color(g::AbstractGraph, seq::Vector{T}) where T <: Integer
39
39
end
40
40
end
41
41
42
- return coloring {T} (maximum (cols), cols)
42
+ return Coloring {T} (maximum (cols), cols)
43
43
end
44
44
45
45
"""
46
46
degree_greedy_color(g)
47
47
48
48
Color graph `g` iteratively in the descending order of the degree of the vertices.
49
49
"""
50
- function degree_greedy_color (g:: AbstractGraph{T} ) where T <: Integer
50
+ function degree_greedy_color (g:: AbstractGraph{T} ) where { T <: Integer }
51
51
seq = convert (Vector{T}, sortperm (degree (g), rev= true ))
52
52
return perm_greedy_color (g, seq)
53
53
end
54
54
55
55
56
56
"""
57
- random_greedy_color(g, reps=1 )
57
+ random_greedy_color(g, reps)
58
58
59
- Color graph `g` iteratively in a random order using a greedy heruistic
60
- and choose the best coloring out of `reps` such random coloring .
59
+ Color the graph `g` iteratively in a random order using a greedy heuristic
60
+ and choose the best coloring out of `reps` such random colorings .
61
61
"""
62
- function random_greedy_color (g:: AbstractGraph{T} ,
63
- reps:: Integer ) where T <: Integer
62
+ function random_greedy_color (g:: AbstractGraph{T} , reps:: Integer ) where {T <: Integer }
64
63
65
64
seq = shuffle (vertices (g))
66
65
best = perm_greedy_color (g, seq)
@@ -87,5 +86,4 @@ If `sort_degree` is false then `reps` colorings are obtained based on random per
87
86
colors is chosen.
88
87
"""
89
88
greedy_color (g:: AbstractGraph{U} ; sort_degree:: Bool = false , reps:: Integer = 1 ) where {U <: Integer } =
90
- sort_degree ? degree_greedy_color (g) : random_greedy_color (g, reps)
91
-
89
+ sort_degree ? degree_greedy_color (g) : random_greedy_color (g, reps)
0 commit comments