Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Concert C++ API: Memory usage when using the IloRange::getExpr() method.

    Posted 12/08/10 11:26 AM

    Originally posted by: DavidNLarsson


    Hi,

    I'm working on a Branch and Price implementation for large MILP. To locate fractional variables (and most of all, to find the 'best' fractional variable, by some definition of 'best') prone to branching, during the course of the branching procedure, several times over my program extracts expressions from constraints in the RMP model.

    During this procedure, I've noticed a small (~0.0007MB) increase in total memory usage every time the IloRange::getExpr() method is used. I've given an example below.

    Q: Is this memory use expected? Is there any way to free the memory used when invoking this method?

    TIA.

    Regards,
    David.

    (I'm using ILOG Concert Technology Version 2.9)

    // ------------------------------------------------------------------------------------
    // Small but unexpected memory usage when invoking the IloRange::getExpr() method.
    // ------------------------------------------------------------------------------------
     
    // libraries
    #include <ilcplex/ilocplex.h>
    ILOSTLBEGIN
     
    using namespace std;
     
    #define MEGA 1.0e6
    #define SOME_CONSTANT ...
     
    // main 
    int main (int argc, char **argv)
    {
            // create the optimization enviroment 
            IloEnv env;
     
            // no error catching for this simple example.. :)
     
            // create IloModel object associated with the optimization problem
            IloModel optModel(env);
     
            // some constrant
            IloRangeArray someConstraint(env);
     
            // some temporary expression
            
            // some counter
            IloInt t;
     
     
    /* Some operations on the model, defining variables, "filling" constraints etc. ... */
     
            // now, a loop where I for some reason want to extract - expression by expression - the
            // content of 'someConstraint':
            for (t = 0; t < SOME_CONSTANT; t++) {
     
                    env.out() << "memUsage = " << (env.getMemoryUsage())/MEGA << "MB, t = " << t << endl;
     
                    // get expression from specific constraint:
                    tempExpr = someConstraint[m].getExpr();
     
                    // Perform some operations ...
     
                    // clear tempExpr
                    tempExpr.clear();
            }
     
            // use method ::end() inherited from IloExtractable class 
            // to "free all the resources used by the invoking object".
            tempExpr.end()
     
            // QUESTION/PROBLEM:
            // In my actual program, a loop similar to the one above is called very many times.
            // For each iteration, I see an increase in memory use of 0.0006-00007MB. 
            // (No portion of this memory is returned after i use the end() method, probably as
            // the tempExpr has already been "cleared", ::clear().)
            // This leads to a heavy memory use in a much faster pace than expected.
            // Q: Is this normal and to be expected, a small memory usage when using the getExpr() method?
            // (If "A: Yes", I simply have to deter refrain an implementation as this, or is there any way
            // to get out off that slight mem-use?)
            
            // ...
            env.end();
            
            return 0;       
     
    } // END of main()
    

    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Concert C++ API: Memory usage when using the IloRange::getExpr() method.

    Posted 12/08/10 12:09 PM

    Originally posted by: SystemAdmin


    I checked it here. The same behavior. To cure that you have to do tempExpr.end() in the loop.
    This solves the problem.
    This means that tempExpr is actually a copy of the expression in the IloRange instance. This may seem unexpected at first glance but is perfectly meaningful as IloRange::getExpr() is declared 'const'.
    You can see that IloRange::getExpr() returns a copy by this:
    IloExpr expr = ...;
    std::cout << expr.getId() << std::endl;
    IloRange range(env, 0, expr, 1);
    std::cout << range.getExpr().getId() << std::endl;
    

    The two ids will be different! Also the getImpl() methods will return different things.
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Concert C++ API: Memory usage when using the IloRange::getExpr() method.

    Posted 12/08/10 01:02 PM

    Originally posted by: DavidNLarsson


    Thank you Daniel, that explained and solved the issue!

    In that context, does the line

    // clear tempExpr
    tempExpr.clear();
    


    have any function at all? (No compilation error/warnings, however)
    I don't quite know from where I got the idea that IloExpr objects have a ::clear() method, as I can't find any such method in the reference manual (albeit available for IloArray objects, in which context I've used it frequently).

    Also thanks again for previously proposing a linked data structure for when building my node tree structure, it turned out to help me alot later on on my project :)

    Regards,
    David.
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Concert C++ API: Memory usage when using the IloRange::getExpr() method.

    Posted 12/08/10 02:03 PM

    Originally posted by: SystemAdmin


    You are welcome :-)

    Indeed, the clear() function is not documented. It does something meaningful (though not in this context): It clears the expression. After calling this function the expression is empty. No more terms etc.
    #CPLEXOptimizers
    #DecisionOptimization