Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Free Memory after solving a problem in OPL Script

    Posted 10/23/19 06:00 PM

    Originally posted by: naoseinao


    Hi there,

    I have an main opl file to run a model with different parameters. My problem is that I run out of memory, as oplrun apparently does not free up not used RAM sufficiently by default. It uses 10-15GB, but reserves more than double of that RAM, that by time (after a week or so) it runs out of memory. I could remove the already solved problems from my array to continue where it stopped, but I would prefer it running through, though. Reading the Knowledge Center I only found options to reduce the memory load. That is not what I am looking for, I look for an option to free the memory after finishing solving one problem or running into a time limit.

    Following an excerpt from my main.mod calling model.mod:

    // === MAIN ===
    
            var src = new IloOplModelSource("model.mod");
            var cplex = new IloCplex();
            var def = new IloOplModelDefinition(src);
    
            var filenameResults = "results.csv";
            var f = new IloOplOutputFile(filenameResults);
            f.close();
    
            for (var ci = 1; ci < thisOplModel.noOfClasses; ci++) { // int noOfClasses = 1; 
                    var param1 = thisOplModel.classes[ci][1]; // int classes[1..noOfClasses][1..2] = [...];
                    var param2 = thisOplModel.classes[ci][2];
            
                    for (var i = 1; i <= instances; i++) { // var instances = 100;
                            var opl = new IloOplModel(def, cplex);
                            var filename = param1 + "-" + param2 + "-" + i + ".dat";
                            var result = "\"(" + param1 + ", " + param2 + ")\";" + i;
                            writeOplConfig(readConfiguration(filename), filename);
                    
                            opl.addDataSource(new IloOplDataSource(folderOplData + filename));
                            opl.generate();
                            cplex.tilim = 3600; // Would a memory limit help to free up not anymore used memory?
                    
                            if (cplex.solve()) { 
                                    result = result + "," + cplex.getBestObjValue();
                                    if (cplex.getCplexStatus() == 1) {
                                            result = result + ",true";
                                    } else {
                                            result = result + ",false";
                                    }
                                    // Save Decision Variables in File
                                    var rf = new IloOplOutputFile(folderDecisionVars + filename);
                                    rf.writeln("obj = " + opl.obj);
                                    rf.writeln("a = " + opl.a);
                                    rf.writeln("b = " + opl.b);
                                    rf.close();
                                    
                            } else {
                                    writeln("No solution");
                                    result = result + ",n/a";
                            }
            
                            opl.end(); // Should free up used memory...
                            f = new IloOplOutputFile(filenameResults, true);
                            f.writeln(result);
                            f.close();
                    }
            }
    

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Free Memory after solving a problem in OPL Script

    Posted 10/25/19 04:27 AM

    Hi,

    the class IloOplModel has an "end" method that you could use

    regatds


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Free Memory after solving a problem in OPL Script

    Posted 10/26/19 08:11 PM

    Originally posted by: naoseinao


    Hi Alex,

    thank your for your quick response. 
    Please have a look at line 44 of my example. Shouldn't that already do the trick?

    Kind regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Free Memory after solving a problem in OPL Script

    Posted 10/27/19 09:22 AM

    Hi,

    if you use the IDE do not forget setting mainEndEnabled to true

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Free Memory after solving a problem in OPL Script

    Posted 10/29/19 01:22 PM

    Originally posted by: naoseinao


    Thanks. I actually call oplrun from the command line.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer