Skip to content

Commit b19acda

Browse files
committed
Format
1 parent 275924e commit b19acda

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

lib/OptimizationMOI/src/OptimizationMOI.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,16 +358,16 @@ function SciMLBase.__solve(prob::OptimizationProblem,
358358
end
359359
end
360360
end
361-
361+
362362
if prob.int !== nothing
363363
@assert eachindex(prob.int) == Base.OneTo(num_variables)
364364
for i in 1:num_variables
365-
if prob.int[i]
365+
if prob.int[i]
366366
MOI.add_constraint(opt_setup, θ[i], MOI.ZeroOne())
367367
end
368368
end
369-
end
370-
369+
end
370+
371371
if MOI.supports(opt_setup, MOI.VariablePrimalStart(), MOI.VariableIndex)
372372
@assert eachindex(prob.u0) == Base.OneTo(num_variables)
373373
for i in 1:num_variables

lib/OptimizationMOI/test/runtests.jl

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -95,27 +95,25 @@ end
9595
end
9696
end end
9797

98-
@testset "MINLP" begin
99-
v = [1.0, 2.0, 4.0, 3.0]
100-
w = [5.0, 4.0, 3.0, 2.0]
101-
W = 4.0
102-
u0 = [0.0, 0., 0., 1.0]
103-
104-
optfun = OptimizationFunction(
105-
(u, p)-> -v'u, cons = (res, u,p)-> res .= w'u, Optimization.AutoForwardDiff()
106-
)
107-
108-
109-
110-
optprob = OptimizationProblem(
111-
optfun, u0; lb = zero.(u0), ub = one.(u0), int = ones(Bool, length(u0)),
112-
lcons = [-Inf;], ucons = [W;]
113-
)
114-
115-
nl_solver = OptimizationMOI.MOI.OptimizerWithAttributes(Ipopt.Optimizer, "print_level"=>0)
116-
minlp_solver = OptimizationMOI.MOI.OptimizerWithAttributes(Juniper.Optimizer, "nl_solver"=> nl_solver)
117-
118-
res = solve(optprob, minlp_solver)
119-
@test res.u == [0., 0., 1., 0.]
120-
@test res.objective == -4.0
98+
@testset "MINLP" begin
99+
v = [1.0, 2.0, 4.0, 3.0]
100+
w = [5.0, 4.0, 3.0, 2.0]
101+
W = 4.0
102+
u0 = [0.0, 0.0, 0.0, 1.0]
103+
104+
optfun = OptimizationFunction((u, p) -> -v'u, cons = (res, u, p) -> res .= w'u,
105+
Optimization.AutoForwardDiff())
106+
107+
optprob = OptimizationProblem(optfun, u0; lb = zero.(u0), ub = one.(u0),
108+
int = ones(Bool, length(u0)),
109+
lcons = [-Inf;], ucons = [W;])
110+
111+
nl_solver = OptimizationMOI.MOI.OptimizerWithAttributes(Ipopt.Optimizer,
112+
"print_level" => 0)
113+
minlp_solver = OptimizationMOI.MOI.OptimizerWithAttributes(Juniper.Optimizer,
114+
"nl_solver" => nl_solver)
115+
116+
res = solve(optprob, minlp_solver)
117+
@test res.u == [0.0, 0.0, 1.0, 0.0]
118+
@test res.objective == -4.0
121119
end

0 commit comments

Comments
 (0)