Skip to content

Commit

Permalink
Breaking changes for MOI 0.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed May 3, 2021
1 parent b9c225c commit 494b397
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
14 changes: 7 additions & 7 deletions perf/runbench.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function generate_moi_problem(model, At, b, c;
else
for row in 1:rows
MOI.add_constraint(model, MOI.VectorAffineFunction(
[MOI.VectorAffineTerm(1,
[MOI.VectorAffineTerm(1,
MOI.ScalarAffineTerm(A_vals[i], x[A_cols[i]])
) for i in nzrange(At, row)], [-b[row]]),
MOI.Nonpositives(1))
Expand Down Expand Up @@ -113,7 +113,7 @@ function time_build_and_solve(to_build, to_solve, At, b, c, scalar = true)
end
MOI.set(to_solve, MOI.TimeLimitSec(), 0.0010)
@time @timeit "opt" MOI.optimize!(to_solve)
val = MOI.get(to_solve, MOI.SolveTime())
val = MOI.get(to_solve, MOI.SolveTimeSec())
println(val)
@show MOI.get(to_solve, MOI.ObjectiveValue())
@show MOI.get(to_solve, MOI.TerminationStatus())
Expand All @@ -129,19 +129,19 @@ function solve_GLPK(seed, data; time_limit_sec=Inf)
GC.gc()
bridged_cache, pure_solver = bridged_cache_and_solver()
@timeit "bc + s" time_build_and_solve(bridged_cache, pure_solver, At, b, c)

GC.gc()
cache, pure_solver2 = cache_and_solver()
@timeit "c + s" time_build_and_solve(cache, pure_solver2, At, b, c)

GC.gc()
full_solver = bridged_cached_solver()
@timeit "bcs" time_build_and_solve(full_solver, full_solver, At, b, c)

GC.gc()
full_solver = bridged_cached_solver()
@timeit "bcs + v" time_build_and_solve(full_solver, full_solver, At, b, c, false)

GC.gc()
cache_solver = cached_solver()
@timeit "cs" time_build_and_solve(cache_solver, cache_solver, At, b, c)
Expand All @@ -153,4 +153,4 @@ function solve_GLPK(seed, data; time_limit_sec=Inf)
end

solve_GLPK(2, RandomLP(11, 11, 0.5); time_limit_sec=5)
solve_GLPK(20, RandomLP(10000, 10000, 0.005); time_limit_sec=5)
solve_GLPK(20, RandomLP(10000, 10000, 0.005); time_limit_sec=5)
6 changes: 3 additions & 3 deletions src/MOI_wrapper/MOI_copy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function _extract_row_data(src, mapping, lb, ub, I, J, V, ::Type{S}) where {S}
for term in f.terms
non_zeros += 1
I[non_zeros] = row
J[non_zeros] = Cint(mapping[term.variable_index].value::Int64)
J[non_zeros] = Cint(mapping[term.variable].value::Int64)
V[non_zeros] = term.coefficient
end
row += 1
Expand All @@ -134,7 +134,7 @@ function _extract_row_data(src, mapping, lb, ub, I, J, V, ::Type{S}) where {S}
end

function test_data(src, dest)
for (F, S) in MOI.get(src, MOI.ListOfConstraints())
for (F, S) in MOI.get(src, MOI.ListOfConstraintTypesPresent())
if !MOI.supports_constraint(dest, F, S)
throw(MOI.UnsupportedConstraint{F, S}("GLPK.Optimizer does not support constraints of type $F-in-$S."))
end
Expand Down Expand Up @@ -235,7 +235,7 @@ function MOI.copy_to(
end

function pass_constraint_attributes(dest, src, copy_names, mapping)
ctr_types = MOI.get(src, MOI.ListOfConstraints())
ctr_types = MOI.get(src, MOI.ListOfConstraintTypesPresent())
for (F,S) in ctr_types
pass_constraint_attributes(dest, src, copy_names, mapping, F, S)
end
Expand Down
12 changes: 6 additions & 6 deletions src/MOI_wrapper/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ function _indices_and_coefficients(
)
i = 1
for term in f.terms
indices[i] = Cint(column(model, term.variable_index))
indices[i] = Cint(column(model, term.variable))
coefficients[i] = term.coefficient
i += 1
end
Expand Down Expand Up @@ -602,7 +602,7 @@ function MOI.set(
num_vars = length(model.variable_info)
obj = zeros(Float64, num_vars)
for term in f.terms
col = column(model, term.variable_index)
col = column(model, term.variable)
obj[col] += term.coefficient
end
for (col, coef) in enumerate(obj)
Expand Down Expand Up @@ -1598,7 +1598,7 @@ end

function MOI.get(model::Optimizer, attr::MOI.PrimalStatus)
_throw_if_optimize_in_progress(model, attr)
if attr.N != 1
if attr.result_index != 1
return MOI.NO_SOLUTION
end
(status, _) = _get_status(model)
Expand All @@ -1618,7 +1618,7 @@ end

function MOI.get(model::Optimizer, attr::MOI.DualStatus)
_throw_if_optimize_in_progress(model, attr)
if attr.N != 1 || model.last_solved_by_mip
if attr.result_index != 1 || model.last_solved_by_mip
return MOI.NO_SOLUTION
end
(status, _) = _get_status(model)
Expand Down Expand Up @@ -1856,7 +1856,7 @@ function MOI.get(model::Optimizer, attr::MOI.RelativeGap)
return model.relative_gap
end

function MOI.get(model::Optimizer, attr::MOI.SolveTime)
function MOI.get(model::Optimizer, attr::MOI.SolveTimeSec)
_throw_if_optimize_in_progress(model, attr)
return model.solve_time
end
Expand Down Expand Up @@ -1942,7 +1942,7 @@ function MOI.get(
return sort!(indices, by = x -> x.value)
end

function MOI.get(model::Optimizer, ::MOI.ListOfConstraints)
function MOI.get(model::Optimizer, ::MOI.ListOfConstraintTypesPresent)
constraints = Set{Tuple{DataType, DataType}}()
for info in values(model.variable_info)
if info.bound == NONE
Expand Down

0 comments on commit 494b397

Please sign in to comment.