@@ -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,16 @@ 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! (
34+ first_visit_to_tree,
35+ forbidden_colors,
36+ v,
37+ w,
38+ x,
39+ g,
40+ two_colored_forest,
41+ color,
42+ )
3443 end
3544 end
3645 end
@@ -41,7 +50,7 @@ function color_graph(g::Graphs.AbstractGraph, ::AcyclicColoring)
4150
4251 for w in outneighbors (g, v)
4352 if color[w] != 0
44- grow_star! (two_colored_forest,first_neighbor,v, w, g, color)
53+ grow_star! (two_colored_forest, first_neighbor, v, w, g, color)
4554 end
4655 end
4756
@@ -50,7 +59,7 @@ function color_graph(g::Graphs.AbstractGraph, ::AcyclicColoring)
5059 for x in outneighbors (g, w)
5160 if color[x] != 0 && x != v
5261 if color[x] == color[v]
53- merge_trees! (two_colored_forest,v,w,x, g)
62+ merge_trees! (two_colored_forest, v, w, x, g)
5463 end
5564 end
5665 end
@@ -76,19 +85,21 @@ which is adjacent to vertices w and x in graph g. Disjoint set is used to store
7685the induced 2-colored subgraphs/trees where the id of set is an integer
7786representing an edge of graph 'g'
7887"""
79- function prevent_cycle! (first_visit_to_tree:: AbstractVector{<:Tuple{Integer,Integer}} ,
80- forbidden_colors:: AbstractVector{<:Integer} ,
81- v:: Integer ,
82- w:: Integer ,
83- x:: Integer ,
84- g:: Graphs.AbstractGraph ,
85- two_colored_forest:: DisjointSets{<:Integer} ,
86- color:: AbstractVector{<:Integer} )
88+ function prevent_cycle! (
89+ first_visit_to_tree:: AbstractVector{<:Tuple{Integer,Integer}} ,
90+ forbidden_colors:: AbstractVector{<:Integer} ,
91+ v:: Integer ,
92+ w:: Integer ,
93+ x:: Integer ,
94+ g:: Graphs.AbstractGraph ,
95+ two_colored_forest:: DisjointSets{<:Integer} ,
96+ color:: AbstractVector{<:Integer} ,
97+ )
8798 e = find (w, x, g, two_colored_forest)
8899 p, q = first_visit_to_tree[e]
89100
90101 if p != v
91- first_visit_to_tree[e] = (v,w)
102+ first_visit_to_tree[e] = (v, w)
92103 elseif q != w
93104 forbidden_colors[color[x]] = v
94105 end
@@ -108,20 +119,22 @@ previously uncolored vertex v, by comparing it with the adjacent vertex w.
108119Disjoint set is used to store stars in sets, which are identified through key
109120edges present in g.
110121"""
111- function grow_star! (two_colored_forest:: DisjointSets{<:Integer} ,
112- first_neighbor:: AbstractVector{<: Tuple{Integer,Integer}} ,
113- v:: Integer ,
114- w:: Integer ,
115- g:: Graphs.AbstractGraph ,
116- color:: AbstractVector{<:Integer} )
117- insert_new_tree! (two_colored_forest,v,w,g)
122+ function grow_star! (
123+ two_colored_forest:: DisjointSets{<:Integer} ,
124+ first_neighbor:: AbstractVector{<:Tuple{Integer,Integer}} ,
125+ v:: Integer ,
126+ w:: Integer ,
127+ g:: Graphs.AbstractGraph ,
128+ color:: AbstractVector{<:Integer} ,
129+ )
130+ insert_new_tree! (two_colored_forest, v, w, g)
118131 p, q = first_neighbor[color[w]]
119132
120133 if p != v
121- first_neighbor[color[w]] = (v,w)
134+ first_neighbor[color[w]] = (v, w)
122135 else
123- e1 = find (v,w,g, two_colored_forest)
124- e2 = find (p,q,g, two_colored_forest)
136+ e1 = find (v, w, g, two_colored_forest)
137+ e2 = find (p, q, g, two_colored_forest)
125138 union! (two_colored_forest, e1, e2)
126139 end
127140end
@@ -137,13 +150,15 @@ end
137150Subroutine to merge trees present in the disjoint set which have a
138151common edge.
139152"""
140- function merge_trees! (two_colored_forest:: DisjointSets{<:Integer} ,
141- v:: Integer ,
142- w:: Integer ,
143- x:: Integer ,
144- g:: Graphs.AbstractGraph )
145- e1 = find (v,w,g,two_colored_forest)
146- e2 = find (w,x,g,two_colored_forest)
153+ function merge_trees! (
154+ two_colored_forest:: DisjointSets{<:Integer} ,
155+ v:: Integer ,
156+ w:: Integer ,
157+ x:: Integer ,
158+ g:: Graphs.AbstractGraph ,
159+ )
160+ e1 = find (v, w, g, two_colored_forest)
161+ e2 = find (w, x, g, two_colored_forest)
147162 if e1 != e2
148163 union! (two_colored_forest, e1, e2)
149164 end
@@ -159,12 +174,14 @@ end
159174creates a new singleton set in the disjoint set 'two_colored_forest' consisting
160175of the edge connecting v and w in the graph g
161176"""
162- function insert_new_tree! (two_colored_forest:: DisjointSets{<:Integer} ,
163- v:: Integer ,
164- w:: Integer ,
165- g:: Graphs.AbstractGraph )
166- edge_index = find_edge_index (v,w,g)
167- push! (two_colored_forest,edge_index)
177+ function insert_new_tree! (
178+ two_colored_forest:: DisjointSets{<:Integer} ,
179+ v:: Integer ,
180+ w:: Integer ,
181+ g:: Graphs.AbstractGraph ,
182+ )
183+ edge_index = find_edge_index (v, w, g)
184+ push! (two_colored_forest, edge_index)
168185end
169186
170187
@@ -187,10 +204,12 @@ end
187204Returns the root of the disjoint set to which the edge connecting vertices w and x
188205in the graph g belongs to
189206"""
190- function find (w:: Integer ,
191- x:: Integer ,
192- g:: Graphs.AbstractGraph ,
193- two_colored_forest:: DisjointSets{<:Integer} )
207+ function find (
208+ w:: Integer ,
209+ x:: Integer ,
210+ g:: Graphs.AbstractGraph ,
211+ two_colored_forest:: DisjointSets{<:Integer} ,
212+ )
194213 edge_index = find_edge_index (w, x, g)
195214 return find_root! (two_colored_forest, edge_index)
196215end
0 commit comments