【问题标题】:I can not reach the array' s previous iteration values in OPL Script我无法在 OPL 脚本中达到数组的先前迭代值
【发布时间】:2021-01-23 23:13:34
【问题描述】:

我在 CPlex 中有一个 MIP 模型。

  • 在每次迭代中,我使用不同的 .dat 文件并解决问题。

  • 我将决策变量解值保存在一个多维数组中,例如“Array[iteration][i]”,“i”是决策变量的索引,迭代代表不同的实例(不同的 .dat 文件)。

  • 我想在“iteration = 2”时达到“Array[1][i]”,它显示“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();
    
     } 
    

    }

【问题讨论】:

    标签: arrays optimization cplex opl


    【解决方案1】:

    代替

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

    我会试试的

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

    【讨论】:

      猜你喜欢
      • 2019-03-25
      • 2019-04-01
      • 2014-09-08
      • 2022-11-23
      • 1970-01-01
      • 1970-01-01
      • 2018-09-18
      • 1970-01-01
      • 2023-03-09
      相关资源
      最近更新 更多