Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Error on IloExpr 's end() function call that is supposed to free allocated memory

    Posted 10/24/14 11:38 AM

    Originally posted by: UserCplex


    Hello,

    I have a model for which I instantiate all components as follows:

    IloEnv env1;
    IloModel model1(env1);
    IloCplex cplex1(model1);
    IloExpr objective1(env1);
    IloObjective obj1(env1,objective1,IloObjective::Minimize);
    IloRangeArray con1(env1);
    IloNumVarArray x1(env1, 100, 0, IloInfinity, ILOFLOAT);
    IloNumVarArray s1(env1, 100, 0, IloInfinity, ILOFLOAT);
    IloNumArray xans1(env1, 100);
    

    After doing what it is supposed to do, I free the memory associated with each of these objects as follows.

    xans1.end();
    s1.endElements(); s1.end();
    x1.endElements(); x1.end();
    con1.endElements(); con1.end();
    obj1.end();
    objective1.end();
    cplex1.end();
    model1.end();
    env1.end();
    

    However, the above code fails in the following line:

    objective1.end()
    

    The error is:

    Unhandled exception at 0x007424d0 in xxx.exe: 0xC0000005: Access violation at location 0x00000000007424d0.
    

     

    The specific code that seems to fail is in iloextractable.h:

    void end() {
        if ( _impl ){
            _impl->end();
            _impl = 0;//This line seems to be causing the problem.
        }
    }
    

     

    If I comment out the specific .end() command as below:

    //objective1.end(); Commenting out this line did not cause any problem
    

    the error does not crop up.

    Any ideas on what could be causing the exception?

    Thanks.


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Error on IloExpr 's end() function call that is supposed to free allocated memory

    Posted 10/27/14 05:03 AM

    This error usually means that you are calling end() twice on the same object. It looks as if you are doing something wrong with the objective1 object in the code you did not show here (the code between the constructors and destructors). Could you double-check what exactly you are doing with the objective1 object and if all of that is legal?


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Error on IloExpr 's end() function call that is supposed to free allocated memory

    Posted 10/27/14 11:06 AM

    Originally posted by: UserCplex


    Thank Daniel, for the suggestion. Hmm...I will go through the code carefully to figure out what is going on...


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Error on IloExpr 's end() function call that is supposed to free allocated memory

    Posted 10/28/14 01:41 AM

    Two things to note here:

    1. IloExpr instances are passed by value (see here), so it should be safe to call objective1.end() immediately after passing it to the IloObjective constructor. This is correct in general (unless you use that expression later) but may also help to nail down where things go wrong in your case.
    2. If you call env1.end() anyway then there is no need to explicitly end() all the other objects explicitly. They are all allocated on env1 and memory automatically be freed when env.end() is called.

    #CPLEXOptimizers
    #DecisionOptimization