Skip to content

Commit fc63949

Browse files
add update_bounds function
1 parent 120d073 commit fc63949

File tree

3 files changed

+17
-31
lines changed

3 files changed

+17
-31
lines changed

src/RegularizedOptimization.jl

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

32+
# update l_bound_k and u_bound_k
33+
function update_bounds!(l_bound_k, u_bound_k, is_subsolver, l_bound, u_bound, xk, Δ)
34+
if is_subsolver
35+
@. l_bound_k = max(xk - Δ, l_bound)
36+
@. u_bound_k = min(xk + Δ, u_bound)
37+
else
38+
@. l_bound_k = max(-Δ, l_bound - xk)
39+
@. u_bound_k = min(Δ, u_bound - xk)
40+
end
41+
end
42+
3243
include("utils.jl")
3344
include("input_struct.jl")
3445
include("PG_alg.jl")

src/TRDH_alg.jl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -532,14 +532,3 @@ function SolverCore.solve!(
532532

533533
return stats
534534
end
535-
536-
# update l_bound_k and u_bound_k
537-
function update_bounds!(l_bound_k, u_bound_k, is_subsolver, l_bound, u_bound, xk, Δ)
538-
if is_subsolver
539-
@. l_bound_k = max(xk - Δ, l_bound)
540-
@. u_bound_k = min(xk + Δ, u_bound)
541-
else
542-
@. l_bound_k = max(-Δ, l_bound - xk)
543-
@. u_bound_k = min(Δ, u_bound - xk)
544-
end
545-
end

src/TR_alg.jl

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,9 @@ function SolverCore.solve!(
225225
has_bnds = solver.has_bnds
226226

227227
if has_bnds || isa(solver.subsolver, TRDHSolver) #TODO elsewhere ?
228-
l_bound_m_x = solver.l_bound_m_x
229-
u_bound_m_x = solver.u_bound_m_x
230-
l_bound = solver.l_bound
231-
u_bound = solver.u_bound
232-
@. l_bound_m_x = l_bound - xk
233-
@. u_bound_m_x = u_bound - xk
234-
@. l_bound_m_x .= max.(l_bound_m_x, -Δk)
235-
@. u_bound_m_x .= min.(u_bound_m_x, Δk)
228+
l_bound_m_x, u_bound_m_x = solver.l_bound_m_x, solver.u_bound_m_x
229+
l_bound, u_bound = solver.l_bound, solver.u_bound
230+
update_bounds!(l_bound_m_x, u_bound_m_x, false, l_bound, u_bound, xk, Δk)
236231
set_bounds!(ψ, l_bound_m_x, u_bound_m_x)
237232
set_bounds!(solver.subsolver.ψ, l_bound_m_x, u_bound_m_x)
238233
else
@@ -342,10 +337,7 @@ function SolverCore.solve!(
342337
∆_effective = min* χ(s), Δk)
343338

344339
if has_bnds || isa(solver.subsolver, TRDHSolver) #TODO elsewhere ?
345-
@. l_bound_m_x = l_bound - xk
346-
@. u_bound_m_x = u_bound - xk
347-
@. l_bound_m_x .= max.(l_bound_m_x, -∆_effective)
348-
@. u_bound_m_x .= min.(u_bound_m_x, ∆_effective)
340+
update_bounds!(l_bound_m_x, u_bound_m_x, false, l_bound, u_bound, xk, Δk)
349341
set_bounds!(ψ, l_bound_m_x, u_bound_m_x)
350342
set_bounds!(solver.subsolver.ψ, l_bound_m_x, u_bound_m_x)
351343
else
@@ -420,10 +412,7 @@ function SolverCore.solve!(
420412
if η1 ρk < Inf
421413
xk .= xkn
422414
if has_bnds || isa(solver.subsolver, TRDHSolver)
423-
@. l_bound_m_x = l_bound - xk
424-
@. u_bound_m_x = u_bound - xk
425-
@. l_bound_m_x .= max.(l_bound_m_x, -Δk)
426-
@. u_bound_m_x .= min.(u_bound_m_x, Δk)
415+
update_bounds!(l_bound_m_x, u_bound_m_x, false, l_bound, u_bound, xk, Δk)
427416
set_bounds!(ψ, l_bound_m_x, u_bound_m_x)
428417
set_bounds!(solver.subsolver.ψ, l_bound_m_x, u_bound_m_x)
429418
end
@@ -447,10 +436,7 @@ function SolverCore.solve!(
447436
if ρk < η1 || ρk == Inf
448437
Δk = Δk / 2
449438
if has_bnds || isa(solver.subsolver, TRDHSolver)
450-
@. l_bound_m_x = l_bound - xk
451-
@. u_bound_m_x = u_bound - xk
452-
@. l_bound_m_x .= max.(l_bound_m_x, -Δk)
453-
@. u_bound_m_x .= min.(u_bound_m_x, Δk)
439+
update_bounds!(l_bound_m_x, u_bound_m_x, false, l_bound, u_bound, xk, Δk)
454440
set_bounds!(ψ, l_bound_m_x, u_bound_m_x)
455441
set_bounds!(solver.subsolver.ψ, l_bound_m_x, u_bound_m_x)
456442
else

0 commit comments

Comments
 (0)