-
Notifications
You must be signed in to change notification settings - Fork 6
/
006_010.jl
45 lines (37 loc) · 1.16 KB
/
006_010.jl
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
41
42
43
44
45
# Copyright (c) 2021 MINLPTests.jl contributors
#
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
function nlp_mi_expr_006_010(
optimizer,
objective_tol,
primal_tol,
dual_tol,
termination_target = TERMINATION_TARGET_LOCAL,
primal_target = PRIMAL_TARGET_LOCAL,
)
# Test Goals:
# - user defined functions
model = Model(optimizer)
function user_function_1d(x)
if x >= 0
return max(0.25, exp(x) - 1)
else
return log(-x + 3)
end
end
@operator(model, f_1d, 1, user_function_1d)
function user_function_2d(x, y)
return x^2 + y^3
end
@operator(model, f_2d, 2, user_function_2d)
@variable(model, x)
@variable(model, y, Bin)
@objective(model, Max, y + x)
@constraint(model, y >= f_1d(x))
@constraint(model, f_2d(x, y) <= 2)
optimize!(model)
check_status(model, FEASIBLE_PROBLEM, termination_target, primal_target)
check_objective(model, 1 + log(2), tol = objective_tol)
return check_solution([x, y], [log(2), 1.0], tol = primal_tol)
end