question

Noah Z avatar image
0 Likes"
Noah Z asked Noah Z commented

Model Time Units Set to Years Issue

I have a model that has time units in years. I have a source in the model that is supposed to create a token each simulation day (365 tokens a year on non-leap years) and check to see if it is a certain date (e.g. January 1st). If so it sends the token to do some additional activities but if not, the token goes to a sink.

The token source is set to generate a new token in model time units based on: 1/365.24

When I run the model for many years it does not get the timing of it all exactly right so I must be doing something wrong. What am I missing? I have included an example model showcasing this behavior.

yearly-update-not-exactly-a-year.fsm

FlexSim 19.2.0
sourcetime
· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

tannerp avatar image tannerp commented ·

After reviewing your model, I think that you've got the logic as accurate as possible. I verified that 1.0/365 created tokens consistently at 8:00 AM every day here:

FlexSim wasn't necessarily designed to run models that span several years' worth of time. The only thing that would increase the accuracy would be to figure out the exact value used in calculating datetime within FlexSim. The 365.24 figure is relatively accurate across 4 years, but you're right in that it varies a bit over time.

May I ask what you're hoping to simulate over the course of several years?

0 Likes 0 ·
Noah Z avatar image Noah Z tannerp commented ·

I have a process that I'm modeling that would have events happening out a few decades from the model start. I am using the model to do data collection on expected number of specific events in each year during that extended timeframe. Model inputs and assumptions are scheduled to change at various points during the run leading to different outcomes in different epochs. Sorry that is so vague..ufortunately I can't be more specific than that.

Regarding the apparent mismatch between the the time() capture and the one year anniversary (January 1st each year) I'm still not sure how that could be happening. The drift between the two is ~25 days of time (0.07 years) by the time you reach 100 years. Is it possible to have someone on the FlexSim team take a closer look at the datetime calculation within FlexSim to see what is causing this discrepency?

0 Likes 0 ·
Phil BoBo avatar image Phil BoBo ♦♦ Noah Z commented ·

When your model is in "years," FlexSim interprets that as 1.0 unit of simulation time is 365 days. It doesn't account for what year it is, just that it is X * 365 days since the simulation started.

You set a stop time of 100.0 model time units (100 "years" or 36,500 days), but 100 actual years depends on the start date. So for your model that starts at 8 AM on 1/1/2020, if you want the model to stop at 1/1/2120, then the stop time in model units would be 100.0658.

If you want to account for days better, I would suggest using "days" as your model unit instead of years, so that your values are closer to zero instead of 5 decimals out.

Since you are simply making 1 token per day and using a Decide activity to determine whether the current day is the next year, you could use days(1) as the inter-arrival time instead of a hard-coded fraction. This will work regardless of your model units. Whether your model units are seconds, minutes, days, or years, the days(1) command will return 1 day worth of model time.

1 Like 1 ·

1 Answer

Phil BoBo avatar image
2 Likes"
Phil BoBo answered Noah Z commented

It seems to me that you are simply trying to generate a token every January 1. Rather than trying to create a token each day and then throwing most of them away, you can use the DateTime class to determine how many model units there are until near year:

DateTime now = Model.dateTime;
DateTime nextYear = now;
while (nextYear.year <= now.year) {
	nextYear = nextYear + DateTime(1, 0, 0, 0);
}
double secondsUntilNextYear = nextYear - now;
return secondsUntilNextYear / getmodelunit(TIME_MULTIPLE);

Attached is a sample model (yearly-arrival-source.fsm) that generates a token each January 1 without any drift.


If you want to generate a token each year on the same day (not necessarily on Jan 1), you can do that quite easily too:

DateTime now = Model.dateTime;
DateTime nextYear = now + DateTime(365, 0, 0, 0);
if (nextYear.day != now.day) {
	nextYear = nextYear + DateTime(1, 0, 0, 0);
}
double secondsUntilNextYear = nextYear - now;
return secondsUntilNextYear / getmodelunit(TIME_MULTIPLE);

Attached is a sample model (yearly-arrival-source-1.fsm) that generates a token each year on the start date month/day.


· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Noah Z avatar image Noah Z commented ·

Thank for the help, Phil. I've used getmodelunit() up to this point but the DateTime class seems a lot easier and I'll be using that moving forward. Thanks!

Also, the "days(1)" is a nice feature as well.

0 Likes 0 ·