yacc stack overflow error

80 views
Skip to first unread message

Georges Meouchy

unread,
Oct 27, 2014, 4:31:56 PM10/27/14
to am...@googlegroups.com
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

Robert Fourer

unread,
Oct 29, 2014, 7:11:02 PM10/29/14
to am...@googlegroups.com
Yacc is the function that parses AMPL statements, so "yacc stack overflow" is consistent with the statement that is causing the problem. Most likely this extremely long statement is using more stack space than yacc has been configured with. In any case, we'll confirm the cause and see what can be done -- perhaps a stack space parameter just needs to be increased.

Meanwhile with a few simple parameters you might reduce the size of this expression considerably. For example if mdays[m] is the number of days (usually) in month m, and leap[y] is 0 except 1 when year y is a leap year, then it appears to me that your expression begins with

if starting_year = 2012 then
sum {i in 1..starting_month-1} mdays[i] +
(if starting_month > 2 then leap[starting_year]) +
starting_day - 1 ...

I believe if you then define

param ydays {j in 2012..2017} = sum {i in 1..12} mdays[i] + leap[j];

then you can get the whole expression down to

sum {j in 2012..starting_year-1} ydays[j] +
sum {i in 1..starting_month-1} mdays[i] +
(if starting_month > 2 then leap[starting_year]) +
starting_day - 1

Bob Fourer
am...@googlegroups.com

=======

From: am...@googlegroups.com [mailto:am...@googlegroups.com] On Behalf Of Georges Meouchy
Sent: Monday, October 27, 2014 3:32 PM
To: am...@googlegroups.com
Subject: [AMPL 9390] yacc stack overflow error

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 ...

Georges Meouchy

unread,
Oct 29, 2014, 8:40:45 PM10/29/14
to am...@googlegroups.com
Thank you for your answer. This form is much better indeed.
Reply all
Reply to author
Forward
0 new messages