jump-dev / Cbc.jl

A Julia interface to the Coin-OR Branch and Cut solver (CBC)
https://projects.coin-or.org/Cbc
Other
81 stars 35 forks source link

Fix performance issue #180

Closed odow closed 3 years ago

odow commented 3 years ago

Closes #172 Closes #173

Before

julia> bench();
Optimal - objective value 4.50015e+08
Optimal objective 450015000 - 0 iterations time 0.002
  4.113598 seconds (60.00 k allocations: 2.976 MiB)

After

julia> bench();
Optimal - objective value 4.50015e+08
Optimal objective 450015000 - 0 iterations time 0.002
  0.000598 seconds (4 allocations: 234.547 KiB)

Script

using Cbc
const MOI = Cbc.MOI

function bench(N = 30_000)
    cbc = Cbc.Optimizer()
    model = MOI.Utilities.CachingOptimizer(MOI.Utilities.Model{Float64}(), cbc)
    x = MOI.add_variables(model, N);
    MOI.add_constraints(model, x, MOI.GreaterThan.(1.0:N));
    MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE);
    f = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(1.0, x), 0.0);
    MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f);
    MOI.optimize!(model)
    @time MOI.get.(model, MOI.VariablePrimal(), x)
end
bench()
codecov[bot] commented 3 years ago

Codecov Report

Merging #180 (1a263fe) into master (33bcd1b) will increase coverage by 0.67%. The diff coverage is 95.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #180      +/-   ##
==========================================
+ Coverage   53.93%   54.61%   +0.67%     
==========================================
  Files           3        3              
  Lines         534      542       +8     
==========================================
+ Hits          288      296       +8     
  Misses        246      246              
Impacted Files Coverage Δ
src/MOI_wrapper/MOI_wrapper.jl 80.83% <95.00%> (+0.47%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 33bcd1b...1a263fe. Read the comment docs.