|
| 1 | +#= |
| 2 | +wrapper.jl |
| 3 | +
|
| 4 | +=# |
| 5 | + |
| 6 | +""" |
| 7 | + Optimizer{T} <: MOI.AbstractOptimizer |
| 8 | +
|
| 9 | +This struct is responsible for integrating AOCoptimizer with MathOptInterface, |
| 10 | +which is how we can build a solver that can be used by JuMP models. |
| 11 | +
|
| 12 | +```julia |
| 13 | +using JuMP |
| 14 | +using AOCoptimizer |
| 15 | +
|
| 16 | +model = Model(AOCoptimizer.Optimizer) |
| 17 | +
|
| 18 | +@variable(model, x[1:5], Bin) |
| 19 | +@variable(model, -2 <= y[1:5] <= 2) |
| 20 | +
|
| 21 | +@objective(model, Max, sum(x) - sum(y) + 2 * x'y) |
| 22 | +
|
| 23 | +optimize!(model) |
| 24 | +``` |
| 25 | +""" |
| 26 | +mutable struct Optimizer{T} <: MOI.AbstractOptimizer |
| 27 | + sense::MOI.OptimizationSense |
| 28 | + |
| 29 | + quadratic::Matrix{T} |
| 30 | + linear::Union{Vector{T},Nothing} |
| 31 | + offset::T |
| 32 | + continuous::Union{Vector{Bool},Nothing} |
| 33 | + |
| 34 | + moi_attributes::Dict{Symbol,Any} |
| 35 | + raw_attributes::Dict{String,Any} |
| 36 | + aim_attributes::Dict{Symbol,Any} |
| 37 | + |
| 38 | + variable_map::Dict{VI,Int} |
| 39 | + variable_info::VariableInfo{T} |
| 40 | + |
| 41 | + fixed::Dict{VI,T} |
| 42 | + |
| 43 | + output::Union{Dict{String,Any},Nothing} |
| 44 | + |
| 45 | + function Optimizer{T}() where {T} |
| 46 | + return new{T}( |
| 47 | + MOI.MIN_SENSE, # sense |
| 48 | + Matrix{T}(undef, 0, 0), # quadratic |
| 49 | + nothing, # linear |
| 50 | + zero(T), # offset |
| 51 | + nothing, # continuous |
| 52 | + Dict{Symbol,Any}( # moi - default |
| 53 | + :name => "", |
| 54 | + :silent => false, |
| 55 | + :time_limit_sec => nothing, |
| 56 | + ), |
| 57 | + Dict{String,Any}(), |
| 58 | + Dict{Symbol,Any}( # aim - default |
| 59 | + :seed => 0, |
| 60 | + ), |
| 61 | + Dict{VI,Int}(), # variable_map |
| 62 | + Dict{VI,Variable{T}}(), # variable_info |
| 63 | + Dict{VI,T}(), # fixed variables |
| 64 | + nothing, |
| 65 | + ) |
| 66 | + end |
| 67 | + |
| 68 | + Optimizer() = Optimizer{Float64}() |
| 69 | +end |
| 70 | + |
| 71 | +function MOI.empty!(optimizer::Optimizer{T}) where {T} |
| 72 | + optimizer.sense = MOI.MIN_SENSE |
| 73 | + optimizer.quadratic = Matrix{T}(undef, 0, 0) |
| 74 | + optimizer.linear = nothing |
| 75 | + optimizer.offset = zero(T) |
| 76 | + optimizer.continuous = nothing |
| 77 | + optimizer.output = nothing |
| 78 | + |
| 79 | + Base.empty!(optimizer.variable_map) |
| 80 | + Base.empty!(optimizer.variable_info) |
| 81 | + Base.empty!(optimizer.fixed) |
| 82 | + |
| 83 | + return optimizer |
| 84 | +end |
| 85 | + |
| 86 | +function MOI.is_empty(optimizer::Optimizer{T}) where {T} |
| 87 | + return isempty(optimizer.quadratic) && |
| 88 | + isnothing(optimizer.linear) && |
| 89 | + isnothing(optimizer.continuous) && |
| 90 | + iszero(optimizer.offset) && |
| 91 | + isempty(optimizer.variable_map) && |
| 92 | + isempty(optimizer.variable_info) && |
| 93 | + isempty(optimizer.fixed) |
| 94 | +end |
| 95 | + |
| 96 | +function Base.show(io::IO, ::Optimizer) |
| 97 | + return print(io, "AOC Optimizer") |
| 98 | +end |
0 commit comments