@@ -13,8 +13,8 @@ function color_graph(g::Graphs.AbstractGraph, ::AcyclicColoring)
1313 color = zeros (Int, nv (g))
1414 two_colored_forest = DisjointSets {Int} (())
1515
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))
1818
1919 forbidden_colors = zeros (Int, nv (g))
2020
@@ -30,7 +30,8 @@ function color_graph(g::Graphs.AbstractGraph, ::AcyclicColoring)
3030 for x in outneighbors (g, w)
3131 if color[x] != 0
3232 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)
3435 end
3536 end
3637 end
@@ -41,7 +42,7 @@ function color_graph(g::Graphs.AbstractGraph, ::AcyclicColoring)
4142
4243 for w in outneighbors (g, v)
4344 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)
4546 end
4647 end
4748
@@ -50,7 +51,7 @@ function color_graph(g::Graphs.AbstractGraph, ::AcyclicColoring)
5051 for x in outneighbors (g, w)
5152 if color[x] != 0 && x != v
5253 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)
5455 end
5556 end
5657 end
@@ -60,7 +61,6 @@ function color_graph(g::Graphs.AbstractGraph, ::AcyclicColoring)
6061 return color
6162end
6263
63-
6464"""
6565 prevent_cycle!(first_visit_to_tree::AbstractVector{<:Tuple{Integer,Integer}},
6666 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
7676the induced 2-colored subgraphs/trees where the id of set is an integer
7777representing an edge of graph 'g'
7878"""
79- function prevent_cycle! (first_visit_to_tree:: AbstractVector{<:Tuple{Integer,Integer}} ,
79+ function prevent_cycle! (first_visit_to_tree:: AbstractVector{<:Tuple{Integer, Integer}} ,
8080 forbidden_colors:: AbstractVector{<:Integer} ,
8181 v:: Integer ,
8282 w:: Integer ,
@@ -88,13 +88,12 @@ function prevent_cycle!(first_visit_to_tree::AbstractVector{<:Tuple{Integer,Inte
8888 p, q = first_visit_to_tree[e]
8989
9090 if p != v
91- first_visit_to_tree[e] = (v,w)
91+ first_visit_to_tree[e] = (v, w)
9292 elseif q != w
9393 forbidden_colors[color[x]] = v
9494 end
9595end
9696
97-
9897"""
9998 grow_star!(two_colored_forest::DisjointSets{<:Integer},
10099 first_neighbor::AbstractVector{<: Tuple{Integer,Integer}},
@@ -109,24 +108,23 @@ Disjoint set is used to store stars in sets, which are identified through key
109108edges present in g.
110109"""
111110function grow_star! (two_colored_forest:: DisjointSets{<:Integer} ,
112- first_neighbor:: AbstractVector{<: Tuple{Integer,Integer}} ,
111+ first_neighbor:: AbstractVector{<:Tuple{Integer, Integer}} ,
113112 v:: Integer ,
114113 w:: Integer ,
115114 g:: Graphs.AbstractGraph ,
116115 color:: AbstractVector{<:Integer} )
117- insert_new_tree! (two_colored_forest,v,w, g)
116+ insert_new_tree! (two_colored_forest, v, w, g)
118117 p, q = first_neighbor[color[w]]
119118
120119 if p != v
121- first_neighbor[color[w]] = (v,w)
120+ first_neighbor[color[w]] = (v, w)
122121 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)
125124 union! (two_colored_forest, e1, e2)
126125 end
127126end
128127
129-
130128"""
131129 merge_trees!(two_colored_forest::DisjointSets{<:Integer},
132130 v::Integer,
@@ -142,14 +140,13 @@ function merge_trees!(two_colored_forest::DisjointSets{<:Integer},
142140 w:: Integer ,
143141 x:: Integer ,
144142 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)
147145 if e1 != e2
148146 union! (two_colored_forest, e1, e2)
149147 end
150148end
151149
152-
153150"""
154151 insert_new_tree!(two_colored_forest::DisjointSets{<:Integer},
155152 v::Integer,
@@ -163,11 +160,10 @@ function insert_new_tree!(two_colored_forest::DisjointSets{<:Integer},
163160 v:: Integer ,
164161 w:: Integer ,
165162 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)
168165end
169166
170-
171167"""
172168 min_index(forbidden_colors::AbstractVector{<:Integer}, v::Integer)
173169
@@ -177,7 +173,6 @@ function min_index(forbidden_colors::AbstractVector{<:Integer}, v::Integer)
177173 return findfirst (! isequal (v), forbidden_colors)
178174end
179175
180-
181176"""
182177 find(w::Integer,
183178 x::Integer,
@@ -195,7 +190,6 @@ function find(w::Integer,
195190 return find_root! (two_colored_forest, edge_index)
196191end
197192
198-
199193"""
200194 find_edge(g::Graphs.AbstractGraph, v::Integer, w::Integer)
201195
@@ -205,7 +199,6 @@ v and w in the graph g
205199function find_edge_index (v:: Integer , w:: Integer , g:: Graphs.AbstractGraph )
206200 pos = 1
207201 for i in edges (g)
208-
209202 if (src (i) == v && dst (i) == w) || (src (i) == w && dst (i) == v)
210203 return pos
211204 end
0 commit comments