Skip to content

Commit 07826ee

Browse files
committed
Add tests with operator
1 parent 20b7294 commit 07826ee

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

test/nlp_problems/operatorspb.jl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
function operatorspb()
2+
nlp = Model()
3+
x0 = [390, 1000, 419.5, 340.5, 198.175, 0.5]
4+
lvar = [0, 0, 340, 340, -1000, 0]
5+
uvar = [400, 1000, 420, 420, 10000, 0.5236]
6+
@variable(nlp, lvar[i] <= x[i = 1:6] <= uvar[i], start = x0[i])
7+
8+
a = 131078 // 1000
9+
b = 148577 // 100000
10+
ci = 90798 // 100000
11+
d = cos(147588 // 100000)
12+
e = sin(147588 // 100000)
13+
14+
@constraint(nlp, 300 - x[1] - 1 / a * x[3] * x[4] * cos(b - x[6]) + ci / a * d * x[3] == 0)
15+
@constraint(nlp, -x[2] - 1 / a * x[3] * x[4] * cos(b + x[6]) + ci / a * d * x[4]^2 == 0)
16+
@constraint(nlp, -x[5] - 1 / a * x[3] * x[4] * cos(b + x[6]) + ci / a * e * x[4]^2 == 0)
17+
@constraint(nlp, 200 - 1 / a * x[3] * x[4] * sin(b - x[6]) + ci / a * e * x[3]^2 == 0)
18+
19+
function f1(t)
20+
return if 0 <= t <= 300
21+
30 * t
22+
elseif 300 <= t <= 400
23+
31 * t
24+
else
25+
eltype(x)(Inf)
26+
end
27+
end
28+
29+
function f2(t)
30+
return if 0 <= t <= 100
31+
28 * t
32+
elseif 100 <= t <= 200
33+
29 * t
34+
elseif 200 <= t <= 1000
35+
30 * t
36+
else
37+
eltype(t)(Inf)
38+
end
39+
end
40+
@operator(nlp, op_f1, 1, f1)
41+
@expression(nlp, op_f1)
42+
@operator(nlp, op_f2, 1, f2)
43+
@expression(nlp, op_f2)
44+
@objective(nlp, Min, op_f1(x[1]) + op_f2(x[2]))
45+
46+
return nlp
47+
end

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using Test, Printf
55
nlp_problems = setdiff(NLPModelsTest.nlp_problems, ["MGH01Feas"])
66
nls_problems = NLPModelsTest.nls_problems
77

8-
extra_nlp_problems = ["nohesspb", "hs61", "hs100", "hs219", "quadcon"]
8+
extra_nlp_problems = ["nohesspb", "hs61", "hs100", "hs219", "quadcon", "operatorspb"]
99
extra_nls_problems = ["nlsnohesspb", "HS30", "HS43", "MGH07", "nlsqc"]
1010

1111
for problem in lowercase.(nlp_problems extra_nlp_problems)

0 commit comments

Comments
 (0)