-
Notifications
You must be signed in to change notification settings - Fork 9
/
bench_modify.jl
88 lines (73 loc) · 1.75 KB
/
bench_modify.jl
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using JuMP
import MathOptInterface as MOI
using Gurobi
using COPT
function bench_jump(model, N::Int, M::Int)
I = 1:N
@variable(model, x[I])
@constraint(model, sum(x[i] for i = I) == N)
@objective(model, Min, sum(i / N * x[i] for i = I))
# for j in 1:M:N
for j in [1]
last_variable = j + M - 1
if last_variable > N
last_variable = N
end
deleted_variables = [x[i] for i in j:last_variable]
delete(model, deleted_variables)
optimize!(model)
end
end
function gurobi_model()
optimizer = optimizer_with_attributes(
Gurobi.Optimizer,
"Presolve" => 0,
"TimeLimit" => 0.0,
MOI.Silent() => true,
)
model = direct_model(optimizer)
return model
end
function copt_model()
optimizer = optimizer_with_attributes(
COPT.Optimizer,
"Presolve" => 0,
"TimeLimit" => 0.0,
MOI.Silent() => true,
)
model = direct_model(optimizer)
return model
end
function bench_gurobi(N, M)
model = gurobi_model()
bench_jump(model, N, M)
end
function bench_copt(N, M)
model = copt_model()
bench_jump(model, N, M)
end
function main(N, M)
time_dict = Dict{String,Float64}()
println("N: $N, M: $M")
println("Gurobi starts")
t1 = time()
bench_gurobi(N, M)
t2 = time()
println("Gurobi ends and takes ", t2 - t1, " seconds")
time_dict["gurobi"] = t2 - t1
println("COPT starts")
t1 = time()
bench_copt(N, M)
t2 = time()
println("COPT ends and takes ", t2 - t1, " seconds")
time_dict["copt"] = t2 - t1
return time_dict
end
main(5, 1)
result_dict = Dict()
for N in [1000000]
for M in [10000]
result_dict[(N, M)] = main(N, M)
end
end
result_dict