Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/ADNLPProblems/ADNLPProblems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@ end
@require ADNLPModels = "54578032-b7ea-4c30-94aa-7cbd1cce6c9a" begin
using JLD2, LinearAlgebra, SparseArrays, SpecialFunctions

"""
@adjust_nvar_warn(problem_name, n_orig, n)

Issue a warning if the number of variables was adjusted, showing both original and adjusted values.
This macro provides consistent warning messages across all problems with dimension adjustments.

# Example
```julia
n_orig = n
n = 4 * max(1, div(n, 4))
@adjust_nvar_warn("woods", n_orig, n)
```
"""
macro adjust_nvar_warn(problem_name, n_orig, n)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it only in the ADNLPProblems and not in the PureJump ?

return quote
($(esc(n)) == $(esc(n_orig))) ||
@warn(string($(esc(problem_name)), ": number of variables adjusted from ",
$(esc(n_orig)), " to ", $(esc(n))))
end
end

path = dirname(@__FILE__)
files = filter(x -> x[(end - 2):end] == ".jl", readdir(path))
for file in files
Expand Down
4 changes: 4 additions & 0 deletions src/ADNLPProblems/NZF1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ function NZF1(; use_nls::Bool = false, kwargs...)
end

function NZF1(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
n_orig = n
nbis = max(2, div(n, 13))
n = 13 * nbis
@adjust_nvar_warn("NZF1", n_orig, n)
l = div(n, 13)
function f(x; l = l)
return sum(
Expand All @@ -29,8 +31,10 @@ function NZF1(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, kwarg
end

function NZF1(::Val{:nls}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
n_orig = n
nbis = max(2, div(n, 13))
n = 13 * nbis
@adjust_nvar_warn("NZF1", n_orig, n)
l = div(n, 13)
function F!(r, x; l = l)
for i = 1:l
Expand Down
16 changes: 16 additions & 0 deletions src/ADNLPProblems/bearing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ function bearing(;
# nx > 0 # grid points in 1st direction
# ny > 0 # grid points in 2nd direction

# Ensure nx and ny are at least 1, and warn if they need adjustment
nx_orig = nx
ny_orig = ny
nx = max(1, nx)
ny = max(1, ny)
if nx != nx_orig || ny != ny_orig
msg_parts = String[]
if nx != nx_orig
push!(msg_parts, "nx from $(nx_orig) to $(nx)")
end
if ny != ny_orig
push!(msg_parts, "ny from $(ny_orig) to $(ny)")
end
@warn("bearing: grid dimensions adjusted: " * join(msg_parts, ", "))
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the macro ? it's n we are interested in, not nx and ny.


b = 10 # grid is (0,2*pi)x(0,2*b)
e = 1 // 10 # eccentricity

Expand Down
4 changes: 2 additions & 2 deletions src/ADNLPProblems/catenary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ function catenary(
FRACT = 0.6,
kwargs...,
) where {T}
(n % 3 == 0) || @warn("catenary: number of variables adjusted to be a multiple of 3")
n_orig = n
n = 3 * max(1, div(n, 3))
(n < 6) || @warn("catenary: number of variables adjusted to be greater or equal to 6")
n = max(n, 6)
@adjust_nvar_warn("catenary", n_orig, n)

## Model Parameters
N = div(n, 3) - 2
Expand Down
6 changes: 4 additions & 2 deletions src/ADNLPProblems/chainwoo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ function chainwoo(; use_nls::Bool = false, kwargs...)
end

function chainwoo(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
(n % 4 == 0) || @warn("chainwoo: number of variables adjusted to be a multiple of 4")
n_orig = n
n = 4 * max(1, div(n, 4))
@adjust_nvar_warn("chainwoo", n_orig, n)
function f(x; n = length(x))
return 1 + sum(
100 * (x[2 * i] - x[2 * i - 1]^2)^2 +
Expand All @@ -23,8 +24,9 @@ function chainwoo(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, k
end

function chainwoo(::Val{:nls}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
(n % 4 == 0) || @warn("chainwoo: number of variables adjusted to be a multiple of 4")
n_orig = n
n = 4 * max(1, div(n, 4))
@adjust_nvar_warn("chainwoo", n_orig, n)
function F!(r, x; n = length(x))
nb = div(n, 2) - 1
r[1] = 1
Expand Down
3 changes: 2 additions & 1 deletion src/ADNLPProblems/clplatea.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ function clplatea(;
wght = -0.1,
kwargs...,
) where {T}
n_orig = n
p = max(floor(Int, sqrt(n)), 3)
p * p != n && @warn("clplatea: number of variables adjusted from $n to $(p*p)")
n = p * p
@adjust_nvar_warn("clplatea", n_orig, n)
hp2 = (1 // 2) * p^2
function f(x; p = p, hp2 = hp2, wght = wght)
return (eltype(x)(wght) * x[p + (p - 1) * p]) +
Expand Down
3 changes: 2 additions & 1 deletion src/ADNLPProblems/clplateb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ function clplateb(;
wght = -0.1,
kwargs...,
) where {T}
n_orig = n
p = max(floor(Int, sqrt(n)), 3)
p * p != n && @warn("clplateb: number of variables adjusted from $n to $(p*p)")
n = p * p
@adjust_nvar_warn("clplateb", n_orig, n)
hp2 = 1 // 2 * p^2
function f(x; p = p, hp2 = hp2, wght = wght)
return sum(eltype(x)(wght) / (p - 1) * x[p + (j - 1) * p] for j = 1:p) +
Expand Down
3 changes: 2 additions & 1 deletion src/ADNLPProblems/clplatec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ function clplatec(;
l = 0.01,
kwargs...,
) where {T}
n_orig = n
p = max(floor(Int, sqrt(n)), 3)
p * p != n && @warn("clplatec: number of variables adjusted from $n to $(p*p)")
n = p * p
@adjust_nvar_warn("clplatec", n_orig, n)

hp2 = 1 // 2 * p^2
function f(x; p = p, hp2 = hp2, wght = wght, r = r, l = l)
Expand Down
5 changes: 2 additions & 3 deletions src/ADNLPProblems/fminsrf2.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
export fminsrf2

function fminsrf2(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
n < 4 && @warn("fminsrf2: number of variables must be ≥ 4")
n_orig = n
n = max(4, n)

p = floor(Int, sqrt(n))
p * p != n && @warn("fminsrf2: number of variables adjusted from $n down to $(p*p)")
n = p * p
@adjust_nvar_warn("fminsrf2", n_orig, n)

h00 = 1
slopej = 4
Expand Down
8 changes: 5 additions & 3 deletions src/ADNLPProblems/powellsg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ function powellsg(; use_nls::Bool = false, kwargs...)
end

function powellsg(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
(n % 4 == 0) || @warn("powellsg: number of variables adjusted to be a multiple of 4")
n = 4 * max(1, div(n, 4)) # number of variables adjusted to be a multiple of 4
n_orig = n
n = 4 * max(1, div(n, 4))
@adjust_nvar_warn("powellsg", n_orig, n)
function f(x; n = length(x))
return sum(
(x[j] + 10 * x[j + 1])^2 +
Expand All @@ -24,8 +25,9 @@ function powellsg(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, k
end

function powellsg(::Val{:nls}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
(n % 4 == 0) || @warn("powellsg: number of variables adjusted to be a multiple of 4")
n_orig = n
n = 4 * max(1, div(n, 4))
@adjust_nvar_warn("powellsg", n_orig, n)
function F!(r, x; n = length(x))
@inbounds for j = 1:4:n
r[j] = x[j] + 10 * x[j + 1]
Expand Down
4 changes: 4 additions & 0 deletions src/ADNLPProblems/spmsrtls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ function spmsrtls(; use_nls::Bool = false, kwargs...)
end

function spmsrtls(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
n_orig = n
m = max(Int(round((n + 2) / 3)), 34)
n = m * 3 - 2
@adjust_nvar_warn("spmsrtls", n_orig, n)
p = [sin(i^2) for i = 1:n]
x0 = T[p[i] / 5 for i = 1:n]

Expand Down Expand Up @@ -59,8 +61,10 @@ function spmsrtls(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, k
end

function spmsrtls(::Val{:nls}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
n_orig = n
m = max(Int(round((n + 2) / 3)), 34)
n = m * 3 - 2
@adjust_nvar_warn("spmsrtls", n_orig, n)
p = [sin(i^2) for i = 1:n]
x0 = T[p[i] / 5 for i = 1:n]

Expand Down
3 changes: 2 additions & 1 deletion src/ADNLPProblems/srosenbr.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export srosenbr

function srosenbr(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
(n % 2 == 0) || @warn("srosenbr: number of variables adjusted to be even")
n_orig = n
n = 2 * max(1, div(n, 2))
@adjust_nvar_warn("srosenbr", n_orig, n)
function f(x; n = length(x))
return sum(100 * (x[2 * i] - x[2 * i - 1]^2)^2 + (x[2 * i - 1] - 1)^2 for i = 1:div(n, 2))
end
Expand Down
4 changes: 4 additions & 0 deletions src/ADNLPProblems/watson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ function watson(; use_nls::Bool = false, kwargs...)
end

function watson(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
n_orig = n
n = min(max(n, 2), 31)
@adjust_nvar_warn("watson", n_orig, n)
function f(x; n = n)
Ti = eltype(x)
return 1 // 2 * sum(
Expand All @@ -31,7 +33,9 @@ function watson(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, kwa
end

function watson(::Val{:nls}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
n_orig = n
n = min(max(n, 2), 31)
@adjust_nvar_warn("watson", n_orig, n)
function F!(r, x; n = n)
Ti = eltype(x)
for i = 1:29
Expand Down
3 changes: 2 additions & 1 deletion src/ADNLPProblems/woods.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export woods

function woods(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
(n % 4 == 0) || @warn("woods: number of variables adjusted to be a multiple of 4")
n_orig = n
n = 4 * max(1, div(n, 4))
@adjust_nvar_warn("woods", n_orig, n)
function f(x; n = length(x))
return sum(
100 * (x[4 * i - 2] - x[4 * i - 3]^2)^2 +
Expand Down
Loading