Here we will build a model that uses lists for basic many-to-many routing of items. The layout for this model is shown in the following image.
How It Will Work
In this model, items will be sent from three queues to one of four processors. We will use an item list. The queues will push the items onto the list, and the processors will pull them from the list and process them. Initially we will implement a simple pull, but later we will experiment with filtering and prioritizing.
Modeling Steps
- Build the Model Layout - Starting with a new model, create and connect objects in the model according to the following image, namely, a source that connects to three queues, and four processors that connect to a single sink. Do not connect the queues to the processors.
- Define Source Properties
- Open the Source properties window.
- Define the Inter-Arrivaltime as
exponential(0, 2.5, 0)
. - In the Flow tab under Send To Port choose Random Port from the pick list.
- Also, let's make three different item types, which we will use later. Add an OnCreation trigger to Set Itemtype and Color to
duniform(1, 3)
.
- Add an Item List - From the Toolbox, press the button and select Global List > Item List. This will add an item list to the model. We don't need to define any custom properties right now, so close the list's properties window.
- Make Queues Push to the List - Define each queue's Send To Port by choosing Use List > Push to Item List from its pick list. Make sure the list corresponds the the item list's name that you added.
- Make Processors Pull from the List - For each processor's Input, check Pull and under Pull Strategy choose Use List > Pull from Item List from the pick list. Make sure the list name corresponds with the name of the item list that you added. You can leave the query blank.
- Run the Model - Now we're ready to run the model. Before we do that, though, let's open live views of what is on the list and who is waiting to pull from the list. In the Toolbox, double-click on the item list to open its properties. From the General tab, press both View Entries... and View Back Orders.... These buttons will open the entry viewer and back order viewer respectively.
Now run the model.
When the model first starts, you'll notice that there are four rows in the back order viewer.
This means that the four processors have initiated a pull from the list, but since no items have been pushed to the list, they are waiting for their pull to be fulfilled.
As the model runs, items will enter the queues and be pushed onto the list, fulfilling the processor back orders, and then start to be processed. When an item is pushed onto the list and there are outstanding back orders, the item will be immediately pulled from the list. The back order will be fulfilled and subsequently removed from the back order list.
Eventually all outstanding back orders will be fulfilled, meaning all processors have found an item to process and are now processing it. When the back order list becomes empty, subsequent items that enter the queues are pushed onto the list, and, having no back orders to fulfill, they will remain on the list until a processor is finished processing its current item and pulls from the list again.
When items are pushed onto the list, they are added to the end of the list. If pull operations do not include prioritization as part of their query, the items will be pulled off in FIFO (first-in-first-out) order. Back orders will also be fulfilled in FIFO order if you do not define a Back Order Queue Strategy.
Model Experimentation
Now let's experiment with the different settings for the pull operations.
Scenario 1: Filter by Itemtype
Let's say that one of the processors can only process itemtype 2. We can accomplish this logic in our simulation by implementing a simple query on the processor.
- Open a processor's properties window.
- In the Flow tab, under Pull Strategy, open the pick list option properties.
- Under Query enter
WHERE itemType = 2
. You can use the button on the right for help in building this query, or just enter it in directly.This expression means that you only want to pull items from the list where the itemType column is equal to 2.
- Reset and run the model.
Now you should notice that the processor whose pull query we changed will only pull and process items with an itemtype of 2 (the green items).
For FlexScript Coders: The = operatorIn this example we use the expression WHERE itemType = 2
. The use of = as a comparison operator may be counter-intuitive for people who are familiar with FlexScript but new to SQL. In FlexScript (and in many other c-style languages), = is an assignment operator, whereas == is a comparison operator. In standard SQL, = is the comparison operator, and there is no assignment operator. To alleviate this confusion for our users, we have added a special SQL rule within FlexSim that makes both = and == a comparison operator, so that if you're used to using ==, you can do that in your list queries in FlexSim.
Scenario 2: LIFO Pulling
Let's say now that we want all the processors to pull in LIFO order (last-in-first-out) instead of the default FIFO, meaning that the items that were most recently added to the list should be the first to be pulled from the list. Again, we can accomplish this in the simulation by implementing a simple pull query.
For each of the processors, do the following:
- Open the processor's properties window.
- In the Flow tab, under Pull Strategy, open the pick list option properties.
- Under Query enter
ORDER BY age ASC
. Again, you can use the button on the right for help in building this query, or just enter it in directly.This expression tells the pull operation that you want to prioritize by the list's age column in ascending order, meaning items on the list with the lowest age will get the highest priority.
If you want to keep the previous scenario's logic where one processor only pulls itemtype 2, then for that processor, you just append the ORDER BY clause at the end of the expression.
WHERE itemType = 2 ORDER BY age ASC
- Reset and run the model.
You should notice now that items on the end of the list will be pulled first, and items at the front will be pulled last.
Using the Entry Viewer's Advanced Tools
The entry viewer has advanced tools that you can use if you want to test out various queries. For example, what if we wanted to test out our ORDER BY age ASC
query to make sure it does what we want before actually implementing it in the simulation logic? We can use the entry viewer's advanced tools to do this.
- Run the model until there are several items on the list.
- In the entry viewer, press the button to show the advanced tools.
- Test the pull query by entering
ORDER BY age ASC
in the Query field and pressing Enter.Notice that the items in the list are now reordered based on their age in ascending order. A pull operation that uses this query would pull from the top of this sorted list, namely /Queue8/Box with itemType of 2 and age of 0.36.
SQL Quick Start
If you're new to using SQL, the SQL Quick Start topic includes a lot more examples of the different pull queries that you might use in this model.