11export chainwoo
22
3- function chainwoo (; n:: Int = default_nvar, type:: Type{T} = Float64, kwargs... ) where {T}
3+ function chainwoo (; use_nls:: Bool = false , kwargs... )
4+ model = use_nls ? :nls : :nlp
5+ return chainwoo (Val (model); kwargs... )
6+ end
7+
8+ function chainwoo (:: Val{:nlp} ; n:: Int = default_nvar, type:: Type{T} = Float64, kwargs... ) where {T}
49 (n % 4 == 0 ) || @warn (" chainwoo: number of variables adjusted to be a multiple of 4" )
510 n = 4 * max (1 , div (n, 4 ))
611 function f (x; n = length (x))
@@ -16,3 +21,26 @@ function chainwoo(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) w
1621 x0 = vcat ([- 3 , - 1 , - 3 , - 1 ], - 2 * ones (T, n - 4 ))
1722 return ADNLPModels. ADNLPModel (f, x0, name = " chainwoo" ; kwargs... )
1823end
24+
25+ function chainwoo (:: Val{:nls} ; n:: Int = default_nvar, type:: Type{T} = Float64, kwargs... ) where {T}
26+ (n % 4 == 0 ) || @warn (" chainwoo: number of variables adjusted to be a multiple of 4" )
27+ n = 4 * max (1 , div (n, 4 ))
28+ function F! (r, x; n = length (x))
29+ nb = div (n, 2 ) - 1
30+ r[1 ] = 1
31+ idx = 2
32+ @inbounds for i = 1 : nb
33+ r[idx] = 10 * (x[2 * i] - x[2 * i - 1 ]^ 2 )
34+ r[idx + 1 ] = 1 - x[2 * i - 1 ]
35+ r[idx + 2 ] = T (sqrt (90 )) * (x[2 * i + 2 ] - x[2 * i + 1 ]^ 2 )
36+ r[idx + 3 ] = 1 - x[2 * i + 1 ]
37+ r[idx + 4 ] = T (sqrt (10 )) * (x[2 * i] + x[2 * i + 2 ] - 2 )
38+ r[idx + 5 ] = (x[2 * i] - x[2 * i + 2 ]) / T (sqrt (10 ))
39+ idx += 6
40+ end
41+ return r
42+ end
43+ nequ = 1 + 6 * (div (n, 2 ) - 1 )
44+ x0 = vcat ([- 3 , - 1 , - 3 , - 1 ], - 2 * ones (T, n - 4 ))
45+ return ADNLPModels. ADNLSModel! (F!, x0, nequ, name = " chainwoo-nls" ; kwargs... )
46+ end
0 commit comments