Skip to content

Commit

Permalink
Add MOI v1.0 support
Browse files Browse the repository at this point in the history
- Remove deprecated test and replace with new MOI tests
  • Loading branch information
migarstka committed Feb 19, 2022
1 parent b3eff39 commit 3f9a535
Show file tree
Hide file tree
Showing 2 changed files with 311 additions and 262 deletions.
46 changes: 36 additions & 10 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# certain utility function are taken from the SCS MathOptInterface:
# https://github.com/JuliaOpt/SCS.jl
using MathOptInterface

const MOI = MathOptInterface
const MOIU = MOI.Utilities
const CI = MOI.ConstraintIndex
Expand Down Expand Up @@ -345,19 +344,28 @@ coefficient(t::MOI.ScalarAffineTerm) = t.coefficient
coefficient(t::MOI.VectorAffineTerm) = coefficient(t.scalar_term)

function processconstraints!(optimizer::Optimizer{T}, src::MOI.ModelLike, idxmap, LOCs, rowranges::Dict{Int, UnitRange{Int}}) where {T <: AbstractFloat}

m = mapreduce(length, +, values(rowranges), init = 0)


if length(LOCs) > 0
m = mapreduce(length, +, values(rowranges), init = 0)
else
# handle case of a problem without constraints
m = 0
end
b = zeros(T, m)
constant = zeros(T, m)
I = Int[]
J = Int[]
V = T[]
convex_sets = Array{COSMO.AbstractConvexSet{T}}(undef, 0)
set_constant = zeros(T, m)
# loop over constraints and modify A, l, u and constants
for (F, S) in LOCs
processconstraints!((I, J, V), b, convex_sets, constant, set_constant, src, idxmap, rowranges, F, S)

if m > 0
# loop over constraints and modify A, l, u and constants
for (F, S) in LOCs
processconstraints!((I, J, V), b, convex_sets, constant, set_constant, src, idxmap, rowranges, F, S)
end
else
convex_sets = [COSMO.ZeroSet{T}(0)] #fall back if no constraints present
end
optimizer.set_constant = set_constant
# subtract constant from right hand side
Expand Down Expand Up @@ -624,9 +632,27 @@ function MOI.get(optimizer::Optimizer, a::MOI.ObjectiveValue)
end
end

MOI.get(optimizer::Optimizer, a::MOI.SolveTimeSec) = optimizer.results.times.solver_time
MOI.get(optimizer::Optimizer, a::MOI.SolverName) = "COSMO"
MOI.get(optimizer::Optimizer, a::MOI.SolverVersion) = "v" * string(COSMO.version())

MOI.get(optimizer::Optimizer, ::MOI.SolverName) = "COSMO"
MOI.get(optimizer::Optimizer, ::MOI.SolverVersion) = "v" * string(COSMO.version())
MOI.get(optimizer::Optimizer, ::MOI.NumberOfThreads) = Threads.nthreads()

function MOI.get(optimizer::Optimizer, ::MOI.RawStatusString)
if optimizer.hasresults
return string(optimizer.results.status)
else
return ""
end
end

function MOI.get(optimizer::Optimizer, a::MOI.SolveTimeSec)
if optimizer.hasresults
return optimizer.results.times.solver_time
else
return NaN
end
end


# Get Termination Status
function MOI.get(optimizer::Optimizer, a::MOI.TerminationStatus)
Expand Down
Loading

0 comments on commit 3f9a535

Please sign in to comment.