|
1 | 1 | module NLPModelsIpopt
|
2 | 2 |
|
3 |
| -export ipopt, IpoptSolver, reset!, solve! |
| 3 | +export ipopt, IpoptSolver, reset!, solve!, FeasibilityFormNLS |
4 | 4 |
|
5 | 5 | using NLPModels, Ipopt, SolverCore
|
6 | 6 |
|
@@ -181,6 +181,33 @@ function ipopt(nlp::AbstractNLPModel; kwargs...)
|
181 | 181 | return solve!(solver, nlp, stats; kwargs...)
|
182 | 182 | end
|
183 | 183 |
|
| 184 | +""" |
| 185 | + ipopt(nls::AbstractNLSModel; kwargs...) |
| 186 | +
|
| 187 | +Solves the `AbstractNLSModel` problem `nls` using `IpOpt` by converting it to a feasibility form. |
| 188 | +
|
| 189 | +# Arguments |
| 190 | +- `nls::AbstractNLSModel`: The nonlinear least squares problem to solve |
| 191 | +
|
| 192 | +For advanced usage, first define a `IpoptSolver` to preallocate the memory used in the algorithm, and then call `solve!`: |
| 193 | + solver = IpoptSolver(nls) |
| 194 | + solve!(solver, nls; kwargs...) |
| 195 | +
|
| 196 | +# Examples |
| 197 | +```julia |
| 198 | +using NLPModelsIpopt, ADNLPModels |
| 199 | +nls = ADNLSModel(x -> [x[1] - 1, x[2] - 2], [0.0, 0.0], 2) |
| 200 | +stats = ipopt(nls, print_level = 0) |
| 201 | +``` |
| 202 | +""" |
| 203 | +function ipopt(nls::AbstractNLSModel; kwargs...) |
| 204 | + feasibility_form = FeasibilityFormNLS(nls) |
| 205 | + # Call the general AbstractNLPModel method |
| 206 | + solver = IpoptSolver(feasibility_form) |
| 207 | + stats = GenericExecutionStats(feasibility_form) |
| 208 | + return solve!(solver, feasibility_form, stats; kwargs...) |
| 209 | +end |
| 210 | + |
184 | 211 | function SolverCore.solve!(
|
185 | 212 | solver::IpoptSolver,
|
186 | 213 | nlp::AbstractNLPModel,
|
@@ -304,4 +331,20 @@ function SolverCore.solve!(
|
304 | 331 | stats
|
305 | 332 | end
|
306 | 333 |
|
| 334 | +""" |
| 335 | + FeasibilityFormNLS(nls::AbstractNLSModel) |
| 336 | +
|
| 337 | +Convert an `AbstractNLSModel` to a form suitable for feasibility-based optimization. |
| 338 | +Since `AbstractNLSModel` is a subtype of `AbstractNLPModel`, this function simply returns the input model. |
| 339 | +
|
| 340 | +# Arguments |
| 341 | +- `nls::AbstractNLSModel`: The nonlinear least squares model to convert |
| 342 | +
|
| 343 | +# Returns |
| 344 | +- The same `AbstractNLSModel` instance, as it's already suitable for optimization |
| 345 | +""" |
| 346 | +function FeasibilityFormNLS(nls::AbstractNLSModel) |
| 347 | + return nls |
| 348 | +end |
| 349 | + |
307 | 350 | end # module
|
0 commit comments