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 Jun 15, 2021
1 parent 83e31ee commit d987706
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 235 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ MathOptInterface = "~0.9.19"
julia = "1"

[extras]
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Random", "SparseArrays", "Test"]
test = ["Pkg", "Random", "SparseArrays", "Test"]
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)
10 changes: 5 additions & 5 deletions src/MOI_wrapper/MOI_copy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Throw an error if unsupported constraint or objective types are present in
`src`.
"""
function _validate_constraint_types(dest::Optimizer, src::MOI.ModelLike)
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}(
Expand Down Expand Up @@ -122,7 +122,7 @@ function _extract_row_data(src, map, cache, ::Type{S}) where {S}
for term in f.terms
nnz += 1
cache.I[nnz] = row
cache.J[nnz] = Cint(map[term.variable_index].value::Int64)
cache.J[nnz] = Cint(map[term.variable].value::Int64)
cache.V[nnz] = term.coefficient
end
map[ci] = MOI.ConstraintIndex{MOI.ScalarAffineFunction{Float64},S}(row)
Expand All @@ -137,9 +137,9 @@ function _add_all_variables(model::Optimizer, cache::_OptimizerCache)
sizehint!(model.variable_info, N)
for i in 1:N
bound = get_moi_bound_type(cache.cl[i], cache.cu[i], cache.bounds[i])
index = CleverDicts.add_item(
CleverDicts.add_item(
model.variable_info,
VariableInfo(MOI.VariableIndex(i), i, bound, cache.types[i]),
VariableInfo(MOI.VariableIndex(i), i, bound, cache.types[i], ""),
)
glp_bound_type = get_glp_bound_type(cache.cl[i], cache.cu[i])
glp_set_col_bnds(model, i, glp_bound_type, cache.cl[i], cache.cu[i])
Expand Down Expand Up @@ -223,7 +223,7 @@ function MOI.copy_to(
# Copy model attributes:
MOIU.pass_attributes(dest, src, copy_names, map)
MOIU.pass_attributes(dest, src, copy_names, map, variables)
for (F, S) in MOI.get(src, MOI.ListOfConstraints())
for (F, S) in MOI.get(src, MOI.ListOfConstraintTypesPresent())
indices = MOI.get(src, MOI.ListOfConstraintIndices{F,S}())
# TODO(odow): fix copy_names = false.
MOIU.pass_attributes(dest, src, false, map, indices)
Expand Down
Loading

0 comments on commit d987706

Please sign in to comment.