Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

Why does cplex need so much mamory/ what do I do wrong

  • 1.  Why does cplex need so much mamory/ what do I do wrong

    Posted 01/21/16 11:06 AM

    Originally posted by: Namal


    Hello,

     

    I am using cplex to calculate solutions for a problem in which I set a pair of variables to 0 or 1.  So i have two for loops that run over all the variables and set the bonds for it.

    First I tried to use a single environment:

     

     

    IloEnv lp;
                    
                    try{
                            IloModel model(lp);
                            
                            IloNumVarArray var(lp);
                IloRangeArray con(lp);
          
                //adding problem 
                            
    
          
                 model.add(con);
    
                
                for(unsigned int i = 0; i<A.get_num_variables()-1;++i)
                for(unsigned int j = i+1; j<A.get_num_variables();++j){
            
            //for 00
            
                    var[i].setBounds(0,0);
                    var[j].setBounds(0,0);
    
    
                                    IloCplex cplex(model);
                                    cplex.setOut(lp.getNullStream());
                                    cplex.setParam(IloCplex::RootAlg, IloCplex::Dual);
                                    cplex.setParam(IloCplex::Param::MIP::Tolerances::MIPGap, 1.0);
                                    
                                    int solution = cplex.solve(); 
                                    
                                    if(!solution)...
                                    
                                    
                                   //for 01
                    var[i].setBounds(0,0);
                    var[j].setBounds(1,1);
                                    
                                    
                                    solution = cplex.solve(); 
                                    
                                    if(!solution)...
                                    
                                    //for 10
                                    var[i].setBounds(1,1);
                                    var[j].setBounds(0,0);
                                                            
                                    solution = cplex.solve(); 
                                    
                                    if(!solution)...
                                    
                                    
                                    //for 11
                    var[i].setBounds(1,1);
                    var[j].setBounds(1,1);
                                    
                                    solution = cplex.solve(); 
                                    
                                    if(!solution)...
                                    
    
                            //setting both variables back   
                    var[i].setBounds(0,1);
                    var[j].setBounds(0,1);
                            }
                    }
                    
                    catch (IloException &e) {
                            lp.error() << "Failed to optimize LP" << endl;
                            cerr << "Concert exception caught: " << e <<'\n';
                    } 
                    catch (...) {cerr << "Unknown exception caught" <<'\n';}
    lp.end();
    

    but this takes too much memory and is far slower than when i make that double for loop around one environment where I have to load my problem again and again. Do I forget to clear up the memory or why is it so slow?


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Why does cplex need so much mamory/ what do I do wrong

    Posted 01/27/16 05:23 AM

    Have tried calling cplex.end() at the end of the inner loop?

    As far as I can tell you are leaking an instance of IloCplex in each iteration. Moreover, 'model' is extracted to all these instances. Thus any modification of 'model' (for example changing the bounds of variables) has to be propagated to all those IloCplex instances. This may explain why things are so slow.


    #CPLEXOptimizers
    #DecisionOptimization