diff --git a/src/algorithm.jl b/src/algorithm.jl index 0cb30270..acd77c54 100644 --- a/src/algorithm.jl +++ b/src/algorithm.jl @@ -191,7 +191,7 @@ function set_variable_type(model::MOI.ModelLike, xs, variable_types) fx = MOI.SingleVariable(x) if variable_type == :Int MOI.add_constraint(model, fx, MOI.Integer()) - elseif variable_type == :Bool + elseif variable_type == :Bin MOI.add_constraint(model, fx, MOI.ZeroOne()) else @assert variable_type == :Cont diff --git a/src/amp.jl b/src/amp.jl index c0a354a6..935dc6db 100644 --- a/src/amp.jl +++ b/src/amp.jl @@ -429,15 +429,15 @@ function disc_branch_solve(m::Optimizer) # ================= Solve Start ================ # set_mip_time_limit(m) start_bounding_solve = time() - MOI.optimize!(m.model_mip) + JuMP.optimize!(m.model_mip) status = MOI.get(m.model_mip, MOI.TerminationStatus()) cputime_branch_bounding_solve = time() - start_bounding_solve m.logs[:total_time] += cputime_branch_bounding_solve m.logs[:time_left] = max(0.0, get_option(m, :timeout) - m.logs[:total_time]) # ================= Solve End ================ # - if status in [:Optimal, :Suboptimal, :UserLimit] - return m.model_mip.objBound + if status in STATUS_OPT || status in STATUS_LIMIT + return MOI.get(m.model_mip, MOI.ObjectiveBound()) else @warn " Warning: Unexpected solving condition $(status) during disc branching." end diff --git a/src/solver.jl b/src/solver.jl index e09c87ec..1d50fa23 100644 --- a/src/solver.jl +++ b/src/solver.jl @@ -450,7 +450,6 @@ function MOI.set(model::Optimizer, ::MOI.ObjectiveSense, sense) else error("Feasibility sense not supported yet by Alpine.") end - @show model.best_bound end function MOI.set(model::Optimizer, ::MOI.ObjectiveFunction{F}, func::F) where F diff --git a/src/utility.jl b/src/utility.jl index a8c41789..fb483f94 100644 --- a/src/utility.jl +++ b/src/utility.jl @@ -631,9 +631,9 @@ function weighted_min_vertex_cover(m::Optimizer, distance::Dict) @objective(minvertex, Min, sum(weights[i]*x[i] for i in nodes)) # Solve the minimum vertex cover - status = solve(minvertex, suppress_warnings=true) + JuMP.optimize!(minvertex) - xVal = getvalue(x) + xVal = JuMP.value.(x) m.num_var_disc_mip = Int(sum(xVal)) m.disc_vars = [i for i in nodes if xVal[i] > 0 && abs(m.u_var_tight[i]-m.l_var_tight[i]) >= get_option(m, :tol)] get_option(m, :loglevel) >= 99 && println("UPDATED DISC-VAR COUNT = $(length(m.disc_vars)) : $(m.disc_vars)") diff --git a/test/algorithm.jl b/test/algorithm.jl index ca6b1a5a..fde182a3 100644 --- a/test/algorithm.jl +++ b/test/algorithm.jl @@ -667,7 +667,7 @@ end "maxiter" => 1, "presolve_bt" => false, "loglevel" => 100) - m = convex_optimize!(solver=test_solver) + m = convex_solve(solver=test_solver) JuMP.optimize!(m) @test termination_status(m) == MOI.OPTIMAL end diff --git a/test/expression.jl b/test/expression.jl index 008da52f..a66e20b6 100644 --- a/test/expression.jl +++ b/test/expression.jl @@ -1,11 +1,3 @@ -function _build(model::JuMP.Model) - MOI.set(model, MOI.NLPBlock(), JuMP._create_nlp_block_data(model)) - MOI.Utilities.attach_optimizer(model) - alpine = JuMP.backend(model).optimizer.model - Alpine.load!(alpine) - return alpine -end - @testset "Expression Parsing || bilinear || Affine || exprs.jl" begin test_solver = optimizer_with_attributes(Alpine.Optimizer,"nlp_solver" => IPOPT_SB,"mip_solver" => CBC,"loglevel" => 100) diff --git a/test/runtests.jl b/test/runtests.jl index 995c7043..754e7d5f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -26,12 +26,16 @@ const CBC = optimizer_with_attributes(Cbc.Optimizer, MOI.Silent() => true) const JUNIPER = optimizer_with_attributes(Juniper.Optimizer, MOI.Silent() => true, "mip_solver" => CBC, "nl_solver" => IPOPT_SB) const PAVITO = optimizer_with_attributes(Pavito.Optimizer, "mip_solver" => CBC, "cont_solver" => IPOPT_SB, "mip_solver_drives" => false) - - -#pavito_solver=PavitoSolver(mip_solver=CbcSolver(logLevel=0), cont_solver=IpoptSolver(print_level=0, sb="yes"), mip_solver_drives=false, log_level=0) +function _build(model::JuMP.Model) + MOI.set(model, MOI.NLPBlock(), JuMP._create_nlp_block_data(model)) + MOI.Utilities.attach_optimizer(model) + alpine = JuMP.backend(model).optimizer.model + Alpine.load!(alpine) + return alpine +end # Perform Tests -#include("$(alpine_dir)/test/solver.jl") +include("$(alpine_dir)/test/solver.jl") include("$(alpine_dir)/test/expression.jl") include("$(alpine_dir)/test/algorithm.jl") -#include("$(alpine_dir)/test/utility.jl") +include("$(alpine_dir)/test/utility.jl") diff --git a/test/solver.jl b/test/solver.jl index 10991396..fbbb496d 100644 --- a/test/solver.jl +++ b/test/solver.jl @@ -1,22 +1,20 @@ -#= @testset "Optimizer loading tests" begin # Random Model 1 - test_solver = () -> Alpine.Optimizer(nlp_solver=IpoptSolver(),mip_solver=CbcSolver(logLevel=0),loglevel=100) + test_solver = optimizer_with_attributes(Alpine.Optimizer, "nlp_solver" => IPOPT, + "mip_solver" => CBC, + "loglevel" => 100) m = operator_c(solver = test_solver) - status = JuMP.build(m) - @test isa(m.internalModel, Alpine.Optimizer) + alpine = _build(m) + @test isa(alpine, Alpine.Optimizer) # Expression Model 1 - test_solver = Alpine.Optimizer(nlp_solver=IpoptSolver(),mip_solver=CbcSolver(logLevel=0),loglevel=100) m = exprstest(solver=test_solver) - status = JuMP.build(m) - @test isa(m.internalModel, Alpine.Optimizer) + alpine = _build(m) + @test isa(alpine, Alpine.Optimizer) end -=# @testset "Partitioning variable selection tests :: nlp3" begin -#= # Select all NL variable test_solver = optimizer_with_attributes(Alpine.Optimizer, "nlp_solver" => IPOPT, @@ -28,259 +26,255 @@ end "maxiter" => 1, "loglevel" => 100) m = nlp3(solver=test_solver) + JuMP.optimize!(m) + alpine = JuMP.backend(m).optimizer.model - MOI.Utilities.attach_optimizer(m) - MOI.set(m, MOI.NLPBlock(), JuMP._create_nlp_block_data(m)) + @test JuMP.termination_status(m) == MOI.OTHER_LIMIT + @test isapprox(JuMP.objective_value(m), 7049.2478976; atol=1e-3) + @test length(alpine.candidate_disc_vars) == 8 + @test length(alpine.disc_vars) == 8 + @test MOI.get(m, MOI.RawParameter("disc_var_pick")) == 0 - alpine = JuMP.backend(m).optimizer.model - Alpine.load!(alpine) - #= - status = MOI.optimize!(m) - - @test status == :UserLimits - @test isapprox(m.objVal, 7049.2478976; atol=1e-3) - @test length(m.internalModel.candidate_disc_vars) == 8 - @test length(m.internalModel.disc_vars) == 8 - @test m.internalModel.disc_var_pick == 0 - - =# -# -#= # Select all NL variable - test_solver = Alpine.Optimizer(nlp_solver=IpoptSolver(print_level=0), - mip_solver=CbcSolver(logLevel=0), - disc_var_pick=2, - disc_uniform_rate=10, - presolve_bp = false, - presolve_bt = false, - maxiter=1, - loglevel=100) + test_solver = optimizer_with_attributes(Alpine.Optimizer, "nlp_solver" => IPOPT, + "mip_solver" => CBC, + "disc_var_pick" => 2, + "disc_uniform_rate" => 10, + "presolve_bp" => false, + "presolve_bt" => false, + "maxiter" => 1, + "loglevel" => 100) m = nlp3(solver=test_solver) - status = solve(m) + JuMP.optimize!(m) + alpine = JuMP.backend(m).optimizer.model - @test status == :UserLimits - @test isapprox(m.objVal, 7049.2478976; atol=1e-3) - @test length(m.internalModel.candidate_disc_vars) == 8 - @test length(m.internalModel.disc_vars) == 8 - @test m.internalModel.disc_var_pick == 2 + @test JuMP.termination_status(m) == MOI.OTHER_LIMIT + @test isapprox(JuMP.objective_value(m), 7049.2478976; atol=1e-3) + @test length(alpine.candidate_disc_vars) == 8 + @test length(alpine.disc_vars) == 8 + @test MOI.get(m, MOI.RawParameter("disc_var_pick")) == 2 # Minimum vertex cover algorithm - test_solver = Alpine.Optimizer(nlp_solver=IpoptSolver(print_level=0), - mip_solver=CbcSolver(logLevel=0), - disc_var_pick=1, - disc_uniform_rate=10, - presolve_bp = false, - presolve_bt = false, - maxiter=1, - loglevel=100) + test_solver = optimizer_with_attributes(Alpine.Optimizer, "nlp_solver" => IPOPT, + "mip_solver" => CBC, + "disc_var_pick" => 1, + "disc_uniform_rate" => 10, + "presolve_bp" => false, + "presolve_bt" => false, + "maxiter" => 1, + "loglevel" => 100) m = nlp3(solver=test_solver) - status = solve(m) + JuMP.optimize!(m) + alpine = JuMP.backend(m).optimizer.model - @test status == :UserLimits - @test isapprox(m.objVal, 7049.2478976; atol=1e-3) - @test length(m.internalModel.candidate_disc_vars) == 8 - @test length(m.internalModel.disc_vars) == 3 - @test m.internalModel.disc_var_pick == 1 + @test JuMP.termination_status(m) == MOI.OTHER_LIMIT + @test isapprox(JuMP.objective_value(m), 7049.2478976; atol=1e-3) + @test length(alpine.candidate_disc_vars) == 8 + @test length(alpine.disc_vars) == 3 + @test MOI.get(m, MOI.RawParameter("disc_var_pick")) == 1 # Adaptive variable selection scheme :: disc_var_pick = 3 - test_solver = Alpine.Optimizer(nlp_solver=IpoptSolver(print_level=0), - mip_solver=CbcSolver(logLevel=0), - disc_var_pick=3, - presolve_bp = false, - presolve_bt = false, - maxiter=2, - loglevel=100) + test_solver = optimizer_with_attributes(Alpine.Optimizer, "nlp_solver" => IPOPT, + "mip_solver" => CBC, + "disc_var_pick" => 3, + "presolve_bp" => false, + "presolve_bt" => false, + "maxiter" => 2, + "loglevel" => 100) m = nlp3(solver=test_solver) - status = solve(m) - - @test status == :UserLimits - @test isapprox(m.objVal, 7049.2478976; atol=1e-3) - @test length(m.internalModel.candidate_disc_vars) == 8 - @test length(m.internalModel.disc_vars) == 8 - @test m.internalModel.disc_var_pick == 3 -=# + JuMP.optimize!(m) + alpine = JuMP.backend(m).optimizer.model + + @test JuMP.termination_status(m) == MOI.OTHER_LIMIT + @test isapprox(JuMP.objective_value(m), 7049.2478976; atol=1e-3) + @test length(alpine.candidate_disc_vars) == 8 + @test length(alpine.disc_vars) == 8 + @test MOI.get(m, MOI.RawParameter("disc_var_pick")) == 3 end -#= @testset "Partitioning variable selection tests :: castro2m2" begin # Select all NL variable - test_solver = Alpine.Optimizer(nlp_solver=IpoptSolver(print_level=0), - mip_solver=CbcSolver(logLevel=0), - disc_var_pick=0, - disc_uniform_rate=10, - presolve_bp=false, - presolve_bt=false, - maxiter=1, - loglevel=100) + test_solver = optimizer_with_attributes(Alpine.Optimizer, "nlp_solver" => IPOPT, + "mip_solver" => CBC, + "disc_var_pick" => 0, + "disc_uniform_rate" => 10, + "presolve_bp" => false, + "presolve_bt" => false, + "maxiter" => 1, + "loglevel" => 100) m = castro2m2(solver=test_solver) - status = solve(m) + JuMP.optimize!(m) + alpine = JuMP.backend(m).optimizer.model - @test status == :UserLimits - @test m.objVal <= 470.3176 + @test JuMP.termination_status(m) == MOI.OTHER_LIMIT + @test JuMP.objective_value(m) <= 470.3176 - @test length(m.internalModel.candidate_disc_vars) == 10 - @test length(m.internalModel.disc_vars) == 10 - @test m.internalModel.disc_var_pick == 0 + @test length(alpine.candidate_disc_vars) == 10 + @test length(alpine.disc_vars) == 10 + @test MOI.get(m, MOI.RawParameter("disc_var_pick")) == 0 # Select minimum vertex cover - test_solver = Alpine.Optimizer(nlp_solver=IpoptSolver(print_level=0), - mip_solver=CbcSolver(logLevel=0), - disc_var_pick=1, - disc_uniform_rate=10, - presolve_bp=false, - presolve_bt=false, - maxiter=1, - loglevel=100) + test_solver = optimizer_with_attributes(Alpine.Optimizer, "nlp_solver" => IPOPT, + "mip_solver" => CBC, + "disc_var_pick" => 1, + "disc_uniform_rate" => 10, + "presolve_bp" => false, + "presolve_bt" => false, + "maxiter" => 1, + "loglevel" => 100) m = castro2m2(solver=test_solver) - status = solve(m) + JuMP.optimize!(m) + alpine = JuMP.backend(m).optimizer.model - @test status == :UserLimits - @test m.objVal <= 470.3176 - @test length(m.internalModel.candidate_disc_vars) == 10 - @test length(m.internalModel.disc_vars) == 4 - @test m.internalModel.disc_var_pick == 1 + @test JuMP.termination_status(m) == MOI.OTHER_LIMIT + @test JuMP.objective_value(m) <= 470.3176 + @test length(alpine.candidate_disc_vars) == 10 + @test length(alpine.disc_vars) == 4 + @test MOI.get(m, MOI.RawParameter("disc_var_pick")) == 1 # Criteria 15 static selection - test_solver = Alpine.Optimizer(nlp_solver=IpoptSolver(print_level=0), - mip_solver=CbcSolver(logLevel=0), - disc_var_pick=2, - disc_uniform_rate=15, - presolve_bp=false, - presolve_bt=false, - maxiter=1, - loglevel=100) + test_solver = optimizer_with_attributes(Alpine.Optimizer, "nlp_solver" => IPOPT, + "mip_solver" => CBC, + "disc_var_pick" => 2, + "disc_uniform_rate" => 15, + "presolve_bp" => false, + "presolve_bt" => false, + "maxiter" => 1, + "loglevel" => 100) m = castro2m2(solver=test_solver) - status = solve(m) + JuMP.optimize!(m) + alpine = JuMP.backend(m).optimizer.model - @test status == :UserLimits - @test m.objVal <= 470.3176 + @test JuMP.termination_status(m) == MOI.OTHER_LIMIT + @test JuMP.objective_value(m) <= 470.3176 - @test length(m.internalModel.candidate_disc_vars) == 10 - @test length(m.internalModel.disc_vars) == 10 - @test m.internalModel.disc_var_pick == 2 + @test length(alpine.candidate_disc_vars) == 10 + @test length(alpine.disc_vars) == 10 + @test MOI.get(m, MOI.RawParameter("disc_var_pick")) == 2 end @testset "Partitioning variable selection tests :: blend029" begin # Select all NL variable - test_solver = Alpine.Optimizer(minlp_solver=pavito_solver, - nlp_solver=IpoptSolver(print_level=0), - mip_solver=CbcSolver(logLevel=0), - disc_var_pick=0, - disc_uniform_rate=10, - presolve_bt=false, - maxiter=1, - loglevel=100) + test_solver = optimizer_with_attributes(Alpine.Optimizer, "minlp_solver" => PAVITO, + "nlp_solver" => IPOPT, + "mip_solver" => CBC, + "disc_var_pick" => 0, + "disc_uniform_rate" => 10, + "presolve_bt" => false, + "maxiter" => 1, + "loglevel" => 100) m = blend029_gl(solver=test_solver) - JuMP.build(m) + alpine = _build(m) - @test length(m.internalModel.candidate_disc_vars) == 26 - @test Set(m.internalModel.candidate_disc_vars) == Set([26, 27, 29, 30, 32, 33, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 55, 56, 57, 58, 59, 60]) - @test length(m.internalModel.disc_vars) == 26 - @test m.internalModel.disc_var_pick == 0 + @test length(alpine.candidate_disc_vars) == 26 + @test Set(alpine.candidate_disc_vars) == Set([26, 27, 29, 30, 32, 33, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 55, 56, 57, 58, 59, 60]) + @test length(alpine.disc_vars) == 26 + @test MOI.get(m, MOI.RawParameter("disc_var_pick")) == 0 # Minimum vertex cover - test_solver = Alpine.Optimizer(minlp_solver=pavito_solver, - nlp_solver=IpoptSolver(print_level=0), - mip_solver=CbcSolver(logLevel=0), - disc_var_pick=1, - disc_uniform_rate=10, - presolve_bp=false, - presolve_bt=false, - maxiter=1, - loglevel=100) + test_solver = optimizer_with_attributes(Alpine.Optimizer, "minlp_solver" => PAVITO, + "nlp_solver" => IPOPT, + "mip_solver" => CBC, + "disc_var_pick" => 1, + "disc_uniform_rate" => 10, + "presolve_bp" => false, + "presolve_bt" => false, + "maxiter" => 1, + "loglevel" => 100) m = blend029_gl(solver=test_solver) - JuMP.build(m) + alpine = _build(m) - @test length(m.internalModel.candidate_disc_vars) == 26 - @test Set(m.internalModel.candidate_disc_vars) == Set([26, 27, 29, 30, 32, 33, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 55, 56, 57, 58, 59, 60]) - @test length(m.internalModel.disc_vars) == 10 - @test m.internalModel.disc_var_pick == 1 + @test length(alpine.candidate_disc_vars) == 26 + @test Set(alpine.candidate_disc_vars) == Set([26, 27, 29, 30, 32, 33, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 55, 56, 57, 58, 59, 60]) + @test length(alpine.disc_vars) == 10 + @test MOI.get(m, MOI.RawParameter("disc_var_pick")) == 1 # Adaptive Scheme vertex cover - test_solver = Alpine.Optimizer(minlp_solver=pavito_solver, - nlp_solver=IpoptSolver(print_level=0), - mip_solver=CbcSolver(logLevel=0), - disc_var_pick=2, - disc_uniform_rate=10, - presolve_bp=false, - presolve_bt=false, - maxiter=1, - loglevel=100) + test_solver = optimizer_with_attributes(Alpine.Optimizer, "minlp_solver" => PAVITO, + "nlp_solver" => IPOPT, + "mip_solver" => CBC, + "disc_var_pick" => 2, + "disc_uniform_rate" => 10, + "presolve_bp" => false, + "presolve_bt" => false, + "maxiter" => 1, + "loglevel" => 100) m = blend029_gl(solver=test_solver) - JuMP.build(m) + alpine = _build(m) - @test length(m.internalModel.candidate_disc_vars) == 26 - @test length(Set(m.internalModel.candidate_disc_vars)) == 26 + @test length(alpine.candidate_disc_vars) == 26 + @test length(Set(alpine.candidate_disc_vars)) == 26 # TODO provide a check to see if candidate_disc_vars are all covered - @test length(m.internalModel.disc_vars) == 10 - @test m.internalModel.disc_var_pick == 2 + @test length(alpine.disc_vars) == 10 + @test MOI.get(m, MOI.RawParameter("disc_var_pick")) == 2 end @testset "Partitioning variable selection tests :: castro6m2" begin # Dynamic Scheme step 2 - test_solver = Alpine.Optimizer(nlp_solver=IpoptSolver(print_level=0), - mip_solver=CbcSolver(logLevel=0), - disc_var_pick=3, - presolve_bp=true, - presolve_bt=false, - maxiter=1, - loglevel=100) + test_solver = optimizer_with_attributes(Alpine.Optimizer, "nlp_solver" => IPOPT, + "mip_solver" => CBC, + "disc_var_pick" => 3, + "presolve_bp" => true, + "presolve_bt" => false, + "maxiter" => 1, + "loglevel" => 100) m = castro6m2(solver=test_solver) - status = solve(m) + JuMP.optimize!(m) + alpine = JuMP.backend(m).optimizer.model - @test status == :UserLimits - @test m.objVal <= 228.87 + @test JuMP.termination_status(m) == MOI.OTHER_LIMIT + @test JuMP.objective_value(m) <= 228.87 - @test length(m.internalModel.candidate_disc_vars) == 24 - @test length(Set(m.internalModel.candidate_disc_vars)) == 24 - @test length(m.internalModel.disc_vars) == 12 - @test length(Set(m.internalModel.disc_vars)) == 12 - @test m.internalModel.disc_var_pick == 3 + @test length(alpine.candidate_disc_vars) == 24 + @test length(Set(alpine.candidate_disc_vars)) == 24 + @test length(alpine.disc_vars) == 12 + @test length(Set(alpine.disc_vars)) == 12 + @test MOI.get(m, MOI.RawParameter("disc_var_pick")) == 3 # Dynamic Scheme step 2 - test_solver = Alpine.Optimizer(nlp_solver=IpoptSolver(print_level=0), - mip_solver=CbcSolver(logLevel=0), - disc_var_pick=3, - presolve_bp=true, - presolve_bt=false, - maxiter=2, - loglevel=100) + test_solver = optimizer_with_attributes(Alpine.Optimizer, "nlp_solver" => IPOPT, + "mip_solver" => CBC, + "disc_var_pick" => 3, + "presolve_bp" => true, + "presolve_bt" => false, + "maxiter" => 2, + "loglevel" => 100) m = castro6m2(solver=test_solver) - status = solve(m) + JuMP.optimize!(m) + alpine = JuMP.backend(m).optimizer.model - @test status == :UserLimits - @test m.objVal <= 228.7810 + @test JuMP.termination_status(m) == MOI.OTHER_LIMIT + @test JuMP.objective_value(m) <= 228.7810 - @test length(m.internalModel.candidate_disc_vars) == 24 - @test length(Set(m.internalModel.candidate_disc_vars)) == 24 - @test length(m.internalModel.disc_vars) == 12 - @test length(Set(m.internalModel.disc_vars)) == 12 - @test m.internalModel.disc_var_pick == 3 + @test length(alpine.candidate_disc_vars) == 24 + @test length(Set(alpine.candidate_disc_vars)) == 24 + @test length(alpine.disc_vars) == 12 + @test length(Set(alpine.disc_vars)) == 12 + @test MOI.get(m, MOI.RawParameter("disc_var_pick")) == 3 end @testset "Test getsolvetime for time tracking" begin - test_solver = Alpine.Optimizer(nlp_solver=IpoptSolver(print_level=0), - mip_solver=CbcSolver(logLevel=0), - disc_var_pick=0, - disc_uniform_rate=10, - presolve_bp=false, - presolve_bt=false, - maxiter=1, - loglevel=100) + test_solver = optimizer_with_attributes(Alpine.Optimizer, "nlp_solver" => IPOPT, + "mip_solver" => CBC, + "disc_var_pick" => 0, + "disc_uniform_rate" => 10, + "presolve_bp" => false, + "presolve_bt" => false, + "maxiter" => 1, + "loglevel" => 100) m = castro2m2(solver=test_solver) - status = solve(m) - @test getsolvetime(m) > 0. + JuMP.optimize!(m) + @test solve_time(m) > 0.0 end -=# diff --git a/test/utility.jl b/test/utility.jl index b5a79f55..ed5aeb9f 100644 --- a/test/utility.jl +++ b/test/utility.jl @@ -1,47 +1,48 @@ @testset "Utility Function Tests: Solver identifier fetch" begin - test_solver=Alpine.Optimizer(minlp_solver=pavito_solver, - nlp_solver=IpoptSolver(print_level=0), - mip_solver=CbcSolver(logLevel=0), - presolve_bp=true, - disc_var_pick=1, - loglevel=100, - maxiter=2, - presolve_bt_width_tol=1e-3, - presolve_bt=false) + test_solver=optimizer_with_attributes(Alpine.Optimizer, "minlp_solver" => PAVITO, + "nlp_solver" => IPOPT, + "mip_solver" => CBC, + "presolve_bp" => true, + "disc_var_pick" => 1, + "loglevel" => 100, + "maxiter" => 2, + "presolve_bt_width_tol" => 1e-3, + "presolve_bt" => false) m = blend029_gl(solver=test_solver) - status = solve(m) + JuMP.optimize!(m) + alpine = JuMP.backend(m).optimizer.model - @test status == :UserLimits - @test m.internalModel.logs[:n_iter] == 2 + @test termination_status(m) == MOI.OTHER_LIMIT + @test alpine.logs[:n_iter] == 2 - Alpine.fetch_mip_solver_identifier(m.internalModel;override="Pajarito.PajaritoSolver(0, Inf, 1.0e-5, false, Cbc.CbcMathProgSolverInterface.CbcSolver(Any[(:logLevel, 0)]), Pajarito.UnsetSolver(), 0, false, true, Ipopt.IpoptSolver(Any[(:print_level, 0)]), true, true, false, false, true, false, false, true, false, true, true, true, true, false, true, 2.0, false, false, false, true, 1.0e-12, 1.0e-6, false, \"\")") - @test m.internalModel.mip_solver_id == "Pajarito" - Alpine.fetch_mip_solver_identifier(m.internalModel;override="Gurobi.GurobiSolver(nothing, Any[])") - @test m.internalModel.mip_solver_id == "Gurobi" - Alpine.fetch_mip_solver_identifier(m.internalModel;override="CPLEX.CplexSolver(Any[])") - @test m.internalModel.mip_solver_id == "Cplex" - Alpine.fetch_mip_solver_identifier(m.internalModel;override="Cbc.CbcMathProgSolverInterface.CbcSolver(Any[])") - @test m.internalModel.mip_solver_id == "Cbc" - Alpine.fetch_mip_solver_identifier(m.internalModel;override="GLPKMathProgInterface.GLPKInterfaceMIP.GLPKSolverMIP(false, Any[])") - @test m.internalModel.mip_solver_id == "GLPK" + Alpine.fetch_mip_solver_identifier(alpine;override="Pajarito.PajaritoSolver(0, Inf, 1.0e-5, false, Cbc.CbcMathProgSolverInterface.CbcSolver(Any[(:logLevel, 0)]), Pajarito.UnsetSolver(), 0, false, true, Ipopt.IpoptSolver(Any[(:print_level, 0)]), true, true, false, false, true, false, false, true, false, true, true, true, true, false, true, 2.0, false, false, false, true, 1.0e-12, 1.0e-6, false, \"\")") + @test alpine.mip_solver_id == "Pajarito" + Alpine.fetch_mip_solver_identifier(alpine;override="Gurobi.GurobiSolver(nothing, Any[])") + @test alpine.mip_solver_id == "Gurobi" + Alpine.fetch_mip_solver_identifier(alpine;override="CPLEX.CplexSolver(Any[])") + @test alpine.mip_solver_id == "Cplex" + Alpine.fetch_mip_solver_identifier(alpine;override="Cbc.CbcMathProgSolverInterface.CbcSolver(Any[])") + @test alpine.mip_solver_id == "Cbc" + Alpine.fetch_mip_solver_identifier(alpine;override="GLPKMathProgInterface.GLPKInterfaceMIP.GLPKSolverMIP(false, Any[])") + @test alpine.mip_solver_id == "GLPK" - Alpine.fetch_nlp_solver_identifier(m.internalModel;override="Pajarito.PajaritoSolver(0, Inf, 1.0e-5, false, Cbc.CbcMathProgSolverInterface.CbcSolver(Any[(:logLevel, 0)]), Pajarito.UnsetSolver(), 0, false, true, Ipopt.IpoptSolver(Any[(:print_level, 0)]), true, true, false, false, true, false, false, true, false, true, true, true, true, false, true, 2.0, false, false, false, true, 1.0e-12, 1.0e-6, false, \"\")") - @test m.internalModel.nlp_solver_id == "Pajarito" - Alpine.fetch_nlp_solver_identifier(m.internalModel;override="Ipopt.IpoptSolver(Any[])") - @test m.internalModel.nlp_solver_id == "Ipopt" - Alpine.fetch_nlp_solver_identifier(m.internalModel;override="AmplNLWriter.AmplNLSolver(\"bonmin\", String[], \"\")") - @test m.internalModel.nlp_solver_id == "Bonmin" + Alpine.fetch_nlp_solver_identifier(alpine;override="Pajarito.PajaritoSolver(0, Inf, 1.0e-5, false, Cbc.CbcMathProgSolverInterface.CbcSolver(Any[(:logLevel, 0)]), Pajarito.UnsetSolver(), 0, false, true, Ipopt.IpoptSolver(Any[(:print_level, 0)]), true, true, false, false, true, false, false, true, false, true, true, true, true, false, true, 2.0, false, false, false, true, 1.0e-12, 1.0e-6, false, \"\")") + @test alpine.nlp_solver_id == "Pajarito" + Alpine.fetch_nlp_solver_identifier(alpine;override="Ipopt.IpoptSolver(Any[])") + @test alpine.nlp_solver_id == "Ipopt" + Alpine.fetch_nlp_solver_identifier(alpine;override="AmplNLWriter.AmplNLSolver(\"bonmin\", String[], \"\")") + @test alpine.nlp_solver_id == "Bonmin" @test "NLopt" == "NLopt" - Alpine.fetch_nlp_solver_identifier(m.internalModel;override="KNITRO.KnitroSolver(Any[])") - @test m.internalModel.nlp_solver_id == "Knitro" + Alpine.fetch_nlp_solver_identifier(alpine;override="KNITRO.KnitroSolver(Any[])") + @test alpine.nlp_solver_id == "Knitro" - Alpine.fetch_minlp_solver_identifier(m.internalModel;override="Pajarito.PajaritoSolver(0, Inf, 1.0e-5, false, Cbc.CbcMathProgSolverInterface.CbcSolver(Any[(:logLevel, 0)]), Pajarito.UnsetSolver(), 0, false, true, Ipopt.IpoptSolver(Any[(:print_level, 0)]), true, true, false, false, true, false, false, true, false, true, true, true, true, false, true, 2.0, false, false, false, true, 1.0e-12, 1.0e-6, false, \"\")") - @test m.internalModel.minlp_solver_id == "Pajarito" - Alpine.fetch_minlp_solver_identifier(m.internalModel;override="AmplNLWriter.AmplNLSolver(\"bonmin\", String[], \"\")") - @test m.internalModel.minlp_solver_id == "Bonmin" - Alpine.fetch_minlp_solver_identifier(m.internalModel;override="KNITRO.KnitroSolver(Any[])") - @test m.internalModel.minlp_solver_id == "Knitro" + Alpine.fetch_minlp_solver_identifier(alpine;override="Pajarito.PajaritoSolver(0, Inf, 1.0e-5, false, Cbc.CbcMathProgSolverInterface.CbcSolver(Any[(:logLevel, 0)]), Pajarito.UnsetSolver(), 0, false, true, Ipopt.IpoptSolver(Any[(:print_level, 0)]), true, true, false, false, true, false, false, true, false, true, true, true, true, false, true, 2.0, false, false, false, true, 1.0e-12, 1.0e-6, false, \"\")") + @test alpine.minlp_solver_id == "Pajarito" + Alpine.fetch_minlp_solver_identifier(alpine;override="AmplNLWriter.AmplNLSolver(\"bonmin\", String[], \"\")") + @test alpine.minlp_solver_id == "Bonmin" + Alpine.fetch_minlp_solver_identifier(alpine;override="KNITRO.KnitroSolver(Any[])") + @test alpine.minlp_solver_id == "Knitro" @test "NLopt" == "NLopt" end