-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04-lim.jl
135 lines (113 loc) · 3.41 KB
/
04-lim.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# using Infiltrator
# using Revise
using OPAC
using Graphs
using Serialization
using Printf
using MetaGraphs
using JuMP
# using Cthulhu
const air_cost=1_000
const air_cap=10_000
const L=4000
const inst_ind = 1
const inst_list = sort(filter(map(readdir("instances")) do x
n,m = parse.(Int, split(x[1:end-4], "-")[2:end])
(n=n, m=m, fn="instances/"*x)
end) do x
x.n <= 51 && x.m <= 1000
end, by=x->(x.n, x.m))
function load_inst(i, s, P)
inst = load_instance(i.fn)
ag, a2l, l2a = mk_air_graph(i.n, i.n, s)
mg = combgraph(inst.lg, ag, a2l, P; download_cost=inst.download_cost, upload_cost=inst.upload_cost)
inst, P, mg, ag, l2a
end
obj_if(model) = if termination_status(model) == MOI.OPTIMAL
objective_value(model), 0.0
else
if has_values(model)
objective_value(model), relative_gap(model)
else
-1, relative_gap(model)
end
end
function fun_benders_gen(inst, P, mg, ag, l2a, m)
model = master_colgen(inst.D, P, mg, inst.lg, ag, l2a;
air_cost=air_cost, air_cap=air_cap, L=L,
model=m, download_cost=inst.download_cost, upload_cost=inst.upload_cost)
obj_if(model)
end
function show_table(res; show_loss=false)
k = ["BD"]
join([string(hk.n) * " & " * string(hk.m) * " & " * string(hk.s) * " & " * string(hk.p) * " & " * join([
begin
j = (mode=i, hk...)
if j ∈ keys(res)
l = res[j]
if show_loss
if l.val[2] == -1.0 # optimal
""
else
@sprintf " %.3e " l.val[1]
end
else
if l.val[2] == 0.0 # optimal
@sprintf " %.1f " l.time
elseif l.val[1] == -1.0 || l.val[2] >= 1 # infeasible
""
else
@sprintf " %.1f\\,\\si{\\percent} " (l.val[2] * 100)
end
end
else
""
end
end
for i in k], " & ") * " \\\\ \n"
for hk in sort(unique([(n=k.n, m=k.m, s=k.s, p=k.p)
for k in keys(res)]), by=x->(x.n, x.m, -x.s, x.p))])
end
# warmup
@time let (inst, P, mg, ag, l2a) = load_inst(inst_list[inst_ind], 5, 3)
fun_benders_gen(inst, 3, mg, ag, l2a, multiflow_gurobi())
end
function main(inst_list, fn, res)
for i in inst_list,
s in [5, 10],
p in [1, 5, 10]
let kn = (mode="BD", n=i.n, m=i.m, s=s, p=p)
if kn ∉ keys(res)
try
t = @elapsed val = let (inst, P, mg, ag, l2a) = load_inst(i, 5, p)
fun_benders_gen(inst, P, mg, ag, l2a, multiflow_gurobi())
end
@show kn, t
res[kn] = (time=t, val=val)
fn !== nothing && serialize(fn, res)
catch e
@show e
end
end
end
w1 = show_table(deepcopy(res); show_loss=false)
println(w1)
w2 = show_table(deepcopy(res); show_loss=true)
if fn !== nothing
open(fn *"-t.txt", "w") do fd
println(fd, w1)
end
open(fn *"-l.txt", "w") do fd
println(fd, w2)
end
end
end
res
end
main(inst_list[[1]], nothing, Dict())
main(inst_list, "lims.jld", try
deserialize("lims.jld")
catch e
println("ignoring error ", e)
Dict()
end)