using JuMP

using HiGHS

a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
b = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75]
arraySize = length(a)
model = Model(HiGHS.Optimizer)
> @variable(model, quantity[1:arraySize], Int)

> @constraint(model, 0 .<= quantity .<= b .- 1)
> @objective(model, Max, a' * quantity)

> @time begin
optimize!(model)
end

if termination_status(model) == MOI.OPTIMAL
    Get the optimal values of x, y, and z
    as = value.(quantity)
    println(as)
else
    println("Optimization failed.")
end

the above code takes 3 seconds to solve equation i want to solve this equation in less than second what can i do please help

1

There are 1 answers

0
Oscar Dowson On

This is Julia's compilation latency at work. See https://jump.dev/JuMP.jl/stable/tutorials/getting_started/performance_tips/#The-%22time-to-first-solve%22-issue

If you solve a second model, it takes only a fraction of a second.

julia> @time begin
           optimize!(model)
       end
Solution has               num          max          sum
Col     infeasibilities      0            0            0
Integer infeasibilities      0            0            0
Row     infeasibilities      0            0            0
Row     residuals            0            0            0
Presolving model
0 rows, 0 cols, 0 nonzeros
0 rows, 0 cols, 0 nonzeros
Presolve: Optimal

Solving report
  Status            Optimal
  Primal bound      16250
  Dual bound        16250
  Gap               0% (tolerance: 0.01%)
  Solution status   feasible
                    16250 (objective)
                    0 (bound viol.)
                    0 (int. viol.)
                    0 (row viol.)
  Timing            0.00 (total)
                    0.00 (presolve)
                    0.00 (postsolve)
  Nodes             0
  LP iterations     0 (total)
                    0 (strong br.)
                    0 (separation)
                    0 (heuristics)
  0.000675 seconds (2 allocations: 32 bytes)