jump-dev / HiGHS.jl

A Julia interface to the HiGHS solver
https://highs.dev
MIT License
103 stars 14 forks source link

Add constraint is very slow #78

Closed 1991jhf closed 2 years ago

1991jhf commented 2 years ago

using HiGHS q=MOI.add_variable(optimizer) @btime MOI.add_constraint(optimizer,q*1.0,MOI.LessThan(0.0))

4.688 ms (9 allocations: 432 bytes)


using CPLEX q=MOI.add_variable(optimizer) @btime MOI.add_constraint(optimizer,q*1.0,MOI.LessThan(0.0))

804.895 ns (15 allocations: 560 bytes)

odow commented 2 years ago

Do you have a reproducible example?


julia> using HiGHS

julia> const MOI = HiGHS.MOI
MathOptInterface

julia> model = HiGHS.Optimizer()
A HiGHS model with 0 columns and 0 rows.

julia> x = MOI.add_variable(model)
MathOptInterface.VariableIndex(1)

julia> using BenchmarkTools

julia> @btime MOI.add_constraint(model, 1.0 * x, MOI.LessThan(0.0))
  1.094 μs (8 allocations: 512 bytes)
MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64}, MathOptInterface.LessThan{Float64}}(500503)
odow commented 2 years ago

I'll also note that benchmarking like this isn't very accurate, because we're modifying the model in-place. So the time can depend on how many runs you have. In my example, we added 500,503 constraints. I could see that if you run @btime multiple times, it would slow down if we add more constraints.

For proper benchmarking, you should use a setup: https://juliaci.github.io/BenchmarkTools.jl/stable/

Closing this issue because I can't reproduce it. If you have a reproducible benchmark that is slow, please re-open the issue.