Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Java API Cplex Creating multiple models

    Posted 02/07/15 04:12 AM

    Originally posted by: Mayda


    Hi,

     

    I am having trouble with creating multiple models in a Java program. JVM doesn't seem to free memory after solving a model. My code looks like this. Does anyone know what could be the problem? I also tried using only one IloCplex instance and modifying it every iteration but it didn't seem to work.

    Thank you for replies.

     

    class Test {

        public void buildModel(IloModeler model, ...other arguments.... ) throws IloException {

            ...

              Initialize objective

            ...
            IloObjective objective = model.minimize( .... );

            model.add(objective)

            ....

             Create expression for constraint

           .....
                
            IloConstraint constr = model.ge(expr, 1);
            model.add(constr);            
            }

        }

        /*
         Main function is used to execute the algorithm
         */
        public static void main(String[] args) {

            try {

               Test test = new Test();

                IloNumVarType varType = IloNumVarType.Float;

                int round = 1;
                for (; round <= 5; round++) {

                    for (int i = 0; i < 10; i++) {



                    IloCplex cplex = new IloCplex();

                       cplex.setParam(IloCplex.IntParam.RootAlg, 2);
                       cplex.setParam(IloCplex.DoubleParam.TiLim, 1000);


                        //Create variables you want to be optimized
                        IloNumVar[] weights = new IloNumVar[features];

                        IloNumVar bias = cplex.numVar(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);


                        //Build model
                        test.buildModel(cplex, tatData.trainingData, weights, bias, ...other arguments...);

                        //Trying to solve the model
                        cplex.solve();          
                        
                        cplex.clearModel();
                        cplex.end();

                    }
                }
            } catch (IloException ex) {
                System.out.println("Concert Error: " + ex);
            }
        }


    }
     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Java API Cplex Creating multiple models

    Posted 02/11/15 01:55 AM

    How exactly do you come to the conclusion that memory is not freed? The freed memory is not necessarily returned to the system. The JVM may keep it although it is currently not used to store any objects.

    Do you run out of memory eventually?

    Have you tried using tools like jhat to identify where memory goes?


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Java API Cplex Creating multiple models

    Posted 02/11/15 02:39 AM

    Originally posted by: Mayda


    No, I didn't use any tools. I run it on servers where I allocate some amount of memory, usually 100GB and I can monitor how much of memory is being used by my program. Creating one model takes around 80GB. Then I start creating next model and usage memory just keeps going up.


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Java API Cplex Creating multiple models

    Posted 02/11/15 06:57 AM

    Does it help to explicitly invoke the garbage collector after calling cplex.end()?

    Is the memory continuously growing? It is growing by a large amount? If the memory only grows by a small amount this may not necessarily be a leak.

    If you suspect a memory leak then I suggest to do the following:

    - Stop your program after calling cplex.end() (for example by doing a System.in.read())
    - Use jmap to create a snapshot of the heap at this point of time
    - Use jhat to investigate this heap dump

    Some instructions about that can for example be found here or here. If you find any unexpected CPLEX objects then there may be a leak in CPLEX. Otherwise there either is no leak or the leak is somewhere else.

    If you can construct a minimal example to reproduce this problem and attach that example here then I could also take a look at it.


    #CPLEXOptimizers
    #DecisionOptimization