question

Paula LG avatar image
0 Likes"
Paula LG asked Paula LG commented

Losing repeatability because of stock creation way

Hi,

I have a repeatability issue with a model I'm developing, and I can't find what's causing it. I think it could be a bug, but maybe I'm missing something.

The model consists of a storage facility that needs to have an initial stock built at the beginning of the simulation. The only information I have about this stock is quantity. Because of that, the first time I run the simulation I assign random empty slots to the stock items and write all the addresses on a table, so that the second time I run it, it can be built a lot faster and the model performance will improve. Both ways, the stock locations are exactly identical.

The first situation (having an empty stock table) could happen again anytime, since the model layout is auto-buildable based on some parameters, and, every time it is re-built, the table is reset.

The issue appears when the order creation logic starts, and it persists in all newer FlexSim versions; different items are chosen to be part of those orders depending on how the stock was created.

I have developed a small dummy with only 1 rack to illustrate what's happening. The items chosen to be part of the orders are colored, so that it's easy to identify them. It also contains a script to clear all the "Stock" table cells to be able to replicate the two scenarios.

1742561975745.png1742561987714.png

24.1 Orders repeatability.fsm

Thanks in advance!

FlexSim 24.1.1
finditemordersstock
· 2
5 |100000

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

1 Answer

Jordan Johnson avatar image
0 Likes"
Jordan Johnson answered Paula LG commented

@Felix Möhlmann is correct. When your table is empty, all the tokens will flow through the "Find empty random slot" side of the flow. This side calls ORDER BY RAND(), which uses stream zero a whole bunch of times. The Find Item activity also uses the same stream for its ORDER BY RAND(). So the first time you run the model, stream zero is used a whole bunch. The second time you run it, stream zero hasn't been used as much, so those same random values are applied to picking items rather than placing items. Consider the following table:

Question Run 1 Run 2
Location for Item 1? Based on stream 0 (1st value) Based on the table
Location for Item 2? Based on stream 0 (2nd value) Based on the table
...

Item for order 1? Base on stream 0 (505th value) Based on stream 0 (1st value)
Item for order 2? Based on stream 0 (506th value) Based on stream 0 (2nd value)


I think your real question is how to quickly initialize random inventory. Consider the attached model:

QuickRandomFillShuffleArray.fsm

Here's the basic idea:

  1. Get an Array of all the slots
  2. Shuffle that array
    1. Pick a random index
    2. Ad that value to the new array
    3. copy whatever's on the end to the random position
    4. pop the last value off the end (popping the last value is much faster than removing a value in the middle)
  3. Push the array of shuffled slots to a list, one at a time
  4. When you need a random slot, pull from the list.

I would use a strategy like this to make initialization fast. Then you don't have to depend on previous runs.


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