Topic
• 4 replies
• Latest Post - ‏2016-01-05T14:26:22Z by m_adel
1883 Posts

# Pinned topic How to extract 3-D arrays (CPLEX + C++)

‏2013-01-01T15:34:58Z |
Hello,

I have one 2D and one 3D boolean arrays that I defined as:

``````
typedef IloArray<IloBoolVarArray> ArrayVar2D; typedef IloArray<IloArray<IloBoolVarArray> > ArrayVar3D;```
```

and

``````
IloEnv env; IloModel model(env); IloCplex cplex(env);```
```

and

``````
ArrayVar2D yir (env, 10); ArrayVar3D wijr (env, 10);

for (

int a=0; a<10; a++)
{ xij[a] = IloBoolVarArray(env, 10); yir[a] = IloBoolVarArray(env, 10); wijr[a] = ArrayVar2D(env, 10);

for (

int b=0; b<10; b++)
{ wijr[a][b] = IloBoolVarArray(env, 10);
}
}```
```

It compiles, and CPLEX solves the model. My Problem: when I try to get the values. The code:

``````

for (

int b=0; b<10; b++)
{

for (

int a=0; a<10; a++)
{ cout <<
"\t" << cplex.getValue(yir[b][a]);
} cout << endl;
}```
```

Works fine. But I couldn't get the results from the 3D matrix. The code:

``````

for (

int c=0; c<10; c++)
{ cout <<
"c="<<c<<endl;

for (

int b=0; b<10; b++)
{ cout <<
" "<<b;

for (

int a=0; a<10; a++)
{ cout <<
"\t" << cplex.getValue(wijr[b][a][c]);
} cout << endl;
}
}```
```

Gives me:

``````
Error: IloExtractable 11 IloNumVarI has not been extracted by IloAlgorithm 0x9848ab0```
```

Does anyone have any idea?

Thanks!!!
Updated on 2013-01-06T17:33:50Z at 2013-01-06T17:33:50Z by SystemAdmin
1883 Posts

#### Re: How to extract 3-D arrays (CPLEX + C++)

‏2013-01-06T17:33:50Z
This error occurs if you attempt to query the value of a variable that is not part of the model, i.e., the variable does not appear in the objective function or any constraint.
You should double-check that all variables in the 3D array actually appear somewhere in the model.
You can explicitly add the variables to the model:
```for (int c=0; c<10; c++) {
for (int b=0; b<10; b++) {
for (int a=0; a<10; a++) {
}
}
}
```

When you do that you can query any of the variables in the 3D array and should no longer get that error.
Updated on 2014-03-26T05:51:25Z at 2014-03-26T05:51:25Z by iron-man
2 Posts

#### Re: How to extract 3-D arrays (CPLEX + C++)

‏2016-01-04T17:54:24Z

Hi,

I have a sort of similar problem with a 3d array. I would appreciate if you could give me a hint. I have defined my 3d array as follows:

typedef IloArray<IloNumVarArray>  IloNumVarArray2;
typedef IloArray<IloNumVarArray2>  IloNumVarArray3;

IloNumVarArray3 x2(env);
for(ii=0;ii<SampSize;ii++){
for (i = 0; i < N_Path; i++) {
}
}

Then I get the following error:

Unhandled exception at 0x00828680 in Simple Test.exe: 0xC0000005: Access violation at location 0x0000000000828680.

I can see that the problem is related to the definition of my array but can not detect the problem with it. I would be thankful if you give me a hint.

Thanks,

• DanielJunglas
78 Posts

#### Re: How to extract 3-D arrays (CPLEX + C++)

‏2016-01-05T06:54:29Z
• ‏2016-01-04T17:54:24Z

Hi,

I have a sort of similar problem with a 3d array. I would appreciate if you could give me a hint. I have defined my 3d array as follows:

typedef IloArray<IloNumVarArray>  IloNumVarArray2;
typedef IloArray<IloNumVarArray2>  IloNumVarArray3;

IloNumVarArray3 x2(env);
for(ii=0;ii<SampSize;ii++){
for (i = 0; i < N_Path; i++) {
}
}

Then I get the following error:

Unhandled exception at 0x00828680 in Simple Test.exe: 0xC0000005: Access violation at location 0x0000000000828680.

I can see that the problem is related to the definition of my array but can not detect the problem with it. I would be thankful if you give me a hint.

Thanks,

The problem is that x2[ii] is never initialized. I think the correct initialization is this:

```IloNumVarArray3 x2(env);
for(ii=0;ii<SampSize;ii++){
for (i = 0; i < N_Path; i++) {
}
}
```

2 Posts

#### Re: How to extract 3-D arrays (CPLEX + C++)

‏2016-01-05T14:26:22Z

The problem is that x2[ii] is never initialized. I think the correct initialization is this:

<pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">IloNumVarArray3 x2(env); for(ii=0;ii<SampSize;ii++){ x2.add(IloNumVarArray2(env)); for (i = 0; i < N_Path; i++) { x2[ii].add(IloNumVarArray(env,full_depth, 0.0,1.0,ILOINT)); } } </pre>

Hi Daniel,

Thank you so much I see your point. I solved it with another similar definition as bellow:

```    IloNumVarArray3 x2(env,SampSize);
for(ii=0;ii<SampSize;ii++){
x2[ii]= IloNumVarArray2(env, N_Path);
for (i = 0; i < N_Path; i++) {
x2[ii][i]=IloNumVarArray(env,full_depth);
for(j=0;j<full_depth;j++){
x2[ii][i][j]= IloNumVar(env, 0.0, 1.0, ILOINT);
}
}
}
```