diff --git a/.github/workflows/format_check.yml b/.github/workflows/format_check.yml index 1609b1c..3f67b20 100644 --- a/.github/workflows/format_check.yml +++ b/.github/workflows/format_check.yml @@ -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) diff --git a/ext/ConoptMathOptInterfaceExt/ConoptMathOptInterfaceExt.jl b/ext/ConoptMathOptInterfaceExt/ConoptMathOptInterfaceExt.jl index e1bb211..9c8d8cf 100644 --- a/ext/ConoptMathOptInterfaceExt/ConoptMathOptInterfaceExt.jl +++ b/ext/ConoptMathOptInterfaceExt/ConoptMathOptInterfaceExt.jl @@ -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) diff --git a/ext/ConoptMathOptInterfaceExt/MOI_wrapper.jl b/ext/ConoptMathOptInterfaceExt/MOI_wrapper.jl index 72ab084..5bc7b30 100644 --- a/ext/ConoptMathOptInterfaceExt/MOI_wrapper.jl +++ b/ext/ConoptMathOptInterfaceExt/MOI_wrapper.jl @@ -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 @@ -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, @@ -187,7 +184,6 @@ function MOI.empty!(model::Optimizer) end - ### ### get, set and supports functions for various Optimizer attributes ### @@ -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 @@ -357,6 +354,7 @@ function MOI.supports_constraint( return true end + ### ### indicate the types of objectives that CONOPT supports ### @@ -381,6 +379,7 @@ function MOI.set(model::Optimizer, ::MOI.ObjectiveSense, sense::MOI.Optimization return nothing end + ### ### _EmptyNLPEvaluator ### @@ -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) @@ -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) @@ -616,7 +616,6 @@ function _setup_variables!(dest::Optimizer, src::MOI.ModelLike) end - """ function _set_objective_sense!(model::Optimizer, sense::MOI.OptimizationSense) @@ -1008,7 +1007,6 @@ function setup_model!(dest::Optimizer, src::MOI.ModelLike) end - """ function setup_inner!(model::Optimizer) @@ -1026,7 +1024,6 @@ end ### Optimize ### - """ function MOI.optimize!(dest::Optimizer, src::MOI.ModelLike) @@ -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 @@ -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) @@ -1298,7 +1298,6 @@ end ### Utilities ### - """ function print_model_representation(jac, data) diff --git a/src/C_wrapper.jl b/src/C_wrapper.jl index 4688822..b2e4e88 100644 --- a/src/C_wrapper.jl +++ b/src/C_wrapper.jl @@ -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 diff --git a/test/MOI_wrapper.jl b/test/MOI_wrapper.jl index ea58b6e..78ce77e 100644 --- a/test/MOI_wrapper.jl +++ b/test/MOI_wrapper.jl @@ -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(; @@ -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 """