Hi Renaud,

Thanks for the reply.

For question 1, the simplified example is as follows:

```
//In *.mod file:
range t=2016..2031; //
{string} cost=...;
float Lifetimecost_est[ti in t][c in cost]=ti;
tuple Lifetimecost_tup{
int t;
string cost;
float value;
}
{Lifetimecost_tup} Lifetimecost_exp= {<i,j,Lifetimecost_est[i][j]> | i in t, j in cost};
execute {
writeln(Lifetimecost_tup,Lifetimecost_exp);
};
//In *.dat file
cost={purchase,maintanence,fuel,detour,range,wait,idio};
SheetConnection Outputs("C:\\Users\\jzhong17\\OneDrive - azureford\\Documents\\CPLEX\\OPL project\\Outputs.xlsx");
Lifetimecost_exp to SheetWrite(Outputs,"Test!F2:ZZ500");
```

This simplified model will only generate a 14×7data, but I leave a F2:zz500 space in excel still generate the error of "Description Resource Path Location Type

Exception from IBM ILOG Concert: excel: range width does not fit the arity of the tuple. Test Unknown OPL Problem Marker".

For question 2, I did have initialize the MileB_seg[ti][s][vmt] before this statement in a different for-loop, and MileB_seg[ti][s][vmt] is the same across ti set. Even if I have coded the math.pow() statement, MileB_seg still remain the same.

What I concerned about is that in the script I only apply the for-loop for year "ti", not for other sets (segment and vmtgrp), but I still use the index for these set.

------------------------------

Jia

------------------------------

Original Message:

Sent: Mon April 25, 2022 04:16 AM

From: Renaud Dumeur

Subject: Export Tuple to Excel/ For-loop questions

Dear Jia,

About question 2. You seem to use the same array cell in both sides of your assignment. In your loop you are doing x = x Math.pow(...) with x which is not initialized.

I don't think it is what you want.

I hope this helps.

Cheers,

------------------------------

Renaud Dumeur

Original Message:

Sent: Sun April 24, 2022 10:10 PM

From: Jia Zhong

Subject: Export Tuple to Excel/ For-loop questions

I am still learning the tricks of coding the model. I am still digesting the tricks of OPL.

1. I have a variable "Lifetimecost_est" having multiple dimensions. I use tuple to export the data to excel. It is a data set of 16×7×4×3×24 (32,256). I checked many answers from the community, and was confused by the setup for the excel range. I am not sure for a tuple like this, how could I set up the range of the excel correctly? I have now 24 columns (segments) and 50,000 rows. But still got the errors "".

`tuple Lifetimecost_tup{ int t; string cost; string vehicle; string vmtgrp; string segment; float value;}{Lifetimecost_tup} Lifetimecost_exp= {<i,j,k,z,l,Lifetimecost_est[i][j][k][z][l]> | i in t, j in cost, k in vehicle, z in vmtgrp,l in segment};Lifetimecost_exp to SheetWrite(Outputs,"Lifetimecost!F2:AC50000");`

2. I have a parameter needs to multiply a yearly 0.5% growth rate starting 2016. It is also a multi-dimensional data MileB_seg[ti][s][vmt], ti is the year set.

What I did is putting it in the script

`float MileB_seg[t][segment][vmtgrp];execute{for (var ti in t) { MileB_seg[ti][s][vmt]=MileB_seg[ti][s][vmt]*Math.pow((1-0.005),(ti-2016));}}`

However, I found the MileB_seg still does not change with the time. Wondering what should I code it correctly to apply this compounded growth rate?

Thanks a lot!

------------------------------

Jia

------------------------------