我无法在 OPL 脚本中访问数组的先前迭代值
I can not reach the array' s previous iteration values in OPL Script
我在 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();
}
}
而不是
tempX[iteration][i]= opl.X[i];
我会试试
tempX[iteration][i]= opl.X[i].solutionValue;
我在 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(); }
}
而不是
tempX[iteration][i]= opl.X[i];
我会试试
tempX[iteration][i]= opl.X[i].solutionValue;