-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from emmt/CUTEst
Interface to CUTEst
- Loading branch information
Showing
4 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module PRIMACUTEstExt | ||
|
||
if isdefined(Base, :get_extension) | ||
using NLPModels | ||
using CUTEst | ||
using PRIMA | ||
else | ||
using ..NLPModels | ||
using ..CUTEst | ||
using ..PRIMA | ||
end | ||
|
||
for func in (:uobyqa, :newuoa, :bobyqa, :lincoa, :cobyla, :prima) | ||
@eval function PRIMA.$(Symbol(func,"_CUTEst"))(name::AbstractString; kwds...) | ||
nlp = CUTEstModel(name) | ||
try | ||
return $func(nlp; kwds...) | ||
finally | ||
finalize(nlp) | ||
end | ||
end | ||
end | ||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
module PRIMANLPModelsExt | ||
|
||
if isdefined(Base, :get_extension) | ||
using NLPModels | ||
using PRIMA | ||
else | ||
using ..NLPModels | ||
using ..PRIMA | ||
end | ||
|
||
# This structure is to wrap a non-linear problem model into a callable object. | ||
struct ObjectiveFunction{F<:AbstractNLPModel} <: Function | ||
nlp::F | ||
end | ||
(f::ObjectiveFunction)(x::AbstractVector) = obj(f.nlp, x) | ||
|
||
function check_variables(nlp::AbstractNLPModel, x0::AbstractVector) | ||
length(x0) == get_nvar(nlp) || error( | ||
"initial variables must have $(get_nvar(nlp)) elements") | ||
return x0 | ||
end | ||
|
||
const Variables = AbstractVector{<:Real} | ||
|
||
for func in (:uobyqa, :newuoa) | ||
@eval function PRIMA.$func(nlp::AbstractNLPModel, x0::Variables = get_x0(nlp); kwds...) | ||
has_bounds(nlp) && error("`$($func)` cannot solve problems with bound constraints") | ||
has_equalities(nlp) && error("`$($func)` cannot solve problems with equality constraints") | ||
has_inequalities(nlp) && error("`$($func)` cannot solve problems with inequality constraints") | ||
return uobyqa(ObjectiveFunction(nlp), check_variables(nlp, x0); kwds...) | ||
end | ||
end | ||
|
||
function PRIMA.bobyqa(nlp::AbstractNLPModel, x0::Variables = get_x0(nlp); kwds...) | ||
has_equalities(nlp) && error("`bobyqa` cannot solve problems with equality constraints") | ||
has_inequalities(nlp) && error("`bobyqa` cannot solve problems with inequality constraints") | ||
return bobyqa(ObjectiveFunction(nlp), check_variables(nlp, x0); kwds..., | ||
xl = get_lvar(nlp), xu = get_uvar(nlp)) | ||
end | ||
|
||
function PRIMA.lincoa(nlp::AbstractNLPModel, x0::Variables = get_x0(nlp); kwds...) | ||
nlin = get_nlin(nlp) # number of linear constraints | ||
nnln = get_nnln(nlp) # number of non-linear constraints | ||
nlin == 0 || error("linear constraints not yet implemented for NLPModels in `lincoa`") | ||
nnln == 0 || error("`lincoa` cannot solve problems with non-linear constraints") | ||
return lincoa(ObjectiveFunction(nlp), check_variables(nlp, x0); kwds..., | ||
xl = get_lvar(nlp), xu = get_uvar(nlp), | ||
linear_eq = nothing, linear_ineq = nothing) | ||
end | ||
|
||
function PRIMA.cobyla(nlp::AbstractNLPModel, x0::Variables = get_x0(nlp); kwds...) | ||
nlin = get_nlin(nlp) # number of linear constraints | ||
nnln = get_nnln(nlp) # number of non-linear constraints | ||
nlin == 0 || error("linear constraints not yet implemented for NLPModels in `cobyla`") | ||
nnln == 0 || error("non-linear constraints not yet implemented for NLPModels in `cobyla`") | ||
return cobyla(ObjectiveFunction(nlp), check_variables(nlp, x0); kwds..., | ||
xl = get_lvar(nlp), xu = get_uvar(nlp), | ||
linear_eq = nothing, linear_ineq = nothing, | ||
nonlinear_eq = nothing, nonlinear_ineq = nothing) | ||
end | ||
|
||
function PRIMA.prima(nlp::AbstractNLPModel, x0::Variables = get_x0(nlp); kwds...) | ||
nlin = get_nlin(nlp) # number of linear constraints | ||
nnln = get_nnln(nlp) # number of non-linear constraints | ||
if nnln > 0 | ||
# Only COBYLA can deal with non-linear constraints. | ||
error("solving problem with non-linear constraints by COBYLA not yet implemented") | ||
return cobyla(nlp, x0; kwds...) | ||
elseif nlin > 0 | ||
# LINCOA can deal with bounds and linear constraints. | ||
error("solving problem with linear constraints by LINCOA not yet implemented") | ||
return lincoa(nlp, x0; kwds...) | ||
elseif has_bounds(nlp) | ||
# BOBYQA can deal with bounds. | ||
return bobyqa(nlp, x0; kwds...) | ||
else | ||
# Use NEWUOA for unconstrained problems. | ||
return newuoa(nlp, x0; kwds...) | ||
end | ||
end | ||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6c30115
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@check-spelling-bot Report
🔴 Please review
See the 📜action log or 📝 job summary for details.
Unrecognized words (8)
nlin
nlp
nnln
nvar
PRIMACUT
PRIMANLP
uvar
weakdeps
To accept these unrecognized words as correct, you could run the following commands
... in a clone of the git@github.com:libprima/PRIMA.jl.git repository
on the
main
branch (ℹ️ how do I use this?):Errors (1)
See the 📜action log or 📝 job summary for details.
See ❌ Event descriptions for more information.
If the flagged items are 🤯 false positives
If items relate to a ...
binary file (or some other file you wouldn't want to check at all).
Please add a file path to the
excludes.txt
file matching the containing file.File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.
^
refers to the file's path from the root of the repository, so^README\.md$
would exclude README.md (on whichever branch you're using).well-formed pattern.
If you can write a pattern that would match it,
try adding it to the
patterns.txt
file.Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.
Note that patterns can't match multiline strings.