Skip to content

Commit 15550bd

Browse files
🤖 Format .jl files (#130)
Co-authored-by: tmigot <[email protected]>
1 parent b5ed99d commit 15550bd

File tree

2 files changed

+37
-43
lines changed

2 files changed

+37
-43
lines changed

src/R2.jl

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,26 @@ function R2Solver(nlp::AbstractNLPModel{T, V}) where {T, V}
5454
return R2Solver{V}(x, gx, cx)
5555
end
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...)
6360
end
6461

6562
function 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

test/test_solvers.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function tests()
77
("trunk+cg", (nlp; kwargs...) -> trunk(nlp, subsolver_type = CgSolver; kwargs...)),
88
("lbfgs", lbfgs),
99
("tron", tron),
10-
("R2", R2)
10+
("R2", R2),
1111
]
1212
unconstrained_nlp(solver)
1313
multiprecision_nlp(solver, :unc)

0 commit comments

Comments
 (0)