@@ -54,30 +54,26 @@ function R2Solver(nlp::AbstractNLPModel{T, V}) where {T, V}
5454 return R2Solver {V} (x, gx, cx)
5555end
5656
57- @doc (@doc R2Solver) function R2 (
58- nlp:: AbstractNLPModel{T,V} ;
59- kwargs... ,
60- ) where {T, V}
57+ @doc (@doc R2Solver) function R2 (nlp:: AbstractNLPModel{T, V} ; kwargs... ) where {T, V}
6158 solver = R2Solver (nlp)
6259 return solve! (solver, nlp; kwargs... )
6360end
6461
6562function solve! (
66- solver:: R2Solver{V} ,
67- nlp:: AbstractNLPModel{T, V} ;
68- x0:: V = nlp. meta. x0,
69- atol = eps (T)^ (1 / 2 ),
70- rtol = eps (T)^ (1 / 2 ),
71- η1 = eps (T)^ (1 / 4 ),
72- η2 = T (0.95 ),
73- γ1 = T (1 / 2 ),
74- γ2 = 1 / γ1,
75- σmin = zero (T),
76- max_time:: Float64 = 3600.0 ,
77- max_eval:: Int = - 1 ,
78- verbose:: Int = 0 ,
79- ) where {T, V}
80-
63+ solver:: R2Solver{V} ,
64+ nlp:: AbstractNLPModel{T, V} ;
65+ x0:: V = nlp. meta. x0,
66+ atol = eps (T)^ (1 / 2 ),
67+ rtol = eps (T)^ (1 / 2 ),
68+ η1 = eps (T)^ (1 / 4 ),
69+ η2 = T (0.95 ),
70+ γ1 = T (1 / 2 ),
71+ γ2 = 1 / γ1,
72+ σmin = zero (T),
73+ max_time:: Float64 = 3600.0 ,
74+ max_eval:: Int = - 1 ,
75+ verbose:: Int = 0 ,
76+ ) where {T, V}
8177 unconstrained (nlp) || error (" R2 should only be called on unconstrained problems." )
8278 start_time = time ()
8379 elapsed_time = 0.0
@@ -88,7 +84,7 @@ function solve!(
8884
8985 iter = 0
9086 fk = obj (nlp, x)
91-
87+
9288 grad! (nlp, x, ∇fk)
9389 norm_∇fk = norm (∇fk)
9490 # σk = norm(hess(nlp, x))
@@ -111,16 +107,15 @@ function solve!(
111107 status = :unknown
112108
113109 while ! (optimal | tired)
114-
115110 ck .= x .- (∇fk ./ σk)
116- ΔTk= norm_∇fk^ 2 / σk
111+ ΔTk = norm_∇fk^ 2 / σk
117112 fck = obj (nlp, ck)
118113 if fck == - Inf
119114 status = :unbounded
120115 break
121116 end
122117
123- ρk = (fk - fck) / ΔTk
118+ ρk = (fk - fck) / ΔTk
124119
125120 # Update regularization parameters
126121 if ρk >= η2
@@ -141,31 +136,30 @@ function solve!(
141136 elapsed_time = time () - start_time
142137 optimal = norm_∇fk ≤ ϵ
143138 tired = neval_obj (nlp) > max_eval ≥ 0 || elapsed_time > max_time
144-
139+
145140 if verbose > 0 && mod (iter, verbose) == 0
146141 @info infoline
147142 infoline = @sprintf " %5d %9.2e %7.1e %7.1e" iter fk norm_∇fk σk
148143 end
149-
150144 end
151-
145+
152146 status = if optimal
153- :first_order
154- elseif tired
155- if elapsed_time > max_time
156- status = :max_time
157- elseif neval_obj (nlp) > max_eval
158- status = :max_eval
159- end
147+ :first_order
148+ elseif tired
149+ if elapsed_time > max_time
150+ status = :max_time
151+ elseif neval_obj (nlp) > max_eval
152+ status = :max_eval
160153 end
154+ end
161155
162156 return GenericExecutionStats (
163- status,
164- nlp,
165- solution = x,
166- objective = fk,
167- dual_feas = norm_∇fk,
168- elapsed_time = elapsed_time,
169- iter = iter,
170- )
171- end
157+ status,
158+ nlp,
159+ solution = x,
160+ objective = fk,
161+ dual_feas = norm_∇fk,
162+ elapsed_time = elapsed_time,
163+ iter = iter,
164+ )
165+ end
0 commit comments