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