In the JuMP docs it shows how to efficiently set start values using one model:
x = all_variables(model) x_solution = value.(x) set_start_value.(x, x_solution)
However, I am looking for an efficient way to do this with two models, where the first model (with a solution) includes a subset of the variables in a second model.
Here is my very slow attempt:
# ... build model1 optimize!(model1) x1 = all_variables(model1); x1_solution = value.(x1); d = Dict(string(n)=>v for (n,v) in zip(x1, x1_solution)) model2 = JuMP.Model() # ... create second model that has more variables than model1 # and also shares variable names with model1 x2 = all_variables(model2); for (n1,v) in d # this loop is very slow, like one variable/second x2_index = findfirst(n2 -> string(n2) == n1, x2) if !(isnothing(x2_index)) set_start_value(x2[x2_index], v) @info("Set start value for $(x2[x2_index])") end end
I also question if I am doing this correctly?