@@ -13,8 +13,8 @@ function color_graph(g::Graphs.AbstractGraph, ::AcyclicColoring)
13
13
color = zeros (Int, nv (g))
14
14
two_colored_forest = DisjointSets {Int} (())
15
15
16
- first_visit_to_tree = fill ((0 ,0 ), ne (g))
17
- first_neighbor = fill ((0 ,0 ), ne (g))
16
+ first_visit_to_tree = fill ((0 , 0 ), ne (g))
17
+ first_neighbor = fill ((0 , 0 ), ne (g))
18
18
19
19
forbidden_colors = zeros (Int, nv (g))
20
20
@@ -30,7 +30,8 @@ function color_graph(g::Graphs.AbstractGraph, ::AcyclicColoring)
30
30
for x in outneighbors (g, w)
31
31
if color[x] != 0
32
32
if forbidden_colors[color[x]] != v
33
- prevent_cycle! (first_visit_to_tree,forbidden_colors,v, w, x, g, two_colored_forest,color)
33
+ prevent_cycle! (first_visit_to_tree, forbidden_colors, v, w, x,
34
+ g, two_colored_forest, color)
34
35
end
35
36
end
36
37
end
@@ -41,7 +42,7 @@ function color_graph(g::Graphs.AbstractGraph, ::AcyclicColoring)
41
42
42
43
for w in outneighbors (g, v)
43
44
if color[w] != 0
44
- grow_star! (two_colored_forest,first_neighbor,v, w, g, color)
45
+ grow_star! (two_colored_forest, first_neighbor, v, w, g, color)
45
46
end
46
47
end
47
48
@@ -50,7 +51,7 @@ function color_graph(g::Graphs.AbstractGraph, ::AcyclicColoring)
50
51
for x in outneighbors (g, w)
51
52
if color[x] != 0 && x != v
52
53
if color[x] == color[v]
53
- merge_trees! (two_colored_forest,v,w,x, g)
54
+ merge_trees! (two_colored_forest, v, w, x, g)
54
55
end
55
56
end
56
57
end
@@ -60,7 +61,6 @@ function color_graph(g::Graphs.AbstractGraph, ::AcyclicColoring)
60
61
return color
61
62
end
62
63
63
-
64
64
"""
65
65
prevent_cycle!(first_visit_to_tree::AbstractVector{<:Tuple{Integer,Integer}},
66
66
forbidden_colors::AbstractVector{<:Integer},
@@ -76,7 +76,7 @@ which is adjacent to vertices w and x in graph g. Disjoint set is used to store
76
76
the induced 2-colored subgraphs/trees where the id of set is an integer
77
77
representing an edge of graph 'g'
78
78
"""
79
- function prevent_cycle! (first_visit_to_tree:: AbstractVector{<:Tuple{Integer,Integer}} ,
79
+ function prevent_cycle! (first_visit_to_tree:: AbstractVector{<:Tuple{Integer, Integer}} ,
80
80
forbidden_colors:: AbstractVector{<:Integer} ,
81
81
v:: Integer ,
82
82
w:: Integer ,
@@ -88,13 +88,12 @@ function prevent_cycle!(first_visit_to_tree::AbstractVector{<:Tuple{Integer,Inte
88
88
p, q = first_visit_to_tree[e]
89
89
90
90
if p != v
91
- first_visit_to_tree[e] = (v,w)
91
+ first_visit_to_tree[e] = (v, w)
92
92
elseif q != w
93
93
forbidden_colors[color[x]] = v
94
94
end
95
95
end
96
96
97
-
98
97
"""
99
98
grow_star!(two_colored_forest::DisjointSets{<:Integer},
100
99
first_neighbor::AbstractVector{<: Tuple{Integer,Integer}},
@@ -109,24 +108,23 @@ Disjoint set is used to store stars in sets, which are identified through key
109
108
edges present in g.
110
109
"""
111
110
function grow_star! (two_colored_forest:: DisjointSets{<:Integer} ,
112
- first_neighbor:: AbstractVector{<: Tuple{Integer,Integer}} ,
111
+ first_neighbor:: AbstractVector{<:Tuple{Integer, Integer}} ,
113
112
v:: Integer ,
114
113
w:: Integer ,
115
114
g:: Graphs.AbstractGraph ,
116
115
color:: AbstractVector{<:Integer} )
117
- insert_new_tree! (two_colored_forest,v,w, g)
116
+ insert_new_tree! (two_colored_forest, v, w, g)
118
117
p, q = first_neighbor[color[w]]
119
118
120
119
if p != v
121
- first_neighbor[color[w]] = (v,w)
120
+ first_neighbor[color[w]] = (v, w)
122
121
else
123
- e1 = find (v,w,g, two_colored_forest)
124
- e2 = find (p,q,g, two_colored_forest)
122
+ e1 = find (v, w, g, two_colored_forest)
123
+ e2 = find (p, q, g, two_colored_forest)
125
124
union! (two_colored_forest, e1, e2)
126
125
end
127
126
end
128
127
129
-
130
128
"""
131
129
merge_trees!(two_colored_forest::DisjointSets{<:Integer},
132
130
v::Integer,
@@ -142,14 +140,13 @@ function merge_trees!(two_colored_forest::DisjointSets{<:Integer},
142
140
w:: Integer ,
143
141
x:: Integer ,
144
142
g:: Graphs.AbstractGraph )
145
- e1 = find (v,w,g, two_colored_forest)
146
- e2 = find (w,x,g, two_colored_forest)
143
+ e1 = find (v, w, g, two_colored_forest)
144
+ e2 = find (w, x, g, two_colored_forest)
147
145
if e1 != e2
148
146
union! (two_colored_forest, e1, e2)
149
147
end
150
148
end
151
149
152
-
153
150
"""
154
151
insert_new_tree!(two_colored_forest::DisjointSets{<:Integer},
155
152
v::Integer,
@@ -163,11 +160,10 @@ function insert_new_tree!(two_colored_forest::DisjointSets{<:Integer},
163
160
v:: Integer ,
164
161
w:: Integer ,
165
162
g:: Graphs.AbstractGraph )
166
- edge_index = find_edge_index (v,w, g)
167
- push! (two_colored_forest,edge_index)
163
+ edge_index = find_edge_index (v, w, g)
164
+ push! (two_colored_forest, edge_index)
168
165
end
169
166
170
-
171
167
"""
172
168
min_index(forbidden_colors::AbstractVector{<:Integer}, v::Integer)
173
169
@@ -177,7 +173,6 @@ function min_index(forbidden_colors::AbstractVector{<:Integer}, v::Integer)
177
173
return findfirst (! isequal (v), forbidden_colors)
178
174
end
179
175
180
-
181
176
"""
182
177
find(w::Integer,
183
178
x::Integer,
@@ -195,7 +190,6 @@ function find(w::Integer,
195
190
return find_root! (two_colored_forest, edge_index)
196
191
end
197
192
198
-
199
193
"""
200
194
find_edge(g::Graphs.AbstractGraph, v::Integer, w::Integer)
201
195
@@ -205,7 +199,6 @@ v and w in the graph g
205
199
function find_edge_index (v:: Integer , w:: Integer , g:: Graphs.AbstractGraph )
206
200
pos = 1
207
201
for i in edges (g)
208
-
209
202
if (src (i) == v && dst (i) == w) || (src (i) == w && dst (i) == v)
210
203
return pos
211
204
end
0 commit comments