-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathtoint.jl
More file actions
40 lines (37 loc) · 1007 Bytes
/
toint.jl
File metadata and controls
40 lines (37 loc) · 1007 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
export toint
function toint(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
function f(x; n = length(x))
s = zero(T)
for i ∈ 1:n
ci = 1 + (i // 10)
jmin = max(1, i - 2)
jmax = min(n, i + 2)
for j ∈ jmin:jmax
aij = 5 * (1 + mod(i, 5) + mod(j, 5))
bij = (i + j) // 10
cj = (1 + j) // 10
s += aij * sin(bij + ci * x[i] + cj * x[j])
end
if iseven(n)
half = n ÷ 2
j1 = i + half
if 1 <= j1 <= n && (j1 < jmin || j1 > jmax)
aij = 5 * (1 + mod(i, 5) + mod(j1, 5))
bij = (i + j1) // 10
cj = (1 + j1) // 10
s += aij * sin(bij + ci * x[i] + cj * x[j1])
end
j2 = i - half
if 1 <= j2 <= n && j2 != j1 && (j2 < jmin || j2 > jmax)
aij = 5 * (1 + mod(i, 5) + mod(j2, 5))
bij = (i + j2) // 10
cj = (1 + j2) // 10
s += aij * sin(bij + ci * x[i] + cj * x[j2])
end
end
end
return s / n
end
x0 = fill(one(T), n)
return ADNLPModels.ADNLPModel(f, x0, name = "toint"; kwargs...)
end