Suppose I have a model as follows:
using CSV
using JuMP
using HiGHS
using Random
using DataFrames
Random.seed!(2025)
Z = 3
T = 8760
coef = rand(Float64, (Z,T))
m = Model(HiGHS.Optimizer)
@variable(m, x1[z in 1:Z, t in 1:T]>=0)
@variable(m, x2[z in 1:Z, t in 1:T]>=0)
@constraint(m, c1[z in 1:Z, t in 1:T], m[:x1][z,t] + 2*m[:x2][z,t] <= 2)
@constraint(m, c2[z in 1:Z, t in 1:T], 2*m[:x1][z,t] + m[:x2][z,t] >= 1)
@expression(m, e[z in 1:Z, t in 1:T], coef[z, t]*m[:x1][z,t]+(1-coef[z,t])*m[:x2][z,t])
@objective(m, Min, sum(m[:e][z,t] for z in 1:Z, t in 1:T))
optimize!(m)
@sync begin
@async begin
global t1_start = time()
CSV.write("x1.csv", DataFrame(value.(m[:x1]),:auto))
global t1_end = time()
println("Writing x1 done at $t1_end")
end
@async begin
global t2_start = time()
CSV.write("x2.csv", DataFrame(value.(m[:x2]),:auto))
global t2_end = time()
println("Writing x2 done at $t2_end")
end
end
println("Start time difference is $(t2_start - t1_start)")
println("End time difference is $(t2_end - t1_end)")
println("Average writing time is $((t2_end - t1_end + t2_start - t1_start)/2)")
the time difference is shown as follows:
Start time difference is 0.0315549373626709
End time difference is 0.028921842575073242
Average writing time is 0.03023838996887207
The time difference of two start times is almost same as writing time, does this mean that we could not fetch the results from solved model asynchronously? Is there any way to fulfill asynchronous results fetch?