Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/format_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ jobs:
using Pkg
Pkg.add(PackageSpec(name="JuliaFormatter", version="2"))
using JuliaFormatter
format("src/MOI_wrapper", verbose=true)
format("src")
format("ext/ConoptMathOptInterfaceExt", verbose=true)
format("test", verbose=true)
out = String(read(Cmd(`git diff`)))
if isempty(out)
Expand Down
3 changes: 1 addition & 2 deletions ext/ConoptMathOptInterfaceExt/ConoptMathOptInterfaceExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ PrecompileTools.@setup_workload begin
# Add a nonlinear objective
MOI.set(src, MOI.ObjectiveSense(), MOI.MAX_SENSE)
f_nl = MOI.ScalarNonlinearFunction(
:+,
Any[MOI.ScalarNonlinearFunction(:sin, Any[x[i]]) for i in 1:3],
:+, Any[MOI.ScalarNonlinearFunction(:sin, Any[x[i]]) for i in 1:3]
)
MOI.set(src, MOI.ObjectiveFunction{typeof(f_nl)}(), f_nl)

Expand Down
25 changes: 12 additions & 13 deletions ext/ConoptMathOptInterfaceExt/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mutable struct Optimizer <: MOI.AbstractOptimizer
name::String # name of the model

# parameters
time_limit::Union{Real,Nothing} # time limit in seconds
time_limit::Union{Real, Nothing} # time limit in seconds
log_level::Int # the log level
threads::Int # number of threads (0 is default, tells CONOPT to use the maximum number of threads)
silent::Bool # should the output be disabled
Expand Down Expand Up @@ -114,15 +114,12 @@ function empty_cache!(cache)
return cache
end


###
### Some defines used for specifying the supported constraints
###

const _SETS = Union{
MOI.GreaterThan{Float64},
MOI.LessThan{Float64},
MOI.EqualTo{Float64},
}
const _SETS = Union{MOI.GreaterThan{Float64}, MOI.LessThan{Float64}, MOI.EqualTo{Float64}}

const _FUNCTIONS = Union{
MOI.VariableIndex,
Expand Down Expand Up @@ -187,7 +184,6 @@ function MOI.empty!(model::Optimizer)
end



###
### get, set and supports functions for various Optimizer attributes
###
Expand All @@ -204,6 +200,7 @@ function MOI.get(::Optimizer, ::MOI.SolverVersion)::String
return string(major[], ".", minor[], ".", patch[])
end


# raw solver
MOI.get(model::Optimizer, ::MOI.RawSolver) = model.inner.cntvect

Expand Down Expand Up @@ -357,6 +354,7 @@ function MOI.supports_constraint(
return true
end


###
### indicate the types of objectives that CONOPT supports
###
Expand All @@ -381,6 +379,7 @@ function MOI.set(model::Optimizer, ::MOI.ObjectiveSense, sense::MOI.Optimization
return nothing
end


###
### _EmptyNLPEvaluator
###
Expand Down Expand Up @@ -555,6 +554,7 @@ function _setup_options!(dest::Optimizer)
return dest.inner.license.license_string = dest.license_string
end


"""
function _update_variable_bounds!(model_data::ModelData, var_index::Int; lower::Float64 = -Inf, upper::Float64 = Inf)

Expand Down Expand Up @@ -598,7 +598,7 @@ function _setup_variables!(dest::Optimizer, src::MOI.ModelLike)
dest.var_index_to_pos = zeros(Int, max_index)

dest.inner.model_data.variable_primal_start = zeros(Float64, n_vars)
dest.inner.model_data.variable_lower = fill(-dest.lim_variable, n_vars) #= ah, that's probably where you would need lim_variable, because if the user chooses a different value for CONOPT, this would not be correct =#
dest.inner.model_data.variable_lower = fill(-dest.lim_variable, n_vars)
dest.inner.model_data.variable_upper = fill(dest.lim_variable, n_vars)

for (i, v) in enumerate(dest.variable_indices)
Expand All @@ -616,7 +616,6 @@ function _setup_variables!(dest::Optimizer, src::MOI.ModelLike)
end



"""
function _set_objective_sense!(model::Optimizer, sense::MOI.OptimizationSense)

Expand Down Expand Up @@ -1008,7 +1007,6 @@ function setup_model!(dest::Optimizer, src::MOI.ModelLike)
end



"""
function setup_inner!(model::Optimizer)

Expand All @@ -1026,7 +1024,6 @@ end
### Optimize
###


"""
function MOI.optimize!(dest::Optimizer, src::MOI.ModelLike)

Expand Down Expand Up @@ -1086,7 +1083,7 @@ function MOI.get(model::Optimizer, ::MOI.TerminationStatus)
return MOI.DUAL_INFEASIBLE
elseif model_status == CONOPT.ModelStatus_Infeasible
#return MOI.INFEASIBLE_OR_UNBOUNDED # we don't return INFEASIBLE_OR_UNBOUNDED because
# CONOPT is a local solver.
# CONOPT is a local solver.
return MOI.LOCALLY_INFEASIBLE
elseif model_status == CONOPT.ModelStatus_Locally_Infeasible
return MOI.LOCALLY_INFEASIBLE
Expand Down Expand Up @@ -1116,12 +1113,15 @@ function MOI.get(model::Optimizer, ::MOI.TerminationStatus)
return MOI.OPTIMIZE_NOT_CALLED
end


# raw status string explaining why the solver stopped
MOI.get(model::Optimizer, ::MOI.RawStatusString) = model.inner.solution_status.raw_status


# solving time in seconds
MOI.get(model::Optimizer, ::MOI.SolveTimeSec) = model.solve_time


# the primal status - the status of the primal solution
function MOI.get(model::Optimizer, attr::MOI.PrimalStatus)
if CONOPT.is_empty(model.inner)
Expand Down Expand Up @@ -1298,7 +1298,6 @@ end
### Utilities
###


"""
function print_model_representation(jac, data)

Expand Down
2 changes: 1 addition & 1 deletion src/C_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ mutable struct ConoptModel
cntvect::Ref{Ptr{Cvoid}} # pointer to the CONOPT control vector
silent::Bool # whether CONOPT output should be suppressed: affects the output callbacks of CONOPT
log_level::Int # the log level for the CONOPT output. This matches the C++ verbosity levels
time_limit::Union{Float64,Nothing} # the solver time limit
time_limit::Union{Float64, Nothing} # the solver time limit
threads::Int # the number of threads to use
options::Dict{String, Any} # solver options
option_offset::Int # offset for invalid options
Expand Down
13 changes: 4 additions & 9 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ implemented or that your solver doesn't support.
"""
function test_runtests()
model = MOI.instantiate(
CONOPT.Optimizer;
with_bridge_type=Float64,
with_cache_type=Float64,
CONOPT.Optimizer; with_bridge_type=Float64, with_cache_type=Float64
)
MOI.set(model, MOI.Silent(), true)
config = MOI.Test.Config(;
Expand All @@ -52,15 +50,12 @@ function test_runtests()
],
)
MOI.Test.runtests(
model,
config;
exclude=[
model, config; exclude=[
# CONOPT is a local solver
r"^test_nonlinear_hs071_global$",
],
verbose=true,
], verbose=true
)
return
return nothing
end

"""
Expand Down
Loading