Potential bug in STEP and RAMP initialization

Use this forum to post Vensim related questions.
Post Reply
eneko
Junior Member
Posts: 4
Joined: Tue Jun 28, 2022 12:38 pm
Vensim version: DSS

Potential bug in STEP and RAMP initialization

Post by eneko »

Potential bug in STEP and RAMP initialization, and probably similar functions.

I have noticed that both RAMP and STEP are executed when TIME + TIME STEP/2 > start time and TIME +TIME STEP/2 > step time, respectively.
This could produce a bug when the start time (or step time) is not a multiple of the time step. For example, the function

Code: Select all

RAMP(1, 0.45, 10)
with INITIAL TIME = 0; FINAL TIME = 3; TIME STEP = SAVEPER = 1

produces the output

Code: Select all

0	1	2	3
-0.45	0.55	1.55	2.55
which has a negative value! This is because it is computing

Code: Select all

 slope*(TIME- start time)
when TIME < start time. This value could make some models fail as the ramp return a value outside the expected value rang [0, slope*(final time - start time)].The expected output should be

Code: Select all

0	1	2	3
0	0.55	1.55	2.55
similar happens to step:

Code: Select all

STEP(1, 0.45)
with the same control variables produces:

Code: Select all

0	1	2	3
1	1	1	1
when the expected output would be:

Code: Select all

0	1	2	3
0	1	1	1
I know that is not desirable to have the start time not being a multiple of time step but this could happen sometimes. A possible workaround would be to use the same constant used to ZIDZ and XIDZ to avoid numerical error in comparison, i.e., start the RAMP and STEP when TIME + 1E-6 > start time or TIME + 1E-6 > step time.

I am using Vensim DSS 9.2.4 x64 in Windows.

Find the model attached.
ramp_bug.mdl
(1.28 KiB) Downloaded 102 times
Thank you :)
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Potential bug in STEP and RAMP initialization

Post by tomfid »

For STEP, I think this is not a bug. The step has to happen somewhere, so the logic places it at the nearest time step. In this example, the step time of 0.45 is closer to 0 than to 1, so it's appropriate for the step to occur at 0.

For RAMP, I think you're right - it seems inappropriate to return a value outside the range of [0,slope*(finish time-start time)]. I'll propose a fix.

ZIDZ and XIDZ don't use the common x/(y+1e-6) to compute a result. They do a logical check on the denominator instead. This avoids side effects of computing the numerator when it won't be used (mainly consumption of random numbers). It also avoids numerical dilution when x and y are small relative to the tolerance.
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Potential bug in STEP and RAMP initialization

Post by tomfid »

BTW, whatever testing you're doing, please keep it up!
Post Reply