Skip to content

Commit 2968284

Browse files
committed
removing unnecessary variables
1 parent eb71f89 commit 2968284

File tree

4 files changed

+20
-27
lines changed

4 files changed

+20
-27
lines changed

src/ADNLPProblems/toint.jl

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,27 @@ export toint
33
function toint(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
44
function f(x; n = length(x))
55
s = zero(T)
6-
for i = 1:n_local
7-
xi = x[i]
6+
for i = 1:n
87
ci = 1 + (i / 10)
98

10-
jlo = max(1, i - 2)
11-
jhi = min(n_local, i + 2)
12-
for j = jlo:jhi
9+
for j = max(1, i - 2):min(n, i + 2)
1310
aij = 5 * (1 + mod(i, 5) + mod(j, 5))
1411
bij = (i + j) / 10
1512
cj = (1 + j) / 10
1613
s += aij * sin(bij + ci * xi + cj * x[j])
1714
end
1815

19-
if iseven(n_local)
20-
j = i + (n_local ÷ 2)
21-
if 1 <= j <= n_local
16+
if iseven(n)
17+
j = i + (n ÷ 2)
18+
if 1 <= j <= n
2219
aij = 5 * (1 + mod(i, 5) + mod(j, 5))
2320
bij = (i + j) / 10
2421
cj = (1 + j) / 10
2522
s += aij * sin(bij + ci * xi + cj * x[j])
2623
end
2724
end
2825
end
29-
return s / T(n_local)
26+
return s / n
3027
end
3128

3229
x0 = fill(one(T), n)

src/ADNLPProblems/trig.jl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,23 @@ export trig
33
function trig(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
44
function f(x; n = length(x))
55
s = zero(T)
6-
for i = 1:n_local
7-
term = i * (1 - cos(xi))
6+
for i = 1:n
7+
s += i * (1 - cos(x[i]))
88

99
for j = max(1, i - 2):min(n, i + 2)
1010
aij = 5 * (1 + mod(i, 5) + mod(j, 5))
1111
bij = (i + j) / 10
12-
term += aij * sin(x[j]) + bij * cos(x[j])
12+
s += aij * sin(x[j]) + bij * cos(x[j])
1313
end
1414

15-
if iseven(n_local)
16-
j = i + (n_local ÷ 2)
17-
if 1 <= j <= n_local
15+
if iseven(n)
16+
j = i + (n ÷ 2)
17+
if 1 <= j <= n
1818
aij = 5 * (1 + mod(i, 5) + mod(j, 5))
1919
bij = (i + j) / 10
20-
term += aij * sin(x[j]) + bij * cos(x[j])
20+
s += aij * sin(x[j]) + bij * cos(x[j])
2121
end
2222
end
23-
24-
s += term
2523
end
2624
return s / n
2725
end

src/ADNLPProblems/trigb.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ export trigb
33
function trigb(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
44
function f(x; n = length(x))
55
s = zero(T)
6-
for i = 1:n_local
6+
for i = 1:n
77
xim = (i == 1) ? zero(T) : x[i - 1]
8-
xip = (i == n_local) ? zero(T) : x[i + 1]
9-
term = i * (1 - cos(xi) + sin(left) - sin(right))
10-
s += term
8+
xip = (i == n) ? zero(T) : x[i + 1]
9+
s += i * (1 - cos(x[i]) + sin(xim) - sin(xip))
1110
end
1211
return s
1312
end

src/PureJuMP/trigb.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@ export trigb
1313

1414
function trigb(args...; n::Int = default_nvar, kwargs...)
1515
model = Model()
16-
@variable(model, x[i = 1:n], start = 1.0)
16+
@variable(model, x[i = 1:n], start = 1)
1717

1818
@objective(
1919
model,
2020
Min,
2121
sum(
22-
i * (
23-
(1 - cos(x[i])) + ((i == 1) ? sin(0) : sin(x[i - 1])) -
24-
((i == n) ? sin(0) : sin(x[i + 1]))
25-
) for i = 1:n
22+
i *
23+
((1 - cos(x[i])) + ((i == 1) ? sin(0) : sin(x[i - 1])) - ((i == n) ? sin(0) : sin(x[i + 1])))
24+
for i = 1:n
2625
)
2726
)
2827

0 commit comments

Comments
 (0)