Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've encountered this issue before when running my linear programs. You must CREATE exactly one object and continue to use only one reference to that object.</p> <pre><code>import ilog.concert.*; import ilog.cplex.*; static public class Application { static public main(String[] args) { try { IloCplex cplex = new IloCplex(); // create model and solve it } catch (IloException e) { System.err.println("Concert exception caught: " + e); } } } </code></pre> <p>This issue is </p> <pre><code>IloCplex cplex = new IloCplex(); </code></pre> <p>Only call the above line once in your program. If the clearModel method isn't working, clear all your constraints, clear your objective function, and clear your cuts individually and then reset your constraints and objective function, but do not create a new object. That is what is causing the memory leak. To solve your new model, use </p> <pre><code>cplex.solve() </code></pre> <p>I imagine your code looks something like this</p> <pre><code>import ilog.concert.*; import ilog.cplex.*; public class Example { public static void main(String[] args) { try { for(int i = 1;i &lt;= 5;i++){ // Loop with indices that you may use to create your constraints and objective function. IloCplex cplex = new IloCplex(); // Cause of memory leak double[] lb = {0.0, 0.0, 0.0}; double[] ub = {40.0, Double.MAX_VALUE, Double.MAX_VALUE}; IloNumVar[] x = cplex.numVarArray(3, lb, ub); double[] objvals = {1.0, 2.0, 3.0}; cplex.addMaximize(cplex.scalProd(x, objvals)); cplex.addLe(cplex.sum(cplex.prod(-1.0, x[0]), cplex.prod( 1.0, x[1]), cplex.prod( 1.0, x[2])), 20.0); cplex.addLe(cplex.sum(cplex.prod( 1.0, x[0]), cplex.prod(-3.0, x[1]), cplex.prod( 1.0, x[2])), 30.0); if ( cplex.solve() ) { cplex.out().println("Solution status = " + cplex.getStatus()); cplex.out().println("Solution value = " + cplex.getObjValue()); double[] val = cplex.getValues(x); int ncols = cplex.getNcols(); for (int j = 0; j &lt; ncols; ++j) cplex.out().println("Column: " + j + " Value = " + val[j]); } cplex.end(); } } catch (IloException e) { System.err.println("Concert exception '" + e + "' caught"); } } } </code></pre> <p>Start your for or while loops after you create your instance of the IloCplex object. So, in contrast to the code above, do</p> <pre><code>IloCplex cplex = new IloCplex(); // Cause of memory leak for(int i = 1;i &lt;= 5;i++){ // Loop with indices that you may use to create your constraints and objective function. </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload