Store optimized value into a list
AnsweredHi all,
I wan to the store the objective value in a list, since I iterate the solver in a loop. I don't how to do that.
my code:
for i in range(10):
# update model, solve, return the chromatic number
m.update()
m.optimize()
chrom_num = m.objVal
print("chromatic number of this graph is ", m.objVal)
chrom_list = []
chrom_list.append(chrom_num)
chrom_3 = np.asarray(chrom_list[i])
m.reset()
print(chrom_3.shape)
Thanks in advance!
0
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
Hi Nahom,
Why exactly do you need the \(\texttt{chrom_list}\) object? You could just directly pass the objective value to your chrom_3 array.
for i in range(10):
# update model, solve, return the chromatic number
m.update()
m.optimize()
chrom_num = m.objVal
print("chromatic number of this graph is ", m.objVal)
chrom_3 = np.asarray(chrom_num)
m.reset()
print(chrom_3.shape)If you need the \(\texttt{chrom_list}\), you should define it outside of the loop
chrom_list = []
for i in range(10):
# update model, solve, return the chromatic number
m.update()
m.optimize()
chrom_num = m.objVal
print("chromatic number of this graph is ", m.objVal)
chrom_list.append(chrom_num)
chrom_3 = np.asarray(chrom_list[i])
m.reset()
print(chrom_3.shape)Best regards,
Jaromił0
Post is closed for comments.
Comments
2 comments