Search code examples
arraysoptimizationcplexopl

I can not reach the array' s previous iteration values in OPL Script


I have a MIP model in CPlex.

  • In each iteration I use different .dat files and solve the problem.

  • I hold the decision variable solution values in a multi dimensional array like "Array[iteration][i]", "i" is the decision variable's index and iteration represent the different instances(different .dat files).

  • I want to reach "Array[1][i]" when "iteration = 2", it says "Array[1][i]= [a IloNumVar]".

         main{
             for(var datFile in thisOplModel.datFiles) {
             iteration+=1;
             var opl = new IloOplModel(def,cplex);       
             var data= new IloOplDataSource(datFile);
             opl.addDataSource(data);
             opl.generate(); 
             tempX[iteration]= new Array();
             tempY[iteration]= new Array();
    
             for(var i =1; i_node<=node; i ++){
    
                 tempX[iteration][i]= new Array();
                 tempY[iteration][i]= new Array();
    
                 if (iteration==1){      
                     cplex.solve()
                     tempX[iteration][i]= opl.X[i];  
                     //When I want to print temp[1][i] values at iteration is equal to 1, it print the values.
                     writeln("tempX: ", tempX[1][i]); 
    
                }
             }       
    
             if (iteration==2){
                 for(var i_node=1; i_node<=node; i_node++){  
                 //When I am at iteration 2, i want to reach previous iteration values but it brings "[a IloNumVar]"  
                     writeln("tempX: ", tempX[1][i]);
                 }
             }   
    
        opl.end();
    
     } 
    

    }


Solution

  • Instead of

    tempX[iteration][i]= opl.X[i];
    

    I would try

    tempX[iteration][i]= opl.X[i].solutionValue;