Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamed82008 committed Nov 15, 2023
1 parent 7ecaa6a commit 764bc33
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
41 changes: 27 additions & 14 deletions src/NonconvexPavito.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ import NonconvexCore: optimize!, Workspace

@params struct PavitoIpoptCbcOptions
nt::NamedTuple
subsolver_options
subsolver_options::Any
first_order::Bool
end
function PavitoIpoptCbcOptions(;
first_order = true, subsolver_options = IpoptOptions(first_order = first_order), kwargs...,
first_order = true,
subsolver_options = IpoptOptions(first_order = first_order),
kwargs...,
)
first_order = !hasproperty(subsolver_options.nt, :hessian_approximation) ||
first_order =
!hasproperty(subsolver_options.nt, :hessian_approximation) ||
subsolver_options.nt.hessian_approximation == "limited-memory"
return PavitoIpoptCbcOptions((; kwargs...), subsolver_options, first_order)
end
Expand All @@ -32,8 +35,10 @@ end
counter::Base.RefValue{Int}
end
function PavitoIpoptCbcWorkspace(
model::VecModel, x0::AbstractVector = getinit(model);
options = PavitoIpoptCbcOptions(), kwargs...,
model::VecModel,
x0::AbstractVector = getinit(model);
options = PavitoIpoptCbcOptions(),
kwargs...,
)
integers = model.integer
@assert length(integers) == length(x0)
Expand All @@ -49,20 +54,24 @@ function PavitoIpoptCbcWorkspace(
end
optimizer = JuMP.optimizer_with_attributes(
Pavito.Optimizer,
"cont_solver" => nl_solver, Dict(solver_options)...,
"cont_solver" => nl_solver,
Dict(solver_options)...,
"mip_solver" => JuMP.optimizer_with_attributes(Cbc.Optimizer),
)
problem, counter = get_jump_problem(
model, copy(x0); first_order = options.first_order,
optimizer = optimizer, integers = integers,
model,
copy(x0);
first_order = options.first_order,
optimizer = optimizer,
integers = integers,
)
return PavitoIpoptCbcWorkspace(model, problem, copy(x0), integers, options, counter)
end
@params struct PavitoIpoptCbcResult <: AbstractResult
minimizer
minimum
problem
status
minimizer::Any
minimum::Any
problem::Any
status::Any
fcalls::Int
end

Expand All @@ -79,13 +88,17 @@ function optimize!(workspace::PavitoIpoptCbcWorkspace)
term_status = MOI.get(moi_model, MOI.TerminationStatus())
primal_status = MOI.get(moi_model, MOI.PrimalStatus())
return PavitoIpoptCbcResult(
minimizer, objval, problem, (term_status, primal_status), counter[],
minimizer,
objval,
problem,
(term_status, primal_status),
counter[],
)
end

struct PavitoIpoptCbcAlg <: AbstractOptimizer end

function Workspace(model::VecModel, optimizer::PavitoIpoptCbcAlg, args...; kwargs...,)
function Workspace(model::VecModel, optimizer::PavitoIpoptCbcAlg, args...; kwargs...)
return PavitoIpoptCbcWorkspace(model, args...; kwargs...)
end

Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using NonconvexPavito, LinearAlgebra, Test

f(x::AbstractVector) = sqrt(x[2])
g(x::AbstractVector, a, b) = (a*x[1] + b)^3 - x[2]
g(x::AbstractVector, a, b) = (a * x[1] + b)^3 - x[2]

@testset "First order - $first_order" for first_order in [true, false]
options = PavitoIpoptCbcOptions(first_order = first_order)
Expand Down

0 comments on commit 764bc33

Please sign in to comment.