Skip to content

Commit bc05b49

Browse files
committed
Make resolve compatible with solve(heuristic=true)
1 parent 3e54e76 commit bc05b49

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

src/model/resolve.jl

+31-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ function resolve(model_old, instance::Instance; optimizer = nothing)::OrderedDic
1717
lp_optimizer = _get_default_lp_optimizer()
1818
end
1919

20+
@info "Filtering candidate locations..."
21+
selected_pairs = Set()
22+
for ((node_old, t), var_old) in model_old[:is_open]
23+
if JuMP.value(var_old) > 0.1
24+
push!(selected_pairs, (node_old.location.plant_name, node_old.location.location_name))
25+
end
26+
end
27+
filtered_plants = []
28+
for p in instance.plants
29+
if (p.plant_name, p.location_name) in selected_pairs
30+
push!(filtered_plants, p)
31+
end
32+
end
33+
instance.plants = filtered_plants
34+
2035
@info "Building new graph..."
2136
graph = build_graph(instance)
2237
_print_graph_stats(instance, graph)
@@ -48,10 +63,12 @@ function _fix_plants!(model_old, model_new)::Nothing
4863
# Fix open_plant variables
4964
for ((node_old, t), var_old) in model_old[:open_plant]
5065
value_old = JuMP.value(var_old)
51-
node_new = model_new[:graph].name_to_process_node_map[(
66+
key = (
5267
node_old.location.plant_name,
5368
node_old.location.location_name,
54-
)]
69+
)
70+
key keys(model_new[:graph].name_to_process_node_map) || continue
71+
node_new = model_new[:graph].name_to_process_node_map[key]
5572
var_new = model_new[:open_plant][node_new, t]
5673
JuMP.unset_binary(var_new)
5774
JuMP.fix(var_new, value_old)
@@ -61,10 +78,12 @@ function _fix_plants!(model_old, model_new)::Nothing
6178
for ((node_old, t), var_old) in model_old[:is_open]
6279
t > 0 || continue
6380
value_old = JuMP.value(var_old)
64-
node_new = model_new[:graph].name_to_process_node_map[(
81+
key = (
6582
node_old.location.plant_name,
6683
node_old.location.location_name,
67-
)]
84+
)
85+
key keys(model_new[:graph].name_to_process_node_map) || continue
86+
node_new = model_new[:graph].name_to_process_node_map[key]
6887
var_new = model_new[:is_open][node_new, t]
6988
JuMP.unset_binary(var_new)
7089
JuMP.fix(var_new, value_old)
@@ -73,10 +92,12 @@ function _fix_plants!(model_old, model_new)::Nothing
7392
# Fix plant capacities
7493
for ((node_old, t), var_old) in model_old[:capacity]
7594
value_old = JuMP.value(var_old)
76-
node_new = model_new[:graph].name_to_process_node_map[(
95+
key = (
7796
node_old.location.plant_name,
7897
node_old.location.location_name,
79-
)]
98+
)
99+
key keys(model_new[:graph].name_to_process_node_map) || continue
100+
node_new = model_new[:graph].name_to_process_node_map[key]
80101
var_new = model_new[:capacity][node_new, t]
81102
JuMP.delete_lower_bound(var_new)
82103
JuMP.delete_upper_bound(var_new)
@@ -87,10 +108,12 @@ function _fix_plants!(model_old, model_new)::Nothing
87108
for ((node_old, t), var_old) in model_old[:expansion]
88109
t > 0 || continue
89110
value_old = JuMP.value(var_old)
90-
node_new = model_new[:graph].name_to_process_node_map[(
111+
key = (
91112
node_old.location.plant_name,
92113
node_old.location.location_name,
93-
)]
114+
)
115+
key keys(model_new[:graph].name_to_process_node_map) || continue
116+
node_new = model_new[:graph].name_to_process_node_map[key]
94117
var_new = model_new[:expansion][node_new, t]
95118
JuMP.delete_lower_bound(var_new)
96119
JuMP.delete_upper_bound(var_new)

test/src/model/resolve_test.jl

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44
using RELOG
55

66
function model_resolve_test()
7-
@testset "Resolve" begin
7+
@testset "Resolve (exact)" begin
88
# Shoud not crash
99
filename = fixture("s1.json")
1010
solution_old, model_old = RELOG.solve(filename, return_model = true)
1111
solution_new = RELOG.resolve(model_old, filename)
1212
end
13+
14+
@testset "Resolve (heuristic)" begin
15+
# Shoud not crash
16+
filename = fixture("s1.json")
17+
solution_old, model_old = RELOG.solve(filename, return_model = true, heuristic = true)
18+
solution_new = RELOG.resolve(model_old, filename)
19+
end
1320
end

0 commit comments

Comments
 (0)