简体   繁体   中英

Gurobi model Heap has been corrupted

I am using Gurobi (9.0.3) C API to build a LP model and change the constraints to get different objective value. However, sometimes when I run the code, there is error about "triggered the breakpoint" and "heap has been corrupted" where I marked below. I noticed that the heap will be corrupted if memory is wrongly assigned, but I am not sure what to change with the model.

There are three functions in my code, first I will use constructLPmodel() to build original model and get the result using getSol_LP(). After that, updateLP() will be called several (100+) times to change constraints and get the result.

GRBenv *LPenv = NULL;
GRBmodel  *LPmodel = NULL;
double LPobjectiveValue;

double constructLPmodel()
{
    GRBloadenv(&LPenv, "LP.log");
    GRBnewmodel(LPenv, &LPmodel, "LP", 0, NULL, NULL, NULL, NULL, NULL); //breakpoint sometimes lies here
    
   // create variables and constraints

    getSol_LP();

    return LPobjectiveValue;
}

double updateLP()
{
    int error = 0;

    error = GRBupdatemodel(LPmodel); // breakpoint sometimes lies here
    if (error) printf("Error in updating model\n");

    getSol_LP();

    return LPobjectiveValue;
}
void getSol_LP()
{
    int error = 0;
    double objVal;

    GRBoptimize(LPmodel); // breakpoint sometimes lies here
    GRBwrite(LPmodel, "LP.lp"); // breakpoint sometimes lies here
    GRBwrite(LPmodel, "LP.sol");

    error = GRBgetdblattr(LPmodel, GRB_DBL_ATTR_OBJVAL, &objVal);
    if (error) goto QUIT;

    LPobjectiveValue = objVal;
}

This sounds like a hardware issue. Maybe something is wrong with your memory. Have you tried reproducing this on another machine? Do you have a stack trace of the error, showing where it happens?

Without a (minimal) reproducible example, there is not much we can do to help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM