Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
294 views
in Technique[技术] by (71.8m points)

optimization - 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();
    
     } 
    

    }

question from:https://stackoverflow.com/questions/65865475/i-can-not-reach-the-array-s-previous-iteration-values-in-opl-script

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Instead of

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

I would try

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...