@@ -38,7 +38,7 @@ mutable struct StopAfterIteration <: StoppingCriterion
38
38
reason:: String
39
39
StopAfterIteration (mIter:: Int ) = new (mIter, " " )
40
40
end
41
- function (c:: StopAfterIteration )(p :: P , o :: O , i:: Int ) where {P<: Problem ,O<: Options }
41
+ function (c:: StopAfterIteration )(:: P , :: O , i:: Int ) where {P<: Problem ,O<: Options }
42
42
if i > c. maxIter
43
43
c. reason = " The algorithm reached its maximal number of iterations ($(c. maxIter) ).\n "
44
44
return true
@@ -124,6 +124,33 @@ function (c::StopWhenAll)(p::P, o::O, i::Int) where {P<:Problem,O<:Options}
124
124
end
125
125
get_stopping_criteria (c:: StopWhenAll ) = c. criteria
126
126
127
+ """
128
+ &(s1,s2)
129
+ s1 & s2
130
+
131
+ Combine two [`StoppingCriterion`](@ref) within an [`StopWhenAll`](@ref).
132
+ If either `s1` (or `s2`) is already an [`StopWhenAll`](@ref), then `s2` (or `s1`) is
133
+ appended to the list of [`StoppingCriterion`](@ref) within `s1` (or `s2`).
134
+
135
+ # Example
136
+ a = StopAfterIteration(200) & StopWhenChangeLess(1e-6)
137
+ b = a & StopWhenGradientNormLess(1e-6)
138
+
139
+ Is the same as
140
+
141
+ a = StopWhenAll(StopAfterIteration(200), StopWhenChangeLess(1e-6))
142
+ b = StopWhenAll(StopAfterIteration(200), StopWhenChangeLess(1e-6), StopWhenGradientNormLess(1e-6))
143
+ """
144
+ function Base.:& (s1:: S , s2:: T ) where {S<: StoppingCriterion ,T<: StoppingCriterion }
145
+ return StopWhenAll (s1, s2)
146
+ end
147
+ function Base.:& (s1:: S , s2:: StopWhenAll ) where {S<: StoppingCriterion }
148
+ return StopWhenAll (s1, s2. criteria... )
149
+ end
150
+ function Base.:& (s1:: StopWhenAll , s2:: T ) where {T<: StoppingCriterion }
151
+ return StopWhenAll (s1. criteria... , s2)
152
+ end
153
+
127
154
@doc raw """
128
155
StopWhenAny <: StoppingCriterion
129
156
@@ -149,6 +176,34 @@ function (c::StopWhenAny)(p::P, o::O, i::Int) where {P<:Problem,O<:Options}
149
176
return false
150
177
end
151
178
get_stopping_criteria (c:: StopWhenAny ) = c. criteria
179
+
180
+ """
181
+ |(s1,s2)
182
+ s1 | s2
183
+
184
+ Combine two [`StoppingCriterion`](@ref) within an [`StopWhenAny`](@ref).
185
+ If either `s1` (or `s2`) is already an [`StopWhenAny`](@ref), then `s2` (or `s1`) is
186
+ appended to the list of [`StoppingCriterion`](@ref) within `s1` (or `s2`)
187
+
188
+ # Example
189
+ a = StopAfterIteration(200) | StopWhenChangeLess(1e-6)
190
+ b = a | StopWhenGradientNormLess(1e-6)
191
+
192
+ Is the same as
193
+
194
+ a = StopWhenAny(StopAfterIteration(200), StopWhenChangeLess(1e-6))
195
+ b = StopWhenAny(StopAfterIteration(200), StopWhenChangeLess(1e-6), StopWhenGradientNormLess(1e-6))
196
+ """
197
+ function Base.:| (s1:: S , s2:: T ) where {S<: StoppingCriterion ,T<: StoppingCriterion }
198
+ return StopWhenAny (s1, s2)
199
+ end
200
+ function Base.:| (s1:: S , s2:: StopWhenAny ) where {S<: StoppingCriterion }
201
+ return StopWhenAny (s1, s2. criteria... )
202
+ end
203
+ function Base.:| (s1:: StopWhenAny , s2:: T ) where {T<: StoppingCriterion }
204
+ return StopWhenAny (s1. criteria... , s2)
205
+ end
206
+
152
207
"""
153
208
StopWhenCostLess <: StoppingCriterion
154
209
0 commit comments