メインコンテンツへスキップ

Writing a Constraint using quicksum

回答済み

コメント

3件のコメント

  • 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

サインインしてコメントを残してください。