I am trying to get the penalty function to run using a given optimize function at the top of the code. I want the penalty_method function to run for a certain amount of iterations (n=1000, so i=500), but I cannot figure out the structure. f, g, c, and x0 are given by the function optimize, so I need to integrate my code to run penalty_method to converge on a minimum. There are two constraints given as a vector by the function optimize, c1 and c2. Am I correctly calling them by saying c(x), and c(x)? In the end, I want the value x’ (the optimized x) extracted from the function optimize.
function optimize(f, g, c, x0, n, prob) x′= x0 # y_best=f(x') i=1 R = penalty_method(f, p, x, k_max; ρ=1, γ=2) while i <= n/2 #fc + 2*gc i+=1 x' = penalty_method(f, p, x', k_max; ρ=1, γ=2) end return x′ end function penalty_method(f, p, x, k_max; ρ=1, γ=2) for k in 1 : k_max q1 = c(x) q2 = c(x) p = x -> f(x) + ρ*(sum(q1>0)+sum(q2>0)) x = powell(x -> f(x) + ρ*p(x), x) ρ *= γ if p(x) == 0 return x end end return x end function powell(f, x, ϵ) n = length(x) U = [basis(i,n) for i in 1 : n] Δ = Inf while Δ > ϵ x′ = x for i in 1 : n d = U[i] x′ = line_search(f, x′, d) end for i in 1 : n-1 U[i] = U[i+1] end U[n] = d = x′ - x x′ = line_search(f, x, d) Δ = norm(x′ - x) x = x′ end return x end