Hi,
I am trying to write a parameter in the .mod file as an expression that gives the number of days between 01-01-2012 and a later input day (prior to 01-01-2020):
param starting_day;
param starting_month;
param starting_year;
param starting_date = # Starting date in terms of distance in days to 01-01-2012; 0 if 01-01-2012
if starting_year = 2012 then
if starting_month = 1 then starting_day - 1
else if starting_month = 2 then 31 + starting_day - 1
else if starting_month = 3 then 31 + 29 + starting_day - 1
else if starting_month = 4 then 31 + 29 + 31 + starting_day - 1
else if starting_month = 5 then 31 + 29 + 31 + 30 + starting_day - 1
else if starting_month = 6 then 31 + 29 + 31 + 30 + 31 + starting_day - 1
else if starting_month = 7 then 31 + 29 + 31 + 30 + 31 + 30 + starting_day - 1
else if starting_month = 8 then 31 + 29 + 31 + 30 + 31 + 30 + 31 + starting_day - 1
else if starting_month = 9 then 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + starting_day - 1
else if starting_month = 10 then 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + starting_day - 1
else if starting_month = 11 then 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + starting_day - 1
else if starting_month = 12 then 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + starting_day - 1
else if (starting_year >= 2013 and starting_year <= 2015) then
if starting_month = 1 then 366 + 365*(starting_year - 2012 - 1) + starting_day - 1
else if starting_month = 2 then 366 + 365*(starting_year - 2012 - 1) + 31 + starting_day - 1
else if starting_month = 3 then 366 + 365*(starting_year - 2012 - 1) + 31 + 28 + starting_day - 1
else if starting_month = 4 then 366 + 365*(starting_year - 2012 - 1) + 31 + 28 + 31 + starting_day - 1
else if starting_month = 5 then 366 + 365*(starting_year - 2012 - 1) + 31 + 28 + 31 + 30 + starting_day - 1
else if starting_month = 6 then 366 + 365*(starting_year - 2012 - 1) + 31 + 28 + 31 + 30 + 31 + starting_day - 1
else if starting_month = 7 then 366 + 365*(starting_year - 2012 - 1) + 31 + 28 + 31 + 30 + 31 + 30 + starting_day - 1
else if starting_month = 8 then 366 + 365*(starting_year - 2012 - 1) + 31 + 28 + 31 + 30 + 31 + 30 + 31 + starting_day - 1
else if starting_month = 9 then 366 + 365*(starting_year - 2012 - 1) + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + starting_day - 1
else if starting_month = 10 then 366 + 365*(starting_year - 2012 - 1) + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + starting_day - 1
else if starting_month = 11 then 366 + 365*(starting_year - 2012 - 1) + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + starting_day - 1
else if starting_month = 12 then 366 + 365*(starting_year - 2012 - 1) + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + starting_day - 1
/*else if starting_year = 2016 then
if starting_month = 1 then 366 + 365*(starting_year - 2012 - 1) + starting_day - 1
else if starting_month = 2 then 366 + 365*(starting_year - 2012 - 1) + 31 + starting_day - 1
else if starting_month = 3 then 366 + 365*(starting_year - 2012 - 1) + 31 + 29 + starting_day - 1
else if starting_month = 4 then 366 + 365*(starting_year - 2012 - 1) + 31 + 29 + 31 + starting_day - 1
else if starting_month = 5 then 366 + 365*(starting_year - 2012 - 1) + 31 + 29 + 31 + 30 + starting_day - 1
else if starting_month = 6 then 366 + 365*(starting_year - 2012 - 1) + 31 + 29 + 31 + 30 + 31 + starting_day - 1
else if starting_month = 7 then 366 + 365*(starting_year - 2012 - 1) + 31 + 29 + 31 + 30 + 31 + 30 + starting_day - 1
else if starting_month = 8 then 366 + 365*(starting_year - 2012 - 1) + 31 + 29 + 31 + 30 + 31 + 30 + 31 + starting_day - 1
else if starting_month = 9 then 366 + 365*(starting_year - 2012 - 1) + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + starting_day - 1
else if starting_month = 10 then 366 + 365*(starting_year - 2012 - 1) + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + starting_day - 1
else if starting_month = 11 then 366 + 365*(starting_year - 2012 - 1) + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + starting_day - 1
else if starting_month = 12 then 366 + 365*(starting_year - 2012 - 1) + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + starting_day - 1
else
if starting_month = 1 then 2*366 + 365*(starting_year - 2012 - 2) + starting_day - 1
else if starting_month = 2 then 2*366 + 365*(starting_year - 2012 - 2) + 31 + starting_day - 1
else if starting_month = 3 then 2*366 + 365*(starting_year - 2012 - 2) + 31 + 28 + starting_day - 1
else if starting_month = 4 then 2*366 + 365*(starting_year - 2012 - 2) + 31 + 28 + 31 + starting_day - 1
else if starting_month = 5 then 2*366 + 365*(starting_year - 2012 - 2) + 31 + 28 + 31 + 30 + starting_day - 1
else if starting_month = 6 then 2*366 + 365*(starting_year - 2012 - 2) + 31 + 28 + 31 + 30 + 31 + starting_day - 1
else if starting_month = 7 then 2*366 + 365*(starting_year - 2012 - 2) + 31 + 28 + 31 + 30 + 31 + 30 + starting_day - 1
else if starting_month = 8 then 2*366 + 365*(starting_year - 2012 - 2) + 31 + 28 + 31 + 30 + 31 + 30 + 31 + starting_day - 1
else if starting_month = 9 then 2*366 + 365*(starting_year - 2012 - 2) + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + starting_day - 1
else if starting_month = 10 then 2*366 + 365*(starting_year - 2012 - 2) + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + starting_day - 1
else if starting_month = 11 then 2*366 + 365*(starting_year - 2012 - 2) + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + starting_day - 1
else if starting_month = 12 then 2*366 + 365*(starting_year - 2012 - 2) + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + starting_day - 1*/
;
The program is not running and is outputting the following:
The AMPL Process has terminated. Would you like to restart it?
and yacc stack overflow as an error message.
I have also tried this format but it is still giving me the same error.
param starting_date := # Starting date in terms of distance in days to 01-01-2012; 0 if 01-01-2012
if (starting_year = 2012 and starting_month = 1) then starting_day - 1
else if (starting_year = 2012 and starting_month = 2) then 31 + starting_day - 1
else if (starting_year = 2012 and starting_month = 3) then 31 + 29 + starting_day - 1
else if (starting_year = 2012 and starting_month = 4) then 31 + 29 + 31 + starting_day - 1
else if (starting_year = 2012 and starting_month = 5) then 31 + 29 + 31 + 30 + starting_day - 1
else if (starting_year = 2012 and starting_month = 6) then 31 + 29 + 31 + 30 + 31 + starting_day - 1
else if (starting_year = 2012 and starting_month = 7) then 31 + 29 + 31 + 30 + 31 + 30 + starting_day - 1
else if (starting_year = 2012 and starting_month = 8) then 31 + 29 + 31 + 30 + 31 + 30 + 31 + starting_day - 1
else if (starting_year = 2012 and starting_month = 9) then 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + starting_day - 1
else if (starting_year = 2012 and starting_month = 10) then 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + starting_day - 1
else if (starting_year = 2012 and starting_month = 11) then 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + starting_day - 1
else if (starting_year = 2012 and starting_month = 12) then 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + starting_day - 1
else if (starting_year >= 2013 and starting_year <= 2015 and starting_month = 1) then 366 + 365*(starting_year - 2012 - 1) + starting_day - 1
else if (starting_year >= 2013 and starting_year <= 2015 and starting_month = 2) then 366 + 365*(starting_year - 2012 - 1) + 31 + starting_day - 1
else if (starting_year >= 2013 and starting_year <= 2015 and starting_month = 3) then 366 + 365*(starting_year - 2012 - 1) + 31 + 28 + starting_day - 1
else if (starting_year >= 2013 and starting_year <= 2015 and starting_month = 4) then 366 + 365*(starting_year - 2012 - 1) + 31 + 28 + 31 + starting_day - 1
else if (starting_year >= 2013 and starting_year <= 2015 and starting_month = 5) then 366 + 365*(starting_year - 2012 - 1) + 31 + 28 + 31 + 30 + starting_day - 1
else if (starting_year >= 2013 and starting_year <= 2015 and starting_month = 6) then 366 + 365*(starting_year - 2012 - 1) + 31 + 28 + 31 + 30 + 31 + starting_day - 1
else if (starting_year >= 2013 and starting_year <= 2015 and starting_month = 7) then 366 + 365*(starting_year - 2012 - 1) + 31 + 28 + 31 + 30 + 31 + 30 + starting_day - 1
else if (starting_year >= 2013 and starting_year <= 2015 and starting_month = 8) then 366 + 365*(starting_year - 2012 - 1) + 31 + 28 + 31 + 30 + 31 + 30 + 31 + starting_day - 1
else if (starting_year >= 2013 and starting_year <= 2015 and starting_month = 9) then 366 + 365*(starting_year - 2012 - 1) + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + starting_day - 1
else if (starting_year >= 2013 and starting_year <= 2015 and starting_month = 10) then 366 + 365*(starting_year - 2012 - 1) + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + starting_day - 1
else if (starting_year >= 2013 and starting_year <= 2015 and starting_month = 11) then 366 + 365*(starting_year - 2012 - 1) + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + starting_day - 1
else if (starting_year >= 2013 and starting_year <= 2015 and starting_month = 12) then 366 + 365*(starting_year - 2012 - 1) + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + starting_day - 1
else if (starting_year = 2016 and starting_month = 1) then 366 + 365*(starting_year - 2012 - 1) + starting_day - 1
else if (starting_year = 2016 and starting_month = 2) then 366 + 365*(starting_year - 2012 - 1) + 31 + starting_day - 1
else if (starting_year = 2016 and starting_month = 3) then 366 + 365*(starting_year - 2012 - 1) + 31 + 29 + starting_day - 1
else if (starting_year = 2016 and starting_month = 4) then 366 + 365*(starting_year - 2012 - 1) + 31 + 29 + 31 + starting_day - 1
else if (starting_year = 2016 and starting_month = 5) then 366 + 365*(starting_year - 2012 - 1) + 31 + 29 + 31 + 30 + starting_day - 1
else if (starting_year = 2016 and starting_month = 6) then 366 + 365*(starting_year - 2012 - 1) + 31 + 29 + 31 + 30 + 31 + starting_day - 1
else if (starting_year = 2016 and starting_month = 7) then 366 + 365*(starting_year - 2012 - 1) + 31 + 29 + 31 + 30 + 31 + 30 + starting_day - 1
else if (starting_year = 2016 and starting_month = 8) then 366 + 365*(starting_year - 2012 - 1) + 31 + 29 + 31 + 30 + 31 + 30 + 31 + starting_day - 1
else if (starting_year = 2016 and starting_month = 9) then 366 + 365*(starting_year - 2012 - 1) + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + starting_day - 1
else if (starting_year = 2016 and starting_month = 10) then 366 + 365*(starting_year - 2012 - 1) + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + starting_day - 1
else if (starting_year = 2016 and starting_month = 11) then 366 + 365*(starting_year - 2012 - 1) + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + starting_day - 1
else if (starting_year = 2016 and starting_month = 12) then 366 + 365*(starting_year - 2012 - 1) + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + starting_day - 1
else if (starting_year >= 2017 and starting_month = 1) then 2*366 + 365*(starting_year - 2012 - 2) + starting_day - 1
else if (starting_year >= 2017 and starting_month = 2) then 2*366 + 365*(starting_year - 2012 - 2) + 31 + starting_day - 1
else if (starting_year >= 2017 and starting_month = 3) then 2*366 + 365*(starting_year - 2012 - 2) + 31 + 28 + starting_day - 1
else if (starting_year >= 2017 and starting_month = 4) then 2*366 + 365*(starting_year - 2012 - 2) + 31 + 28 + 31 + starting_day - 1
else if (starting_year >= 2017 and starting_month = 5) then 2*366 + 365*(starting_year - 2012 - 2) + 31 + 28 + 31 + 30 + starting_day - 1
else if (starting_year >= 2017 and starting_month = 6) then 2*366 + 365*(starting_year - 2012 - 2) + 31 + 28 + 31 + 30 + 31 + starting_day - 1
else if (starting_year >= 2017 and starting_month = 7) then 2*366 + 365*(starting_year - 2012 - 2) + 31 + 28 + 31 + 30 + 31 + 30 + starting_day - 1
else if (starting_year >= 2017 and starting_month = 8) then 2*366 + 365*(starting_year - 2012 - 2) + 31 + 28 + 31 + 30 + 31 + 30 + 31 + starting_day - 1
else if (starting_year >= 2017 and starting_month = 9) then 2*366 + 365*(starting_year - 2012 - 2) + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + starting_day - 1
else if (starting_year >= 2017 and starting_month = 10) then 2*366 + 365*(starting_year - 2012 - 2) + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + starting_day - 1
else if (starting_year >= 2017 and starting_month = 11) then 2*366 + 365*(starting_year - 2012 - 2) + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + starting_day - 1
else 2*366 + 365*(starting_year - 2012 - 2) + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + starting_day - 1
;
When I comment almost half of the lines of the expression, and use a corresponding input date, it seems to give the good result with the second format.
Could you please tell me what's wrong with these expressions?
If it doesnt work with an expression, I imagine that I will need to use a table. Is it easier if I use a 4 dimension table with the columns month - day - year - #dayswith01012012 or a 2 dimension table with the columns date (string) - #dayswith01012012 ?
Thanks
Best
Georges