Skip to content

Commit b868635

Browse files
add computation function for bounds and initialize bounds across solvers
1 parent 7b54d4f commit b868635

File tree

8 files changed

+49
-59
lines changed

8 files changed

+49
-59
lines changed

src/LMTR_alg.jl

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,7 @@ function SolverCore.solve!(
328328
∆_effective = min* χ(s), Δk)
329329

330330
if has_bnds
331-
@. l_bound_m_x = l_bound - xk
332-
@. u_bound_m_x = u_bound - xk
333-
@. l_bound_m_x .= max.(l_bound_m_x, -∆_effective)
334-
@. u_bound_m_x .= min.(u_bound_m_x, ∆_effective)
331+
update_bounds!(l_bound_m_x, u_bound_m_x, false, l_bound, u_bound, xk, ∆_effective)
335332
set_bounds!(ψ, l_bound_m_x, u_bound_m_x)
336333
set_bounds!(solver.subsolver.ψ, l_bound_m_x, u_bound_m_x)
337334
else
@@ -399,10 +396,7 @@ function SolverCore.solve!(
399396
if η1 ρk < Inf
400397
xk .= xkn
401398
if has_bnds
402-
@. l_bound_m_x = l_bound - xk
403-
@. u_bound_m_x = u_bound - xk
404-
@. l_bound_m_x .= max.(l_bound_m_x, -Δk)
405-
@. u_bound_m_x .= min.(u_bound_m_x, Δk)
399+
update_bounds!(l_bound_m_x, u_bound_m_x, false, l_bound, u_bound, xk, Δk)
406400
set_bounds!(ψ, l_bound_m_x, u_bound_m_x)
407401
set_bounds!(solver.subsolver.ψ, l_bound_m_x, u_bound_m_x)
408402
end
@@ -430,10 +424,7 @@ function SolverCore.solve!(
430424
if ρk < η1 || ρk == Inf
431425
Δk = Δk / 2
432426
if has_bnds
433-
@. l_bound_m_x = l_bound - xk
434-
@. u_bound_m_x = u_bound - xk
435-
@. l_bound_m_x .= max.(l_bound_m_x, -Δk)
436-
@. u_bound_m_x .= min.(u_bound_m_x, Δk)
427+
update_bounds!(l_bound_m_x, u_bound_m_x, false, l_bound, u_bound, xk, ∆k)
437428
set_bounds!(ψ, l_bound_m_x, u_bound_m_x)
438429
set_bounds!(solver.subsolver.ψ, l_bound_m_x, u_bound_m_x)
439430
else

src/LM_alg.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,10 @@ function SolverCore.solve!(
230230
m_monotone = length(m_fh_hist) + 1
231231

232232
if has_bnds
233-
l_bound = solver.l_bound
234-
u_bound = solver.u_bound
235-
l_bound_m_x = solver.l_bound_m_x
236-
u_bound_m_x = solver.u_bound_m_x
233+
l_bound, u_bound = solver.l_bound, solver.u_bound
234+
l_bound_m_x, u_bound_m_x = solver.l_bound_m_x, solver.u_bound_m_x
235+
update_bounds!(l_bound_m_x, u_bound_m_x, l_bound, u_bound, xk)
236+
set_bounds!(ψ, l_bound_m_x, u_bound_m_x)
237237
end
238238

239239
# initialize parameters
@@ -387,8 +387,7 @@ function SolverCore.solve!(
387387
xk .= xkn
388388

389389
if has_bnds
390-
@. l_bound_m_x = l_bound - xk
391-
@. u_bound_m_x = u_bound - xk
390+
update_bounds!(l_bound_m_x, u_bound_m_x, l_bound, u_bound, xk)
392391
set_bounds!(ψ, l_bound_m_x, u_bound_m_x)
393392
end
394393

src/R2DH.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,10 @@ function SolverCore.solve!(
253253
has_bnds = solver.has_bnds
254254

255255
if has_bnds
256-
l_bound_m_x = solver.l_bound_m_x
257-
u_bound_m_x = solver.u_bound_m_x
258-
l_bound = solver.l_bound
259-
u_bound = solver.u_bound
256+
l_bound, u_bound = solver.l_bound, solver.u_bound
257+
l_bound_m_x, u_bound_m_x = solver.l_bound_m_x, solver.u_bound_m_x
258+
update_bounds!(l_bound_m_x, u_bound_m_x, l_bound, u_bound, xk)
259+
set_bounds!(ψ, l_bound_m_x, u_bound_m_x)
260260
end
261261
m_monotone = length(m_fh_hist) + 1
262262

@@ -388,8 +388,7 @@ function SolverCore.solve!(
388388
if η1 ρk < Inf
389389
xk .= xkn
390390
if has_bnds
391-
@. l_bound_m_x = l_bound - xk
392-
@. u_bound_m_x = u_bound - xk
391+
update_bounds!(l_bound_m_x, u_bound_m_x, l_bound, u_bound, xk)
393392
set_bounds!(ψ, l_bound_m_x, u_bound_m_x)
394393
end
395394
fk = fkn

src/R2N.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,10 @@ function SolverCore.solve!(
243243
has_bnds = solver.has_bnds
244244

245245
if has_bnds
246-
l_bound_m_x = solver.l_bound_m_x
247-
u_bound_m_x = solver.u_bound_m_x
248-
l_bound = solver.l_bound
249-
u_bound = solver.u_bound
246+
l_bound, u_bound = solver.l_bound, solver.u_bound
247+
l_bound_m_x, u_bound_m_x = solver.l_bound_m_x, solver.u_bound_m_x
248+
update_bounds!(l_bound_m_x, u_bound_m_x, l_bound, u_bound, xk)
249+
set_bounds!(ψ, l_bound_m_x, u_bound_m_x)
250250
end
251251
m_monotone = length(m_fh_hist) + 1
252252

@@ -430,8 +430,7 @@ function SolverCore.solve!(
430430
if η1 ρk < Inf
431431
xk .= xkn
432432
if has_bnds
433-
@. l_bound_m_x = l_bound - xk
434-
@. u_bound_m_x = u_bound - xk
433+
update_bounds!(l_bound_m_x, u_bound_m_x, l_bound, u_bound, xk)
435434
set_bounds!(ψ, l_bound_m_x, u_bound_m_x)
436435
end
437436
#update functions

src/R2_alg.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,10 @@ function SolverCore.solve!(
343343
s = solver.s
344344
has_bnds = solver.has_bnds
345345
if has_bnds
346-
l_bound = solver.l_bound
347-
u_bound = solver.u_bound
348-
l_bound_m_x = solver.l_bound_m_x
349-
u_bound_m_x = solver.u_bound_m_x
346+
l_bound, u_bound = solver.l_bound, solver.u_bound
347+
l_bound_m_x, u_bound_m_x = solver.l_bound_m_x, solver.u_bound_m_x
348+
update_bounds!(l_bound_m_x, u_bound_m_x, l_bound, u_bound, xk)
349+
set_bounds!(ψ, l_bound_m_x, u_bound_m_x)
350350
end
351351

352352
# initialize parameters
@@ -462,8 +462,7 @@ function SolverCore.solve!(
462462
if η1 ρk < Inf
463463
xk .= xkn
464464
if has_bnds
465-
@. l_bound_m_x = l_bound - xk
466-
@. u_bound_m_x = u_bound - xk
465+
update_bounds!(l_bound_m_x, u_bound_m_x, l_bound, u_bound, xk)
467466
set_bounds!(ψ, l_bound_m_x, u_bound_m_x)
468467
end
469468
fk = fkn

src/RegularizedOptimization.jl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,6 @@ Notably, you can access, and modify, the following:
3434
- `stats.elapsed_time`: elapsed time in seconds.
3535
"
3636

37-
# update l_bound_k and u_bound_k
38-
function update_bounds!(l_bound_k, u_bound_k, is_subsolver, l_bound, u_bound, xk, Δ)
39-
if is_subsolver
40-
@. l_bound_k = max(xk - Δ, l_bound)
41-
@. u_bound_k = min(xk + Δ, u_bound)
42-
else
43-
@. l_bound_k = max(-Δ, l_bound - xk)
44-
@. u_bound_k = min(Δ, u_bound - xk)
45-
end
46-
end
47-
4837
include("utils.jl")
4938
include("input_struct.jl")
5039
include("TR_alg.jl")

src/TRDH_alg.jl

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,17 @@ function SolverCore.solve!(
265265
χ = solver.χ
266266
has_bnds = solver.has_bnds
267267

268+
is_subsolver = h isa ShiftedProximableFunction # case TRDH is used as a subsolver
269+
268270
if has_bnds
269-
l_bound_m_x = solver.l_bound_m_x
270-
u_bound_m_x = solver.u_bound_m_x
271-
l_bound = solver.l_bound
272-
u_bound = solver.u_bound
271+
l_bound_m_x, u_bound_m_x = solver.l_bound_m_x, solver.u_bound_m_x
272+
l_bound, u_bound = solver.l_bound, solver.u_bound
273+
if is_subsolver
274+
l_bound .= ψ.l
275+
u_bound .= ψ.u
276+
end
277+
update_bounds!(l_bound_m_x, u_bound_m_x, is_subsolver, l_bound, u_bound, xk, Δk)
278+
set_bounds!(ψ, l_bound_m_x, u_bound_m_x)
273279
end
274280

275281
# initialize parameters
@@ -286,13 +292,6 @@ function SolverCore.solve!(
286292
improper == true && @warn "TRDH: Improper term detected"
287293
improper == true && return stats
288294

289-
is_subsolver = h isa ShiftedProximableFunction # case TRDH is used as a subsolver
290-
291-
if is_subsolver
292-
l_bound .= ψ.l
293-
u_bound .= ψ.u
294-
end
295-
296295
if verbose > 0
297296
@info log_header(
298297
[:iter, :fx, :hx, :xi, , , :normx, :norms, :normD, :arrow],
@@ -439,7 +438,7 @@ function SolverCore.solve!(
439438
xk .= xkn
440439
if has_bnds
441440
update_bounds!(l_bound_m_x, u_bound_m_x, is_subsolver, l_bound, u_bound, xk, Δk)
442-
has_bnds && set_bounds!(ψ, l_bound_m_x, u_bound_m_x)
441+
set_bounds!(ψ, l_bound_m_x, u_bound_m_x)
443442
end
444443
fk = fkn
445444
hk = hkn

src/utils.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,18 @@ function get_status(
155155
:unknown
156156
end
157157
end
158+
159+
function update_bounds!(l_bound_m_x::V, u_bound_m_x::V, l_bound::V, u_bound::V, xk::V,) where {V <: AbstractVector}
160+
@. l_bound_m_x = l_bound - xk
161+
@. u_bound_m_x = u_bound - xk
162+
end
163+
164+
function update_bounds!(l_bound_m_x::V, u_bound_m_x::V, is_subsolver::Bool, l_bound::V, u_bound::V, xk::V, Δ::T) where {T <: Real, V <: AbstractVector{T}}
165+
if is_subsolver
166+
@. l_bound_m_x = max(xk - Δ, l_bound)
167+
@. u_bound_m_x = min(xk + Δ, u_bound)
168+
else
169+
@. l_bound_m_x = max(-Δ, l_bound - xk)
170+
@. u_bound_m_x = min(Δ, u_bound - xk)
171+
end
172+
end

0 commit comments

Comments
 (0)