@@ -12,7 +12,8 @@ function push_relabel end
1212 residual_graph: :: :Graphs . IsDirected, # the input graph
1313 source:: Integer , # the source vertex
1414 target:: Integer , # the target vertex
15- capacity_matrix:: AbstractMatrix{T} # edge flow capacities
15+ capacity_matrix:: AbstractMatrix{T} ; # edge flow capacities
16+ tolerance:: T = (T <: AbstractFloat ) ? sqrt (eps (T)) : zero (T)
1617 ) where {T}
1718
1819 n = Graphs. nv (residual_graph)
@@ -43,7 +44,7 @@ function push_relabel end
4344 while length (Q) > 0
4445 v = pop! (Q)
4546 active[v] = false
46- discharge! (residual_graph, v, capacity_matrix, flow_matrix, excess, height, active, count, Q)
47+ discharge! (residual_graph, v, capacity_matrix, flow_matrix, excess, height, active, count, Q; tolerance = tolerance )
4748 end
4849
4950 return sum ([flow_matrix[v, target] for v in Graphs. inneighbors (residual_graph, target)]), flow_matrix
@@ -180,20 +181,21 @@ function discharge! end
180181@traitfn function discharge! (
181182 residual_graph: :: :Graphs . IsDirected, # the input graph
182183 v:: Integer , # vertex to be discharged
183- capacity_matrix:: AbstractMatrix ,
184+ capacity_matrix:: AbstractMatrix{T} ,
184185 flow_matrix:: AbstractMatrix ,
185186 excess:: AbstractVector ,
186187 height:: AbstractVector{Int} ,
187188 active:: AbstractVector{Bool} ,
188189 count:: AbstractVector{Int} ,
189- Q:: AbstractVector # FIFO queue
190- )
190+ Q:: AbstractVector ; # FIFO queue
191+ tolerance = (T <: AbstractFloat ) ? sqrt (eps (T)) : zero (T)
192+ ) where {T}
191193 for to in Graphs. outneighbors (residual_graph, v)
192- excess[v] == 0 && break
194+ is_zero ( excess[v]; atol = tolerance) && break
193195 push_flow! (residual_graph, v, to, capacity_matrix, flow_matrix, excess, height, active, Q)
194196 end
195197
196- if excess[v] > 0
198+ if ! is_zero ( excess[v]; atol = tolerance)
197199 if count[height[v] + 1 ] == 1
198200 gap! (residual_graph, height[v], excess, height, active, count, Q)
199201 else
0 commit comments