Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  free memory issue

    Posted 12/30/10 01:51 AM

    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


  • 2.  Re: free memory issue

    Posted 12/30/10 02:48 AM

    Originally posted by: victortkl


    here is the code
    
    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(); 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.demand[sa][t]!=0) 
    { lefttmp[count][simite]=simmodel.left[sa][t]; right[count]=simmodel.right[sa][t]; count=count+1; 
    } 
    } 
    } 
    } 
    
    else 
    { writeln(
    "no solution"); 
    } 
    //get the sum 
    
    for( var sat=1;sat<=numall;sat++) 
    { lefttmpall[sat]=lefttmpall[sat]+lefttmp[sat][simite]; 
    } simmodel.end(); cplex.end(); 
    } 
    //after each scenario 
    //get avg 
    
    for(  sat=1;sat<=count-1;sat++) 
    { leftavg[sat]=lefttmpall[sat]/big_sce; 
    } 
    //get std 
    
    for ( sat=1; sat<=count-1;sat++) 
    { var tmp=0; 
    
    for (var itesce=1;itesce<=big_sce;itesce++) 
    { tmp=tmp+(leftavg[sat]-lefttmp[sat][itesce])* ((leftavg[sat]-lefttmp[sat][itesce])); 
    } tmp=tmp/(big_sce-1); leftstd[sat]=Opl.sqrt(tmp); 
    } 
    //get z 
    
    for ( sat=1; sat<=count-1;sat++) 
    { 
    
    if (leftstd[sat]!=0) 
    { z[sat]=(right[sat]-leftavg[sat])/leftstd[sat]; writeln(
    "z("+sat+
    "):"+z[sat]); 
    } 
    } 
    }
    

    #DecisionOptimization
    #OPLusingCPLEXOptimizer