Skip to main content

Store optimized value into a list

Answered

Comments

2 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    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.
  • Jaromił Najman
    • Gurobi Staff

    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.