Skip to content

Commit 1d91e4e

Browse files
committed
precision & stop
1 parent b152d91 commit 1d91e4e

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

src/abstract_algorithm.jl

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@ mutable struct RecordedAlgorithm{Q,A} <: AbstractAlgorithm{Q,A}
7070
end
7171
end
7272

73-
abstract type Stoppability end
74-
struct Stoppable <: Stoppability end
75-
struct NotStoppable <: Stoppability end
76-
Stoppability(::AbstractAlgorithm) = NotStoppable()
77-
7873

7974
"""
8075
Initialise
@@ -177,28 +172,32 @@ function progress(ra::RecordedAlgorithm{Q,A}) where {Q,A}
177172
ceil(Int64, output)
178173
end
179174

175+
abstract type Stoppability end
176+
struct Stoppable <: Stoppability end
177+
struct NotStoppable <: Stoppability end
178+
Stoppability(::AbstractAlgorithm) = NotStoppable()
179+
"""
180+
Return true if the stopping condition has been reached
181+
"""
182+
stopnow(ra::RecordedAlgorithm) = stopnow(Stoppability(ra.algorithm), ra)
183+
stopnow(::Stoppable, ra::RecordedAlgorithm) = stopnow(ra.algorithm) || stopnow(NotStoppable(), ra)
184+
function stopnow(::NotStoppable, ra::RecordedAlgorithm)
185+
(ra.stopat[1] 0 && ra.iteration ra.stopat[1]) ||
186+
(ra.stopat[2] 0 && ra.epoch ra.stopat[2]) ||
187+
(ra.stopat[3] 0 && ra.time ra.stopat[3]) ||
188+
(ra.precision_active && ra.iteration > 1 && ra.precision ra.stopat[4])
189+
end
190+
180191
"""
181192
Function used in `record` as an argument of `ProgressMeter.next!`
182193
"""
183194
function generate_showvalues(ra::RecordedAlgorithm)
184-
() -> [(:iterations, ra.iteration), (:epochs, ra.epoch), (:answers, string(ra.answer_count)[6:end-1])]
195+
() -> append!([(:iterations, ra.iteration), (:epochs, ra.epoch), (:answers, string(ra.answer_count)[6:end-1])], ra.precision_active ? [(:precision, ra.precision)] : [])
185196
end
186197

187198
"""
188199
Compile the results to be outputed
189200
"""
190201
function report(ra::RecordedAlgorithm)
191202
(queries=ra.queries, answers=ra.answers, iterations=ra.iterations, epochs=ra.epochs, timestamps=ra.timestamps, answers_origin=ra.answers_origin, answer_count=ra.answer_count, precision=ra.precisions)
192-
end
193-
194-
"""
195-
Return true if the stopping condition has been reached
196-
"""
197-
stopnow(ra::RecordedAlgorithm) = stopnow(Stoppability(ra.algorithm), ra)
198-
stopnow(::Stoppable, ra::RecordedAlgorithm)= stopnow(ra.algorithm) || stopnow(NotStoppable(), ra)
199-
function stopnow(::NotStoppable, ra::RecordedAlgorithm)
200-
(ra.stopat[1] 0 && ra.iteration ra.stopat[1]) ||
201-
(ra.stopat[2] 0 && ra.epoch ra.stopat[2]) ||
202-
(ra.stopat[3] 0 && ra.time ra.stopat[3]) ||
203-
(ra.precision_active && length(ra.queries) > 1 && ra.precision ra.stopat[4])
204203
end

src/start.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ function start_central(network::Network{Q,A}, recorded_algorithm::RecordedAlgori
110110
send_query(network, q)
111111

112112
if !synchronous
113-
while !stopnow(recorded_algorithm) #&& isopen(network)
113+
while !stopnow(recorded_algorithm)
114114
a, worker = get_answer(network)
115115
q = recorded_algorithm(a, worker, problem)
116116
send_query(network, q, worker)
117117
end
118118
else
119119
npid = length(network.pids)
120-
while !stopnow(recorded_algorithm) #&& isopen(network)
120+
while !stopnow(recorded_algorithm)
121121
as, workers = Vector{A}(undef, npid), Vector{Int64}(undef, npid)
122122
for i in 1:npid
123123
as[i], workers[i] = get_answer(network)

0 commit comments

Comments
 (0)