capture daily values from excel

Use this forum to post Vensim related questions.
Post Reply
ebr567
Member
Posts: 36
Joined: Sat Mar 14, 2015 11:26 am
Vensim version: DSS

capture daily values from excel

Post by ebr567 »

Hello,

I am feeding sheep a different amount each day during pregnancy. I am using QUEUE FIFO ATTRIB (body weight is the attribute) for the sheep and I have a list of the daily intakes for days 1-150 of pregnancy in excel. How do I make the ewes eat the correct amount for each day in the queue?

Thank you.
Administrator
Super Administrator
Posts: 4589
Joined: Wed Mar 05, 2003 3:10 am

Re: capture daily values from excel

Post by Administrator »

Start with the example in the Vensim help system and get that working, then it should be simple to read in your own data.

http://www.vensim.com/documentation/ind ... s_data.htm
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
ebr567
Member
Posts: 36
Joined: Sat Mar 14, 2015 11:26 am
Vensim version: DSS

Re: capture daily values from excel

Post by ebr567 »

Thank you. I can input the data values for each day of the simulation, but how can I do it by day in the queue? In the example model QUEUE functions.mdl, for instance, let's say I have to maintain these items in the warehouse, and the amount of labor required for each item increases as it sits in the warehouse. For a one month old item I have to put in 0.03 months of labor to maintain it during this time. For two months, it would be 0.06 months of labor, etc. How would I relate the waiting time in this queue (not the model time) to the labor required for each item?
tomfid
Administrator
Posts: 3808
Joined: Wed May 24, 2006 4:54 am

Re: capture daily values from excel

Post by tomfid »

You can't initialize the internal state of a queue with that level of detail.

How many sheep do you have? An array of individuals might be a viable alternative. (If you have a lot, Ventity might be even better.)

For your inventory-age-labor example, that sounds like a classic aging chain, which could be easily implemented without all the overhead of a queue or array.
ebr567
Member
Posts: 36
Joined: Sat Mar 14, 2015 11:26 am
Vensim version: DSS

Re: capture daily values from excel

Post by ebr567 »

I'm not trying to initialize the state. I'll be initializing this queue with zero members.

My labor costs are proportional to time in queue. Mathematically this would be represented as

Labor_cost = sum( widget(tau)*cost_per_widget(tau), tau from 1 to 180 days )

where tau is the time in the queue so widget(13) is the number of widgets that have been in the queue for 13 days. The cost_per_widget(tau) would not change through the simulation but will be a function of tau and will be initialized with an excel lookup.
For your inventory-age-labor example, that sounds like a classic aging chain, which could be easily implemented without all the overhead of a queue or array.
I'm assuming you are referring to the convey4.mdl example. I'm not familiar enough with conveyors to use them, I'd also like to use indicies, but I having trouble with the helpfiles. In the short term I'll stick with queues, but do you think conveyors would work better?
tomfid
Administrator
Posts: 3808
Joined: Wed May 24, 2006 4:54 am

Re: capture daily values from excel

Post by tomfid »

Ahh ... now I think I understand.

So, you're putting sheep (or widgets or whatever) into the queue, and then retrieving the number of each age, and multiplying by an age-specific factor to get cost. So, you really just need the age distribution of the queue.

How much age detail do you need? For example, with sheep I'd imagine that you'd like to have low or no dispersion in the gestation period (147 days plus or minus), but that the daily cost would vary only in broad sweeps. In other words, day 30-60 might be quite different from day 120+, but day 66 is probably about the same as day 67.

I'd be inclined to use a QUEUE function, and retrieve the age distribution with QUEUE AGE IN RANGE in largish blocks (10 days?) rather than daily. Either way, you'd probably want to use an array to contain the age distribution. There's no way to directly combine a QUEUE and a LOOKUP.

Are we on the right track?
ebr567
Member
Posts: 36
Joined: Sat Mar 14, 2015 11:26 am
Vensim version: DSS

Re: capture daily values from excel

Post by ebr567 »

Yes, exactly. I decided to group them in several stages, then consume a certain amount of feed (DMI) as they move through the stages based on amounts from Excel. I move them through by retrieving the number of animals that have been in the pool the alloted number of days with the QUEUE AGE IN RANGE function.

I have unit errors in the "delay time" and can't understand how to fix them. Can you look at what my unit error is and explain it to me?
Thanks for you help!
Attachments
sheepinputs.xlsx
(58.01 KiB) Downloaded 240 times
Sept 13 model redo 5.mdl
(26.56 KiB) Downloaded 236 times
Administrator
Super Administrator
Posts: 4589
Joined: Wed Mar 05, 2003 3:10 am

Re: capture daily values from excel

Post by Administrator »

The model has a number of unit errors.

What should "breeding date 1" be measured in? Should it be month or day? I'd correct these first and then solve the rest of the errors.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
ebr567
Member
Posts: 36
Joined: Sat Mar 14, 2015 11:26 am
Vensim version: DSS

Re: capture daily values from excel

Post by ebr567 »

I have an additional question regarding this model. Why do the queues become negative and how would you suggest I control that? I'm guessing it's an integration error?

Thank you!
ebr567
Member
Posts: 36
Joined: Sat Mar 14, 2015 11:26 am
Vensim version: DSS

Re: capture daily values from excel

Post by ebr567 »

"date number" is the day of the year (1 to 365) which cycles throughout the run. If I change "date number" and all 5 "breeding dates" to "day" unit, it returns the same errors.
Administrator
Super Administrator
Posts: 4589
Joined: Wed Mar 05, 2003 3:10 am

Re: capture daily values from excel

Post by Administrator »

ebr567 wrote:I have an additional question regarding this model. Why do the queues become negative and how would you suggest I control that? I'm guessing it's an integration error?

Thank you!
Which queues?
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Administrator
Super Administrator
Posts: 4589
Joined: Wed Mar 05, 2003 3:10 am

Re: capture daily values from excel

Post by Administrator »

ebr567 wrote:"date number" is the day of the year (1 to 365) which cycles throughout the run. If I change "date number" and all 5 "breeding dates" to "day" unit, it returns the same errors.
If this should be measured in "day", then I'd change it in the model. Don't change the units to make them balance, always put the correct units in and then fix any errors.

I've managed to get it to pass the units check (changing all the date number to day) with just the one warning,

Code: Select all

Warning: units in equation for - conception rate mature ewes 
Lookup -conception rate lookup- used with dimensioned argument
 Day
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
tomfid
Administrator
Posts: 3808
Joined: Wed May 24, 2006 4:54 am

Re: capture daily values from excel

Post by tomfid »

OK - some questions & observations:

1. Only four stocks actually use the QUEUE AGE function to access the queue internals. The others could be replaced by ordinary stocks (INTEG) to simplify things.

2. In those four, QUEUE AGE is used to determine how many ewes are done with the process under consideration. The resulting behavior is essentially a conveyor or fixed delay, which might be simpler. Is the objective ultimately to add more detail to the DMIs, e.g. by having separate intakes for the "early late lact mature ewes" and "late late lact mature ewes"?

3. Which queue goes negative? I'm probably being dense, but I don't see one. Roundoff is probably responsible, but I would like to see an example to be sure.

4. If I change the age range, date number and breeding dates to units of "day," the units work out for me.

5. Since breeding is regular, you could use a PULSE TRAIN with an interval of 73 days, rather than the IF THEN ELSE statement.
ebr567
Member
Posts: 36
Joined: Sat Mar 14, 2015 11:26 am
Vensim version: DSS

Re: capture daily values from excel

Post by ebr567 »

Thank you - very helpful!

1 and 2. This breeding dates will be variable and can be from only a few days to 6 months apart. The ewes won't overlap coming into and exiting the two Breeding pools (since all animals in each Breeding pool exit at each breeding date), but they will overlap coming into the Early pregnancy pool. Yes, another way to handle this is with fixed delays. For example, I could take out Early preg mature ewes using a fixed delay x days after conception 1 and conception 2. I had stayed away from this option because I was concerned it would form a loop - each rate is determined by the previous one. I had previously wanted body weight associated with each group (through QUEUE FIFO ATTRIB) and needed to maintain the order of animals coming in. Perhaps this does not matter now that I am not changing their body weight within each pool, and I do not need to necessarily pull out the "first in" or oldest ewes out first. Would there be any concern with tying these rates together in a cycle of fixed delays? FYI, I do not plan to further add more detail or groups to this set.

I will be having these ewe produce lambs, which will grow in body weight. I plan to use the QUEUE FIFO ATTRIB for this, but I also suppose I could use an simultaneous chain alongside it. Would QUEUE FIFO ATTRIB be the correct function, or is there a cleaner (but not hidden) way to do this?

3. I will attach the model again - I am getting some negatives in the "Late preg mature ewes".

4. Yes, works for me too. Not sure what happened to me before.

5. This one is regular, but I will be done different breeding schedules that are not, so needed individual date input options.

Again, thanks very much!
Attachments
sheepinputs.xlsx
(58.16 KiB) Downloaded 222 times
Sept 15 model lambs 3.mdl
(32.24 KiB) Downloaded 241 times
tomfid
Administrator
Posts: 3808
Joined: Wed May 24, 2006 4:54 am

Re: capture daily values from excel

Post by tomfid »

3. If you rewrite the equation as

Code: Select all

lambing mature ewes=late preg ready mature ewes/TIME STEP-mature ewe death at lambing
the rounding error goes away.
tomfid
Administrator
Posts: 3808
Joined: Wed May 24, 2006 4:54 am

Re: capture daily values from excel

Post by tomfid »

1/2. I don't think you'd get into loop problems with DELAY FIXED, but I'm not sure it's worth changing. I think your QUEUE approach is quite clever, because it could be generalized to do things like stochastic births of lambs. I'd probably stick with the queue for the lambs alongside ewes too, as long as their growth is strictly a function of age - modeling the dynamics wouldn't add anything.
ebr567
Member
Posts: 36
Joined: Sat Mar 14, 2015 11:26 am
Vensim version: DSS

Re: capture daily values from excel

Post by ebr567 »

Thank you! Yes, I am going to add stochastic lambing into the model, but am having a hard time figuring out how to best go about it. I can change the "time in late preg" into a RANDOM NORMAL distribution, but this will then take the entire group of Late preg mature ewes out at once. How would I randomly distribute the ewes to lamb over the course of 10 days (most at the mean of 146 days with st deviation of 2), rather than taking the whole group at a randomly distributed time? I will attach my attempt to start this, but it will move all ewes at once.
Attachments
sheepinputs.xlsx
(58.16 KiB) Downloaded 224 times
Sept 19 fewer queues stoch.mdl
(31.85 KiB) Downloaded 228 times
tomfid
Administrator
Posts: 3808
Joined: Wed May 24, 2006 4:54 am

Re: capture daily values from excel

Post by tomfid »

Right - I don't think NORMAL for the time constant gives you the right distribution, plus it gives you non-integer sheep.

I think what you need is a table of P( delivers | day ), then you could use RANDOM BINOMIAL to determine how many deliveries occur at each day of maturity. The fly in the ointment is that this won't work with the QUEUE FIFO. You could use the queue's age distribution to determine deliveries once, but then the outflow will always draw on the oldest elements, which will make the age distribution inaccurate in the next step.

DELAY PROFILE might be perfect, if fractional sheep are OK.

Here are a couple attempts, in continuous and discrete time/sheep.
DiscreteGestationDelay1.mdl
(10.55 KiB) Downloaded 246 times
ContinuousGestationDelay1.mdl
(7.17 KiB) Downloaded 238 times
tomfid
Administrator
Posts: 3808
Joined: Wed May 24, 2006 4:54 am

Re: capture daily values from excel

Post by tomfid »

Just for fun, here's a variation on this model in Ventity.
Sheep2 (2).zip
(10.45 KiB) Downloaded 281 times
Post Reply