Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Cplex.End() and memory leak

    Posted Wed August 14, 2013 09:39 AM

    Originally posted by: AlpD


    Hello,

    I am using Cplex 12.5 Concert Technology and coding in C#. I try to solve many LPs in a loop. For each LP, I create and end a cplex object. Although I added these;

    Cplex_obj.ClearModel();  Cplex_obj.EndModel();  Cplex_obj.End();

    after solving each LP, there is a continuous memory leak.

    What may be the reason for this? I was expecting EndModel() and End() methods to free memory, but they did not.

     I suspect the reason is something related with lacking "IloEnv" object and "IloEnv.End()" ? My rationale behind this thought is because of this topic:

    https://www.ibm.com/developerworks/community/forums/html/topic?id=bd735b43-f374-431a-8ab0-b2884f514690&ps=25

    I am actually in the same situation. However, since I code on C#, I do not use "IloEnv" class and as far as I know it is important in preventing from memory leaks. What can I do?

    Thanks in advance,

    Alper.


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Cplex.End() and memory leak

    Posted Thu August 15, 2013 03:11 AM

    In Concert Technology for Java or C# there is no IloEnv as there is no need for that.

    Calling Cplex_obj.End() should release all resources allocated for the cplex object (no need to call ClearModel() or EndModel()).

    Is Cplex_obj the only instance of the cplex class that you create? Or do you create other instances of this class? Maybe even outside the loop? Could you show us (an outline of) your code?


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Cplex.End() and memory leak

    Posted Thu August 15, 2013 01:40 PM

    Originally posted by: AlpD


    Thank you very much. Regarding your answer, I noticed an expression term (expr) of another Cplex instance (Cplex_obj_1) that I use in the loop. I give the outline of the code below:

     

    Cplex Cplex_obj_1= new Cplex();    //first Cplex instance

    INumExpr expr = Cplex_obj_1.NumExpr();  // expression of first Cplex instance

    for(…)      //for loop to solve each LP subproblem

    {

         Cplex Cplex_obj_2= new Cplex();     //second Cplex instance

             : //model construction

             :

         Cplex_obj_2.Solve();

         Cplex.Status status = Cplex_obj_2.GetStatus(); 

         if (status == Cplex.Status.Optimal)

        {

            for(…) for loop for i indice

             {

                  expr = Cplex_obj_2.Sum(expr, Cplex_obj_2.Prod(x[i],y));   //adding new expression terms to 'expr'

              }

       } //end if

     

    Cplex_obj_2.End();  

    }

     

    I think the critical point is adding on to 'expr' in the loop, because when I removed these lines from the code, memory did not leak. However, I need to sum up 

    expressions in each iteration (for loop iteration for each LP subproblem) and then use this 'expr' to create a cut for the master problem. 

    Could you help me, how can i do this task without a memory leak? Thank you in advance.

     

    Alper.

     

     

     

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Cplex.End() and memory leak

    Posted Fri August 16, 2013 08:13 AM

    Does it help to use Cplex_obj_1 instead of Cplex_obj_2 when summing up expr? I guess not?

    What are x and y? Are these arrays of double or arrays of INumVar? Were they allocated by Cplex_obj_1 or by Cplex_obj_2?

    Are you sure that you are actually leaking memory or may it be that the expression stored in expr just gets very big?


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Cplex.End() and memory leak

    Posted Sun August 18, 2013 04:09 PM

    Originally posted by: AlpD


    Thank you very much.

    After a careful examination, I noticed that the expression gets really big therefore the memory usage becomes so high by the iterations. It seems there is no memory leak actually. Now, I wonder whether I can do something to reduce memory usage for the expr or not?

    x[i] are arrays of INumVar (allocated by Cplex_obj_1) and y are double coefficients. And also I add double constants to the expr. 

    I appreciate your help.

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Cplex.End() and memory leak

    Posted Mon August 19, 2013 12:56 AM

    Since the expr you build is just a weighted sum over the x[i], you could store and update this sum in an instance of IDictionary (x[i] as key, their coeffcients as values) instead of an instance of INumExpr. At the point at which you need an INumExpr instance you just create an instance of ILinearNumExpr and call ILinearNumExpr.addTerm() for each element stored in the IDictionary.


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Cplex.End() and memory leak

    Posted Mon August 26, 2013 11:46 AM

    Originally posted by: AlpD


    Thank you very much for your suggestion, it seems very viable. I will try it.

    Best regards.


    #CPLEXOptimizers
    #DecisionOptimization