Skip to main content

Writing a Constraint using quicksum

Answered

Comments

4 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.
  • David Torres Sanchez
    • Gurobi Staff

    Hi Maxim,

    Please provide a Minimal Reproducible Example (MRE) showing what you have already done and the error you are observing.

    Cheers, 
    David

    0
  • Maxim Vodyan
    • Gurobi-versary
    • First Question
    • First Comment

    It takes a lot of time to build an MRE. C is an array of options that are predefined. x and y are boolean variables. I used this constraint:

    m.addConstrs((gp.quicksum(c[i][j] * x[(i, j)] for i in range(N)) <= c[k][j] * y[k] for k in range(N) for j in range(M)), name="Profit")

    Does it match this? 

    I get an error: Unable to retrieve attribute 'ObjVal'. Did you mean: 'ObjNVal', when trying to take the optimum value. I think that the solver cannot find the optimal solution, given the constraint.

    0
  • David Torres Sanchez
    • Gurobi Staff

    Hi Maxim,

    The constraint looks like it matches.
    The error you are getting may indicate that you need to call \(\texttt{m.optimize()}\) before trying to extract the solution.

    Cheers, 
    David

    0

Post is closed for comments.