Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  how to deal bad allocation exception?

    Posted 06/20/11 08:23 AM

    Originally posted by: rourou


    i am using CP Optimizer V2.3 to solve a fesibility problem. When the amount of feasible solution exceed about 200,000, it threw Standard exception: bad allocation

    the main code is below:

    IloModel model(env);
    IloCP cp(model);
    .......
    cp.startNewSearch();
    while(cp.next())
    {
    ......
    }

    cp.end();

    When the amount of while iteration exceed about 200,000, it threw Standard exception: bad allocation .
    How to allocate more memory to this computation?
    #CPOptimizer
    #DecisionOptimization


  • 2.  Re: how to deal bad allocation exception?

    Posted 06/20/11 10:26 AM

    Originally posted by: SystemAdmin


    Hello,
    I think the first think to do is to check that the memory is indeed consumed by CP Optimizer. If you have not done it, you should try printing the CP Optimizer memory usage in the loop and have a look at the memory consumed by CP Optimizer before the exception is thrown:

    
    IloModel model(env); IloCP cp(model); ....... cp.startNewSearch(); 
    
    while(cp.next()) 
    { cp.out() << 
    "Memory usage: " << cp.getInfo(IloCP::MemoryUsage) << endl; ...... 
    } cp.end();
    


    If the memory used by CP Optimizer really is the reason for the memory exception, then the answer may depend on what exactly you are doing with the solutions (example: only count them or store them somewhere for some future use). In this case, one thing you could consider doing is to partition the solution space by solving several models that consist of the original model plus some partitioning constraints like (x<=k / x>k).

    Philippe
    #CPOptimizer
    #DecisionOptimization


  • 3.  Re: how to deal bad allocation exception?

    Posted 06/20/11 10:36 PM

    Originally posted by: rourou


    thank you very much

    when the memory usage reached 3647572, the number didn't change for many iteration. Then the exception is thrown.

    So I have to partition the solution space?
    #CPOptimizer
    #DecisionOptimization


  • 4.  Re: how to deal bad allocation exception?

    Posted 06/21/11 04:39 AM

    Originally posted by: SystemAdmin


    If the peak memory used by CP Optimizer is 3647572 bytes, that is quite few and cannot explain the memory problem I think. Do you allocate something inside the while loop (for instance, store the solution somewhere, ...) ?
    You could also try to see if the memory problem happens inside the cp.next() or inside the while loop by printing something when entering and leaving the while section:

    
    IloModel model(env); IloCP cp(model); ....... cp.startNewSearch(); 
    
    while(cp.next()) 
    { cp.out() << 
    "Memory usage: " << cp.getInfo(IloCP::MemoryUsage) << endl; cp.out() << 
    "Entering section" << endl; ...... cp.out() << 
    "Leaving section" << endl; 
    } cp.end();
    


    Philippe
    #CPOptimizer
    #DecisionOptimization


  • 5.  Re: how to deal bad allocation exception?

    Posted 06/21/11 05:40 AM

    Originally posted by: rourou


    Yes, I will show you the full code

    IloModel model(env);
    IloCP cp(model);
    .......
    list<int> minX;
    list<list<int>> all_minX;
    cp.startNewSearch();
    while(cp.next())
    {
    minX.clear();
    for(i = 0 ;i < m; i ++)
    {
    cp.getValue(xk[i]);

    if(fabs(tp) < 0.0001)
    tp = 0;

    if(tp > 0)
    {
    if((fabs(tp) - (int)(tp+0.5)) < 0.0001)
    tp = (int)(tp+0.5);
    }

    else if(tp < 0)
    {
    if((fabs(tp) - (int)(tp-0.5)) < 0.0001)
    tp = (int)(tp-0.5);
    }

    minX.push_back(tp);
    }

    }
    cp.end();
    #CPOptimizer
    #DecisionOptimization


  • 6.  Re: how to deal bad allocation exception?

    Posted 06/21/11 05:44 AM

    Originally posted by: rourou


    the above thread is not right

    IloModel model(env);
    IloCP cp(model);
    .......
    list<int> minX;
    list<list<int>> all_minX;
    cp.startNewSearch();

    while(cp.next())
    {
    minX.clear();

    for(i = 0 ;i < m; i ++)
    {
    minX.push_back(cp.getValue(x[i]));
    }

    all_minX.push_back(minX);

    }
    cp.end();
    #CPOptimizer
    #DecisionOptimization


  • 7.  Re: how to deal bad allocation exception?

    Posted 06/21/11 06:49 AM

    Originally posted by: SystemAdmin


    So I do not know what is the size m of the model, but it seems that the memory is mostly used to store the solutions in your lists all_minX. Isn't it that it just takes too much memory to store all the solutions?

    Philippe
    #CPOptimizer
    #DecisionOptimization


  • 8.  Re: how to deal bad allocation exception?

    Posted 06/21/11 07:18 AM

    Originally posted by: rourou


    yes you are quite right

    I delete the all_minX.push_back() and output the solution in a txt file, the exception is gone

    thanks you very much.
    #CPOptimizer
    #DecisionOptimization