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

Unable to retrieve attribute 'x' error

回答済み

コメント

4件のコメント

  • Jaromił Najman
    • Gurobi Staff

    Hi Mert,

    Is a feasible solution available at the point of executing the code snippet you provided? In other words, did you run the optimize() method and Gurobi did find at least one feasible solution point before trying to access the X attribute?

    You could implement a safe guard

    if model.SolCount > 1:
     for i in warehouse:
    for j in customers:
    for k in years:
    if z[i,j,k].x > 0.5:
    print("AAA")
    else:
    print("No feasible solution available")

    If the above does not help, please provide a minimal reproducible example resulting in the error.

    Best regards, 
    Jaromił

    0
  • Mert Eroglu
    • Gurobi-versary
    • Conversationalist
    • First Question

    Hello, thanks for your fast support. I implemented your codes into mine and printed:  "No feasible solution available". Therefore why .x is not being used in my code, result i didn't understand that part. You can find a part of example below.

    I have more constraints, but the outcome is infeasible despite commenting out my constraints.

    When i run with constraints, my code gives an error at the first line with ".x".

    Thanks.

     

    x = {}
    for i in warehouses:
        for j in customers:
            for k in years:
                x[i,j,k] = m.addVar(vtype=GRB.BINARY, name="x_%d_%d_%d" % (i, j,k))

     

    z = {}
    for i in warehouses:
        for j in customers:
            for k in years:
                z[i,j,k] = m.addVar(vtype=GRB.BINARY, name="z_%d_%d_%d" % (i,j,k))

     

    for i in warehouses:

      for j in customers:
             for k in years:
                  if z[i,j,k].x > 0.5:
                      print("Customer", j, "will be switched in year",k)

    0
  • Jaromił Najman
    • Gurobi Staff

    I have more constraints, but the outcome is infeasible despite commenting out my constraints.

    In this case, please refer to the Knowledge Base article How do I determine why my model is infeasible?

    When i run with constraints, my code gives an error at the first line with ".x".

    Just to make sure, do you call optimize() before trying to access the X attribute? It is not present in your code snippet.

    0
  • Mert Eroglu
    • Gurobi-versary
    • Conversationalist
    • First Question

    I was getting the error despite calling optimize(), i guess there was a problem with my constraints. But i used another approach for my problem, for now.

    Thanks for your support.

    0

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