Skip to content

Commit 80979c4

Browse files
add rosenbrock test function
1 parent 59ba728 commit 80979c4

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

test/utils.jl

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,27 @@ macro wrappedallocs(expr)
3131
end
3232
end
3333

34-
# Construct the brock-rosenberg problem.
34+
# Construct the rosenbrock problem.
35+
36+
function rosenbrock_f(x::Vector{T}) where{T <: Real}
37+
100*(x[2]-x[1]^2)^2 + (1-x[1])^2
38+
end
39+
40+
function rosenbrock_grad!(gx::Vector{T}, x::Vector{T}) where{T <: Real}
41+
gx[1] = -400*x[1]*(x[2]-x[1]^2)-2*(1-x[1])
42+
gx[2] = 200*(x[2]-x[1]^2)
43+
end
44+
45+
function rosenbrock_hv!(hv::Vector{T}, x::Vector{T}, v::Vector{T}; obj_weight = 1.0) where{T}
46+
hv[1] = (1200*x[1]^2-400*x[2]+2)*v[1] -400*x[1]*v[2]
47+
hv[2] = -400*x[1]*v[1] + 200*v[2]
48+
end
49+
50+
function construct_rosenbrock_nlp()
51+
return NLPModel(
52+
zeros(2),
53+
rosenbrock_f,
54+
grad = rosenbrock_grad!,
55+
hprod = rosenbrock_hv!
56+
)
57+
end

0 commit comments

Comments
 (0)