Originally posted by: victortkl
i write the code to iterate the program. i use end() to free the memory
but when i use end() method, the array created in the script becomes undefined after each iteration. this array is not defined in the model. but it's freed. what shall i do?
the code is listed below.
if i use at least one of the simmodel.end() , cplex.end(), the lefttmp array was freed. but if i do not use this method, the program will be out of memory.
how can i do to free the model's memory but keeps the array?
main
{
var big_sce=200;
var source2 = new IloOplModelSource("sim_demand_base.mod");
var cplex2 = new IloCplex();
var def2 = new IloOplModelDefinition(source2);
var optmodel = new IloOplModel(def2,cplex2);
datafile2= new IloOplDataSource("sim_demand_base.dat");
datasce2 = new IloOplDataElements();
datasce2.numm = 2;
optmodel.addDataSource(datasce2);
optmodel.addDataSource(datafile2);
optmodel.generate();
var numsa=Opl.card(optmodel.sitepro);
var numt=Opl.card(optmodel.nperiod);
var numall=numt*numsa;
var lefttmp= new Array(); //this memory was freed after calling simmodel.end() or cplex.end()
var lefttmpall= new Array();
var leftavg=new Array();
var leftstd=new Array();
var right=new Array();
var z=new Array();
//initialization
for (var i=1;i<=numall;i++)
{
lefttmp[i]=new Array();
lefttmpall[i]=0;
leftavg[i]=0;
leftstd[i]=0;
right[i]=0;
z[i]=0;
for (var j=1;j<=big_sce;j++)
{
lefttmp[i][j]=0;
}
}
for (var simite=1;simite<=200;simite++)
{
var source = new IloOplModelSource("sim_demand_base.mod");
var cplex = new IloCplex();
var def = new IloOplModelDefinition(source);
var simmodel = new IloOplModel(def,cplex);
datafile= new IloOplDataSource("sim_demand_base.dat");
datasce = new IloOplDataElements();
datasce.numm = simite;
simmodel.addDataSource(datasce);
simmodel.addDataSource(datafile);
simmodel.settings.mainEndEnabled = true;
simmodel.generate();
simmodel.settings.mainEndEnabled = true;
if (cplex.solve())
{
//get the original data
writeln("ite:"simite":\t"+cplex.getObjValue());
var count=1;
for (var t in simmodel.nperiod)
{
for (var sa in simmodel.sitepro)
{
if(optmodel.demandsa[t]!=0)
{
lefttmpcountsimite=simmodel.leftsa[t];
rightcount=simmodel.rightsa[t];
count=count+1;
}
}
}
}
else
{
writeln("no solution");
}
//get the sum
for( var sat=1;sat<=numall;sat++)
{
lefttmpallsat=lefttmpallsat+lefttmpsatsimite;
}
simmodel.end();
cplex.end();
}
//after each scenario
//get avg
for( sat=1;sat<=count-1;sat++)
{
leftavgsat=lefttmpallsat/big_sce;
}
//get std
for ( sat=1; sat<=count-1;sat++)
{
var tmp=0;
for (var itesce=1;itesce<=big_sce;itesce++)
{
tmp=tmp+(leftavgsat-lefttmpsatitesce)*
((leftavgsat-lefttmpsatitesce));
}
tmp=tmp/(big_sce-1);
leftstdsat=Opl.sqrt(tmp);
}
//get z
for ( sat=1; sat<=count-1;sat++)
{
if (leftstdsat!=0)
{
zsat=(rightsat-leftavgsat)/leftstdsat;
writeln("z("sat"):"+zsat);
}
}
}
<\code>#DecisionOptimization#OPLusingCPLEXOptimizer