Skip to main content

Error in Setting Objective

Answered

Comments

2 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two 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 Prachi,

    The issue you encounter is because you are adding the variables to Model \(\texttt{m}\) instead of Model \(\texttt{linear}\). The variable addition step should read

    x = linear.addMVar(N, vtype=GRB.CONTINUOUS, lb=0, name='x')

    Moreover, the matrix returned by the getA method is already of type \(\texttt{scipy.sparse}\) in CSR format. Thus, you don't need the line where you convert it to an \(\texttt{np.array}\)

    linear = Model("LP")
    m = read("myLP.lp")
    B = m.getA()
    [...]
    linear.addMConstr(B, x, optr, b)

    Best regards, 
    Jaromił

    0

Post is closed for comments.