@@ -11,12 +11,144 @@ Modified problem 14 in the Hock-Schittkowski suite
1111
1212x₀ = [2.0, 2.0].
1313"""
14- mutable struct SimpleNLPModel{T, S} <: AbstractNLPModel{T, S}
15- meta:: NLPModelMeta{T, S}
14+ mutable struct SimpleNLPModel{T, S, M <: AbstractNLPModelMeta{T, S} } <: AbstractNLPModel{T, S}
15+ meta:: M
1616 counters:: Counters
1717end
1818
19- function SimpleNLPModel (:: Type{T} ) where {T}
19+ mutable struct SimpleNLPMeta{T, S} <: AbstractNLPModelMeta{T, S}
20+ nvar:: Int
21+ x0:: S
22+ lvar:: S
23+ uvar:: S
24+
25+ ifix:: Vector{Int}
26+ ilow:: Vector{Int}
27+ iupp:: Vector{Int}
28+ irng:: Vector{Int}
29+ ifree:: Vector{Int}
30+ iinf:: Vector{Int}
31+
32+ nlvb:: Int
33+ nlvo:: Int
34+ nlvc:: Int
35+
36+ ncon:: Int
37+ y0:: S
38+ lcon:: S
39+ ucon:: S
40+
41+ jfix:: Vector{Int}
42+ jlow:: Vector{Int}
43+ jupp:: Vector{Int}
44+ jrng:: Vector{Int}
45+ jfree:: Vector{Int}
46+ jinf:: Vector{Int}
47+
48+ nnzo:: Int
49+ nnzj:: Int
50+ nnzh:: Int
51+
52+ nlin:: Int
53+ nnln:: Int
54+
55+ lin:: Vector{Int}
56+ nln:: Vector{Int}
57+
58+ minimize:: Bool
59+ islp:: Bool
60+ name:: String
61+ function SimpleNLPMeta {T, S} (
62+ nvar:: Int ;
63+ x0:: S = fill! (S (undef, nvar), zero (T)),
64+ lvar:: S = fill! (S (undef, nvar), T (- Inf )),
65+ uvar:: S = fill! (S (undef, nvar), T (Inf )),
66+ nlvb = nvar,
67+ nlvo = nvar,
68+ nlvc = nvar,
69+ ncon = 0 ,
70+ y0:: S = fill! (S (undef, ncon), zero (T)),
71+ lcon:: S = fill! (S (undef, ncon), T (- Inf )),
72+ ucon:: S = fill! (S (undef, ncon), T (Inf )),
73+ nnzo = nvar,
74+ nnzj = nvar * ncon,
75+ nnzh = nvar * (nvar + 1 ) / 2 ,
76+ lin = Int[],
77+ nln = 1 : ncon,
78+ nlin = length (lin),
79+ nnln = length (nln),
80+ minimize = true ,
81+ islp = false ,
82+ name = " Generic" ,
83+ ) where {T, S}
84+ if (nvar < 1 ) || (ncon < 0 )
85+ error (" Nonsensical dimensions" )
86+ end
87+
88+ @lencheck nvar x0 lvar uvar
89+ @lencheck ncon y0 lcon ucon
90+ @lencheck nlin lin
91+ @lencheck nnln nln
92+ @rangecheck 1 ncon lin nln
93+
94+ ifix = findall (lvar .== uvar)
95+ ilow = findall ((lvar .> T (- Inf )) .& (uvar .== T (Inf )))
96+ iupp = findall ((lvar .== T (- Inf )) .& (uvar .< T (Inf )))
97+ irng = findall ((lvar .> T (- Inf )) .& (uvar .< T (Inf )) .& (lvar .< uvar))
98+ ifree = findall ((lvar .== T (- Inf )) .& (uvar .== T (Inf )))
99+ iinf = findall (lvar .> uvar)
100+
101+ jfix = findall (lcon .== ucon)
102+ jlow = findall ((lcon .> T (- Inf )) .& (ucon .== T (Inf )))
103+ jupp = findall ((lcon .== T (- Inf )) .& (ucon .< T (Inf )))
104+ jrng = findall ((lcon .> T (- Inf )) .& (ucon .< T (Inf )) .& (lcon .< ucon))
105+ jfree = findall ((lcon .== T (- Inf )) .& (ucon .== T (Inf )))
106+ jinf = findall (lcon .> ucon)
107+
108+ nnzj = max (0 , nnzj)
109+ nnzh = max (0 , nnzh)
110+
111+ new {T, S} (
112+ nvar,
113+ x0,
114+ lvar,
115+ uvar,
116+ ifix,
117+ ilow,
118+ iupp,
119+ irng,
120+ ifree,
121+ iinf,
122+ nlvb,
123+ nlvo,
124+ nlvc,
125+ ncon,
126+ y0,
127+ lcon,
128+ ucon,
129+ jfix,
130+ jlow,
131+ jupp,
132+ jrng,
133+ jfree,
134+ jinf,
135+ nnzo,
136+ nnzj,
137+ nnzh,
138+ nlin,
139+ nnln,
140+ lin,
141+ nln,
142+ minimize,
143+ islp,
144+ name,
145+ )
146+ end
147+ end
148+ NLPModels. equality_constrained (meta:: SimpleNLPMeta ) = length (meta. jfix) == meta. ncon > 0
149+ NLPModels. unconstrained (meta:: SimpleNLPMeta ) = meta. ncon == 0 && ! has_bounds (meta)
150+
151+ function SimpleNLPModel (:: Type{T} , :: Type{NLPModelMeta} ) where {T}
20152 meta = NLPModelMeta {T, Vector{T}} (
21153 2 ,
22154 nnzh = 2 ,
@@ -28,10 +160,23 @@ function SimpleNLPModel(::Type{T}) where {T}
28160 ucon = T[0 ; Inf ],
29161 name = " Simple NLP Model" ,
30162 )
31-
32163 return SimpleNLPModel (meta, Counters ())
33164end
34- SimpleNLPModel () = SimpleNLPModel (Float64)
165+ function SimpleNLPModel (:: Type{T} , :: Type{SimpleNLPMeta} ) where {T}
166+ meta = SimpleNLPMeta {T, Vector{T}} (
167+ 2 ,
168+ nnzh = 2 ,
169+ ncon = 2 ,
170+ lvar = zeros (T, 2 ),
171+ uvar = ones (T, 2 ),
172+ x0 = T[2 ; 2 ],
173+ lcon = T[0 ; 0 ],
174+ ucon = T[0 ; Inf ],
175+ name = " Simple NLP Model" ,
176+ )
177+ return SimpleNLPModel (meta, Counters ())
178+ end
179+ SimpleNLPModel () = SimpleNLPModel (Float64, NLPModelMeta)
35180
36181function NLPModels. obj (nlp:: SimpleNLPModel , x:: AbstractVector )
37182 @lencheck 2 x
0 commit comments