I was working on a heuristic where I modify an ILP within a loop and solve it for a certain iterations. As of now, within the loop, I build the model repeatedly during each iteration which is costing me more time. Is there a possibility to not repeatedly build the model while modifying the model and decrementing the timelimit to solve it within the loop? A simple pseudocode below intended to illustrate what I’m trying to do.
f = 10
for i in 1:10
m = build_ILP(instance, parameters)
@constraint(m.model, x + y <= 10*f)
solve(m.model)
f -= 1
end
You can modify a JuMP model by adding additional constraints: just call @constraint again. Similarly, to modify the time limit, just call set_time_limit_sec again.
Option 1: look up the variables in m.model:
m = build_ILP(instance, parameters)
model = m.model
x = model[:x]
y = model[:y]
f = 1
for i in 1:10
set_time_limit_sec(model, 10 - i)
@constraint(mmodel, x + y <= 10 * f)
optimize!(model)
f -= 1
end
Option 2: return the variables from the build_ILP function:
model, x, y = build_ILP(instance, parameters)
for f in 10:-1:1
set_time_limit_sec(model, f)
@constraint(mmodel, x + y <= 10 * f)
optimize!(model)
end
Thanks a lot @odow. But since some of my previous implementation is still using JuMP v0.18, could you please let me know how to replicate this in JuMP v0.18?