Skip to main content

Model status returns GRB_LOADED

Answered

Comments

10 comments

  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    Hi,

    The status \(\texttt{GRB_LOADED}\) means that there is a model at hand, because, e.g., a model has been read in from a file or constructed manually, but no call to the GRBoptimize method has been performed yet.

    Best regards,
    Jaromił

    0
  • Yuyi Zhong
    Gurobi-versary
    Conversationalist
    First Question

    Hi,

    Thanks, but I am actually solving a multi-scenario model https://www.gurobi.com/documentation/9.0/refman/definition_of_a_multi_scen.html.,

    where a single call to the standard Gurobi optimize method is all that is needed to solve all scenarios. 

    I called GRBoptimize once and get "GRB_OPTIMAL" for other scenarios, but why one scenario returns me "GRB_LOADED"?

     

    0
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    If a model is solved via \(\texttt{optimize}\), it does not matter what type of model it is, i.e., it does not matter whether it is a multi-scenario model or not. If a model has not been solved yet, then the model status is \(\texttt{GRB_LOADED}\). Do you mean that you are trying to retrieve the status of each scenario of a multi-scenario model? Could you please share a reproducible example and a LOG file showing this issue?

    Best regards,
    Jaromił

    0
  • Yuyi Zhong
    Gurobi-versary
    Conversationalist
    First Question

    I am trying to retrieve the ObjVal for each scenario, but I had "Gurobi error: Unable to retrieve attribute 'ScenNObjVal'" for one of the scenarios. After checking, I find that the model status for the failed scenario is GRB_LOADED.

    Please allow me some time to get the example code and LOG file, thanks.

     

     

     

     

    0
  • Yuyi Zhong
    Gurobi-versary
    Conversationalist
    First Question

    Hi,

    The overall code is very long, I provided the skeleton, where I create multiple scenarios with the different objective functions (the objective function in base model is 0), then call GRBupdatemodel, finally retrieve the ScenNObjVal for each scenario.

    int var_ind_record[MAX_ITER+2]; //assume that the list has been assigned
    error = GRBsetintattr(model, "NumScenarios", MAX_ITER*3);
    handle_gurobi_error(error, env);
    error = GRBupdatemodel(model);
    handle_gurobi_error(error, env);
    for(j=0; j < MAX_ITER; j++){
    int index1 = var_ind_record[j];
    int index2 = var_ind_record[j+1];
    int index3 = var_ind_record[j+2];
    // Compute z1 + z3
    error = GRBsetintparam(GRBgetenv(model), "ScenarioNumber", j*3);
    handle_gurobi_error(error, GRBgetenv(model));
    error = GRBsetdblattrelement(model, "ScenNObj", index3, 1.0);
    error = GRBsetdblattrelement(model, "ScenNObj", index1, 1.0);
    handle_gurobi_error(error, env);
    error = GRBupdatemodel(model);
    handle_gurobi_error(error, env);
    // Compute z2 + z3
    error = GRBsetintparam(GRBgetenv(model), "ScenarioNumber", j*3+1);
    handle_gurobi_error(error, GRBgetenv(model));
    error = GRBsetdblattrelement(model, "ScenNObj", index3, 1.0);
    error = GRBsetdblattrelement(model, "ScenNObj", index2, 1.0);
    handle_gurobi_error(error, env);
    error = GRBupdatemodel(model);
    handle_gurobi_error(error, env);
    // Compute z1 + z2 + z3
    error = GRBsetintparam(GRBgetenv(model), "ScenarioNumber", j*3+2);
    handle_gurobi_error(error, GRBgetenv(model));
    error = GRBsetdblattrelement(model, "ScenNObj", index3, 1.0);
    error = GRBsetdblattrelement(model, "ScenNObj", index2, 1.0);
    error = GRBsetdblattrelement(model, "ScenNObj", index1, 1.0);
    handle_gurobi_error(error, env);
    error = GRBupdatemodel(model);
    handle_gurobi_error(error, env);
    }
    // Do the multi-scenario solving
    error = GRBsetintattr(model, "ModelSense", -1); //maximization
    handle_gurobi_error(error, env);
    error = GRBupdatemodel(model);
    handle_gurobi_error(error, env);
    error = GRBoptimize(model);
    handle_gurobi_error(error, env);
    error = GRBgetintattr(model, GRB_INT_ATTR_STATUS, &optimstatus);
    handle_gurobi_error(error, env);
    double solved_ub;
    for(j=0; j < MAX_ITER; j++){
    int index1 = var_ind_record[j];
    int index2 = var_ind_record[j+1];
    int index3 = var_ind_record[j+2];
    error = GRBsetintparam(GRBgetenv(model), "ScenarioNumber", 3*j);
    handle_gurobi_error(error, GRBgetenv(model));
    error = GRBgetintattr(model, GRB_INT_ATTR_STATUS, &optimstatus);
    handle_gurobi_error(error, env);
    error = GRBgetdblattr(model, "ScenNObjVal", &solved_ub);
    handle_gurobi_error(error, env);

    error = GRBsetintparam(GRBgetenv(model), "ScenarioNumber", 3*j+1);
    handle_gurobi_error(error, GRBgetenv(model));
    error = GRBgetintattr(model, GRB_INT_ATTR_STATUS, &optimstatus);
    handle_gurobi_error(error, env);
    error = GRBgetdblattr(model, "ScenNObjVal", &solved_ub);
    handle_gurobi_error(error, env);

    error = GRBsetintparam(GRBgetenv(model), "ScenarioNumber", 3*j+2);
    handle_gurobi_error(error, GRBgetenv(model));
    error = GRBgetintattr(model, GRB_INT_ATTR_STATUS, &optimstatus);
    handle_gurobi_error(error, env);
    error = GRBgetdblattr(model, "ScenNObjVal", &solved_ub);
    handle_gurobi_error(error, env);

    }
    0
  • Yuyi Zhong
    Gurobi-versary
    Conversationalist
    First Question

    The printed-out log information is given as followed, where you can see that "Scenario 12 has been solved. 0/49 scenarios left." So all the scenarios should have been solved, but I don't know why scenario 4 is "GRB_LOADED" and cannot retrieve attribute 'ScenNObjVal'. Thank you for your help!

    Academic license - for non-commercial use only
    Gurobi Optimizer version 9.0.0 build v9.0.0rc2 (linux64)

    Warning: excessive time spent in model updates.
    Consider calling update less frequently.

    Optimize a model with 2777 rows, 4004 columns and 442744 nonzeros
    Model fingerprint: 0x01e59090
    Variable types: 4004 continuous, 0 integer (0 binary)
    Coefficient statistics:
    Matrix range [1e-07, 2e+00]
    Objective range [1e+00, 1e+00]
    Bounds range [2e-04, 2e+01]
    RHS range [2e-04, 2e+00]

    Solving a multi-scenario model with 49 scenarios...

    Presolve removed 381 rows and 1290 columns
    Presolve time: 0.56s
    Presolved: 2511 rows, 2877 columns, 150518 nonzeros
    Variable types: 2828 continuous, 49 integer (49 binary)

    Root relaxation: objective 7.985614e-01, 1426 iterations, 0.71 seconds

    Nodes | Current Node | Objective Bounds | Work
    Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time

    0 0 0.79857 0 2 - 0.79857 - - 1s
    H 0 0 0.4968513 0.79857 60.8% - 1s
    H 0 0 0.5932906 0.79857 34.6% - 1s
    0 0 0.70217 0 2 0.59330 0.70217 18.4% - 2s
    0 0 0.69374 0 3 0.59330 0.69374 17.0% - 2s
    Scenario 47 has been solved. 48/49 scenarios left.
    Scenario 48 has been solved. 47/49 scenarios left.
    0 0 0.69107 0 4 0.59330 0.69107 16.5% - 3s
    0 0 0.69093 0 4 0.59330 0.69093 16.5% - 3s
    0 0 0.69021 0 4 0.59330 0.69021 16.4% - 3s
    Scenario 43 has been solved. 46/49 scenarios left.
    Scenario 45 has been solved. 45/49 scenarios left.
    0 0 0.69001 0 4 0.59330 0.69001 16.4% - 4s
    Scenario 44 has been solved. 44/49 scenarios left.
    0 0 0.68981 0 4 0.59330 0.68981 16.3% - 5s
    0 2 0.68981 0 4 0.59330 0.68981 16.3% - 11s
    Scenario 39 has been solved. 43/49 scenarios left.

    Optimal solution found at node 19 - now completing multiple scenarios...

    Nodes | Current Node | Scenario Obj. Bounds | Work
    | | Worst |
    Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time

    19 2 0.54867 10 2 - 0.54867 - 175 13s
    Scenario 38 has been solved. 42/49 scenarios left.
    Scenario 42 has been solved. 41/49 scenarios left.
    Scenario 18 has been solved. 40/49 scenarios left.
    Scenario 21 has been solved. 39/49 scenarios left.
    Scenario 27 has been solved. 38/49 scenarios left.
    Scenario 30 has been solved. 37/49 scenarios left.
    Scenario 35 has been solved. 36/49 scenarios left.
    Scenario 36 has been solved. 35/49 scenarios left.
    Scenario 14 has been solved. 34/49 scenarios left.
    Scenario 17 has been solved. 33/49 scenarios left.
    Scenario 19 has been solved. 32/49 scenarios left.
    Scenario 26 has been solved. 31/49 scenarios left.
    Scenario 33 has been solved. 30/49 scenarios left.
    Scenario 37 has been solved. 29/49 scenarios left.
    55 2 0.37685 28 2 - 0.37685 - 96.9 15s
    Scenario 31 has been solved. 28/49 scenarios left.
    Scenario 34 has been solved. 27/49 scenarios left.
    Scenario 24 has been solved. 26/49 scenarios left.
    Scenario 1 has been solved. 25/49 scenarios left.
    Scenario 15 has been solved. 24/49 scenarios left.
    Scenario 23 has been solved. 23/49 scenarios left.
    Scenario 25 has been solved. 22/49 scenarios left.
    Scenario 40 has been solved. 21/49 scenarios left.
    Scenario 0 has been solved. 20/49 scenarios left.
    Scenario 22 has been solved. 19/49 scenarios left.
    Scenario 28 has been solved. 18/49 scenarios left.
    Scenario 29 has been solved. 17/49 scenarios left.
    Scenario 3 has been solved. 16/49 scenarios left.
    Scenario 13 has been solved. 15/49 scenarios left.
    Scenario 16 has been solved. 14/49 scenarios left.
    Scenario 32 has been solved. 13/49 scenarios left.
    Scenario 41 has been solved. 12/49 scenarios left.
    Scenario 20 has been solved. 11/49 scenarios left.
    Scenario 10 has been solved. 10/49 scenarios left.
    Scenario 46 has been solved. 9/49 scenarios left.
    Scenario 2 has been solved. 8/49 scenarios left.
    Scenario 4 has been solved. 7/49 scenarios left.
    Scenario 5 has been solved. 6/49 scenarios left.
    Scenario 6 has been solved. 5/49 scenarios left.
    Scenario 7 has been solved. 4/49 scenarios left.
    Scenario 8 has been solved. 3/49 scenarios left.
    Scenario 9 has been solved. 2/49 scenarios left.
    Scenario 11 has been solved. 1/49 scenarios left.
    Scenario 12 has been solved. 0/49 scenarios left.

    Cutting planes:
    Gomory: 1
    MIR: 40
    RLT: 7

    Explored 87 nodes (9121 simplex iterations) in 16.27 seconds
    Thread count was 24 (of 24 available processors)

    Solution count 10: 0.593291 0.496852 0.472511 ... 0.407121
    No other solutions better than 0.593291

    Optimal solution found (tolerance 1.01e-04)
    Best objective 5.932905623862e-01, best bound 5.932905623862e-01, gap 0.0000%
    The solution status is 2
    The ScenarioNumber is 0, the solution status is 2
    The ScenarioNumber is 1, the solution status is 2
    The ScenarioNumber is 2, the solution status is 2
    The ScenarioNumber is 3, the solution status is 2
    The ScenarioNumber is 4, the solution status is 1 (GRB_LOADED)
    Gurobi error: Unable to retrieve attribute 'ScenNObjVal'
    0
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    Hi,

    Could you try updating to the latest version 9.5.0 ?

    If this does not help, could you generate an LP or MPS file of your model using the GRBwrite method and share it such that I can try to reproduce this behavior on my side?

    Best regards,
    Jaromił

    0
  • Yuyi Zhong
    Gurobi-versary
    Conversationalist
    First Question

    Hi,

    Thanks for your suggestion, but updating to 9.5.0 doesn't really help.

    I didn't see a button to attach files, how can I share lp and mps files to you? 

    Thanks and Regards,

    Yuyi

    0
  • Yuyi Zhong
    Gurobi-versary
    Conversationalist
    First Question

    Hi,

    I think I know the reason, I added new constraints to the model and updated the model before scenario 4.

    Since the base model is modified, scenario 4 returns "GRB_LOADED". I delayed my calling to

    GRBupdatemodel() function, now it works fine.
     
    Thank you so much for your patience and kind help!!
     
    Best regards,
    Yuyi
    0
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    Great to hear that your were able to solve the issue!

    0

Please sign in to leave a comment.