Hi.
I’m working with JuMP to solve a mathematical optimization problem. I’ve realized that when I use functions like copy(model) or methods to relax models, such as the code snippet below, the order of constraints and variables changes. However, I need to ensure that the order remains consistent in the new model.
for var in all_variables(model)
if is_integer(var)
unset_integer(var)
end
end
Is there a way to retain the order of constraints and variables when copying or modifying the model?
I checked it for different problems. For example, for the mps file in the below link:
link:https://file.io/l1v5hFinmNiQ
the model is:
model=read_from_file(path)
print(model)
min 318𝐶1+159𝐶2+159𝐶3+159𝐶4+114𝐶5+228𝐶6+1096
Subject to
𝐶2∈[0,3]
𝐶3∈[0,3]
𝐶4∈[0,3]
𝐶2∈ℤ
𝐶3∈ℤ
𝐶4∈ℤ
𝐶1∈{0,1}
𝐶5∈{0,1}
𝐶6∈{0,1}
But by implementing bellow code on this model:
function Relaxation(model)
relaxed_model = copy(model);
if JuMP._is_lp(relaxed_model)==false
relax_integrality(relaxed_model);
for var in all_variables(relaxed_model)
if is_integer(var)
unset_integer(var);
end
end
println("Relaxed");
else
print("Model Already is linear");
end
return relaxed_model
end
Relaxation(model)
order of constraint will be changed as below:
min 318𝐶1+159𝐶2+159𝐶3+159𝐶4+114𝐶5+228𝐶6+1096
Subject to
𝐶1≥0
𝐶5≥0
𝐶6≥0
𝐶1≤1
𝐶5≤1
𝐶6≤1
𝐶2∈[0,3]
𝐶3∈[0,3]
𝐶4∈[0,3]