我目前正在为运筹学中的任务实施this model,我发现了一些我认为与变量定义有关的问题。我阅读并观看了很多关于如何实现3D矩阵的参考资料,但我仍然遇到同样的错误,不知道我还能做些什么来解决它。
我得到的错误是this one:
Empty Handle in IloArray::operator[]
ConcertTest: /opt/ibm/ILOG/CPLEX_Studio1261/concert/include/ilconcert/iloenv.h:2232:
X& IloArray<X>::operator[](IloInt) [with X= IloNumArray;
IloInt = long int]: Assertion '(_impl) || (std:: cerr << "Empty Handle in IloArray::operator[]"
<< std:: endl, ilo_stop_assert())' faield.
Aborted (core dumped)
Process returned 134 (0x86) execution time: 0.094 s
变量的代码如下:
using namespace std;
int main()
{
IloEnv env;
try{
IloModel model(env);
IloExpr obj(env);
IloRangeArray constraints(env);
// Defining the type of arrays
typedef IloArray< IloArray<IloNumVarArray> > IloNumVarArray3;
typedef IloArray< IloArray<IloNumArray> > IloNumArray3;
typedef IloArray<IloNumArray> IloNumArray2;
// Creating the variables
IloInt N = 10;
IloInt J = 10;
IloInt W = 3;
IloNumVarArray3 x_iwj(env, N);
IloNumArray3 c_iwj(env, N);
IloNumArray3 ce_iwj(env, N);
IloNumArray3 cb_iwj(env, N);
IloNumArray2 cap_iw(env, N);
IloNumArray dem_j(env, J);
// Definig the variables
for(int i = 0; i < N; i++){
for(int w = 0; w < W; w++){
x_iwj[i][w].add(IloNumVarArray(env, N, 0, IloInfinity, ILOINT));
c_iwj[i][w] = IloNumArray(env, N);
ce_iwj[i][w] = IloNumArray(env, N);
cb_iwj[i][w] = IloNumArray(env, N);
for(int j = 0; j < J; j++){
if(i == 0 && w == 2){
c_iwj[i][w][j] = 100;
}
else{
c_iwj[i][w][j] = 10; //rand() % 10;
}
ce_iwj[i][w][j] = 0.5; //rand() % 1;
cb_iwj[i][w][j] = 0.4; //rand() % 1;
}
}
}
for(int i = 0; i < N; i++){
cap_iw[i] = IloNumArray(env, N);
for(int w = 0; w < W; w++){
cap_iw[i][w] = 150; //rand() % 150;
}
}
for(int j = 0; j < J; j++){
dem_j[j] = 480; //rand() % 500;
}
...
它也可能与代码的其他部分有关,所以如果有必要我可以把它放在这里。
提前非常感谢!