Dear colleagues,
I want to ask you if you can help me to implement an action counter in a model.
The idea is to establish an auxiliar variable that increments its value +1 for each output of a stock variable.
Thanks a lot.
How to implement an action counter in a model?
Re: How to implement an action counter in a model?
A counter usually can't be an auxiliary, because it has a state. It has to be a stock.
You can do something like the following:
water level = RANDOM UNIFORM(0,1,0)~meters~just a test input|
flood flag = IF THEN ELSE( water level > flood level, 1, 0 )~dmnl~|
flood level = 0.9~meters~|
flood count = INTEG( flood flag/TIME STEP, 0 )~dmnl~|
Note that this counts the number of time steps with flooding, rather than the amount of time. If that matters, there are various ways to handle it, but it's hard to say what's appropriate without some information on the situation.
The above structure could also be implemented with SAMPLE IF TRUE.
You can do something like the following:
water level = RANDOM UNIFORM(0,1,0)~meters~just a test input|
flood flag = IF THEN ELSE( water level > flood level, 1, 0 )~dmnl~|
flood level = 0.9~meters~|
flood count = INTEG( flood flag/TIME STEP, 0 )~dmnl~|
Note that this counts the number of time steps with flooding, rather than the amount of time. If that matters, there are various ways to handle it, but it's hard to say what's appropriate without some information on the situation.
The above structure could also be implemented with SAMPLE IF TRUE.
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Re: How to implement an action counter in a model?
I made this module including a counter reset when it reaches the value 10.
The problem is when I running the simulation. In periods 57, 76, and 92 the counter restarts at 1 when it should be 0.
Why is that? Can you help me correct it? Thanks!
The problem is when I running the simulation. In periods 57, 76, and 92 the counter restarts at 1 when it should be 0.
Why is that? Can you help me correct it? Thanks!
- Attachments
-
- test_counter.mdl
- (2.22 KiB) Downloaded 42 times