I am not sure what the expected result is but writing like this :
execute{
for (var ti in t)
for ( var c in cost) {
Lifetimecost_est[ti][c]=Lifetimecost_est[ti][c]*Math.pow((1-0.005),(ti-2016));
}
writeln(Lifetimecost_est);
}
gives
[[2016 2016 2016 2016 2016 2016]
[2006.9 2006.9 2006.9 2006.9 2006.9 2006.9]
[1997.9 1997.9 1997.9 1997.9 1997.9 1997.9]
[1988.9 1988.9 1988.9 1988.9 1988.9 1988.9]
[1979.9 1979.9 1979.9 1979.9 1979.9 1979.9]
[1971 1971 1971 1971 1971 1971]
[1962.1 1962.1 1962.1 1962.1 1962.1 1962.1]
[1953.2 1953.2 1953.2 1953.2 1953.2 1953.2]
[1944.4 1944.4 1944.4 1944.4 1944.4 1944.4]
[1935.7 1935.7 1935.7 1935.7 1935.7 1935.7]
[1926.9 1926.9 1926.9 1926.9 1926.9 1926.9]
[1918.3 1918.3 1918.3 1918.3 1918.3 1918.3]
[1909.6 1909.6 1909.6 1909.6 1909.6 1909.6]
[1901 1901 1901 1901 1901 1901]
[1892.4 1892.4 1892.4 1892.4 1892.4 1892.4]
[1883.9 1883.9 1883.9 1883.9 1883.9 1883.9]]
------------------------------
Frederic Delhoume
------------------------------
Original Message:
Sent: Wed April 27, 2022 03:02 PM
From: Jia Zhong
Subject: Export Tuple to Excel/ For-loop questions
//*.mod range t=2016..2031; //{string} cost=...;float Lifetimecost_est[ti in t][c in cost]=ti;float data[ti in t]=ti;execute{ for (var ti in t) { Lifetimecost_est[ti][c in cost]=Lifetimecost_est[ti][c]*Math.pow((1-0.005),(ti-2016));}writeln(Lifetimecost_est);};//*.datcost={purchase,maintanence,fuel,detour,range,wait,idio};
Hi Renaud, here is the example. I have this multi-dimensional parameter Lifetimecost_est, I would like to let it degrades by 5% annually. In this simplified example, the values are the same across set c. But the idea is let the value change by 5% for all cost categories.
The above statement will yield error message. I need help in correcting this code. I have been searching online for a while about the solution of this.
Thanks a lot!
------------------------------
Jia
Original Message:
Sent: Mon April 25, 2022 04:19 AM
From: Renaud Dumeur
Subject: Export Tuple to Excel/ For-loop questions
Dear Jia,
About question 1, please provide a minimal model and data so that we can reproduce your problem.
Thank you in advance,
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
------------------------------
#DecisionOptimization