Skip to content

Commit 7df80c2

Browse files
aldmadpo
authored andcommitted
add R2 method, add max_eval, rename cviol, remove rtol
1 parent 8d2ac12 commit 7df80c2

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed

examples/demo-cutest.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ nlp = CUTEstModel(problem_name)
99

1010
h = NormL1(1.0)
1111

12-
options = ROSolverOptions(ϵa = 1e-6, ϵr = 1e-6, verbose = 2)
13-
12+
options = ROSolverOptions(ϵa = 1e-6, verbose = 1)
1413
stats = AL(nlp, h, options)
14+
print(stats)
1515

1616
finalize(nlp)

src/AL_alg.jl

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,18 @@ function AL(
100100
nlp::AbstractNLPModel,
101101
h::H,
102102
options::ROSolverOptions{T};
103-
x0::AbstractVector{T} = nlp.meta.x0,
104-
y0::AbstractVector{T} = nlp.meta.y0,
103+
x0::V = nlp.meta.x0,
104+
y0::V = nlp.meta.y0,
105105
subsolver = has_bounds(nlp) ? TR : R2,
106106
subsolver_logger::Logging.AbstractLogger = Logging.NullLogger(),
107-
subsolver_options::ROSolverOptions{T} = ROSolverOptions{T}(),
108107
init_penalty::Real = T(10),
109108
factor_penalty_up::Real = T(2),
110-
ctol::Real = options.ϵa > 0 ? options.ϵa : options.ϵr,
109+
ctol::Real = options.ϵa,
111110
init_subtol::Real = T(0.1),
112111
factor_primal_linear_improvement::Real = T(3 // 4),
113112
factor_decrease_subtol::Real = T(1 // 4),
114113
dual_safeguard = project_y!,
114+
) where {H, T <: Real, V}
115115
if !(nlp.meta.minimize)
116116
error("AL only works for minimization problems")
117117
end
@@ -134,6 +134,7 @@ function AL(
134134
verbose = options.verbose
135135
max_time = options.maxTime
136136
max_iter = options.maxIter
137+
max_eval = -1
137138

138139
# initialization
139140
@assert length(x0) == nlp.meta.nvar
@@ -149,21 +150,19 @@ function AL(
149150
mu = init_penalty
150151
alf = AugLagModel(nlp, y, mu, x, fx, cx)
151152

152-
V = norm(alf.cx, Inf)
153-
V_old = Inf
153+
cviol = norm(alf.cx, Inf)
154+
cviol_old = Inf
154155
iter = 0
155156
subiters = 0
156157
done = false
157-
158-
suboptions = subsolver_options
159158
subtol = init_subtol
160159

161160
if verbose > 0
162161
@info log_header(
163162
[:iter, :subiter, :fx, :prim_res, , :normy, :dual_tol, :inner_status],
164163
[Int, Int, Float64, Float64, Float64, Float64, Float64, Symbol],
165164
)
166-
@info log_row(Any[iter, subiters, fx, V, alf.μ, norm(y), subtol])
165+
@info log_row(Any[iter, subiters, fx, cviol, alf.μ, norm(y), subtol])
167166
end
168167

169168
while !done
@@ -173,10 +172,9 @@ function AL(
173172
dual_safeguard(alf)
174173

175174
# AL subproblem
176-
suboptions.ϵa = max(subtol, options.ϵa)
177-
suboptions.ϵr = max(subtol, options.ϵr)
175+
subtol = max(subtol, options.ϵa)
178176
subout = with_logger(subsolver_logger) do
179-
subsolver(alf, h, suboptions, x0 = x)
177+
subsolver(alf, h, x = x, atol = subtol, rtol = zero(T))
180178
end
181179
x .= subout.solution
182180
subiters += subout.iter
@@ -190,21 +188,22 @@ function AL(
190188
set_constraint_multipliers!(stats, alf.y)
191189

192190
# stationarity measure
191+
# FIXME it seems that R2 returns no dual_feas in `dual_feas`
192+
# but in `solver_specific.xi`
193193
if subout.dual_residual_reliable
194194
set_dual_residual!(stats, subout.dual_feas)
195195
end
196196

197197
# primal violation
198-
V = norm(alf.cx, Inf)
199-
set_primal_residual!(stats, V)
198+
cviol = norm(alf.cx, Inf)
199+
set_primal_residual!(stats, cviol)
200200

201201
# termination checks
202202
dual_ok =
203203
subout.status_reliable &&
204204
subout.status == :first_order &&
205-
suboptions.ϵa <= options.ϵa &&
206-
suboptions.ϵr <= options.ϵr
207-
primal_ok = V <= ctol
205+
subtol <= options.ϵa
206+
primal_ok = cviol <= ctol
208207
optimal = dual_ok && primal_ok
209208

210209
set_iter!(stats, iter)
@@ -221,6 +220,7 @@ function AL(
221220
unbounded = false,
222221
stalled = false,
223222
exception = false,
223+
max_eval = max_eval,
224224
max_time = max_time,
225225
max_iter = max_iter,
226226
),
@@ -229,16 +229,16 @@ function AL(
229229
done = stats.status != :unknown
230230

231231
if verbose > 0 && (mod(stats.iter, verbose) == 0 || done)
232-
@info log_row(Any[iter, subiters, fx, V, alf.μ, norm(alf.y), subtol, subout.status])
232+
@info log_row(Any[iter, subiters, fx, cviol, alf.μ, norm(alf.y), subtol, subout.status])
233233
end
234234

235235
if !done
236-
if V > max(ctol, factor_primal_linear_improvement * V_old)
236+
if cviol > max(ctol, factor_primal_linear_improvement * cviol_old)
237237
#@info "decreasing mu"
238238
mu *= factor_penalty_up
239239
end
240240
update_μ!(alf, mu)
241-
V_old = V
241+
cviol_old = cviol
242242
subtol *= factor_decrease_subtol
243243
end
244244
end

src/R2_alg.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,16 @@ function R2(
204204
)
205205
end
206206

207+
function R2(
208+
nlp::AbstractNLPModel{R, V},
209+
h;
210+
selected::AbstractVector{<:Integer} = 1:(nlp.meta.nvar),
211+
kwargs...,
212+
) where {R, V}
213+
reg_nlp = RegularizedNLPModel(nlp, h, selected)
214+
return R2(reg_nlp; kwargs...)
215+
end
216+
207217
function R2(
208218
f::F,
209219
∇f!::G,

0 commit comments

Comments
 (0)