## Picking Random Numbers From Two Queues and Assembling into a Single Work Item

In this SIMUL8 tip, we will look at selecting different numbers of items from two queues and assembling them into a single work item, which represents a completed order.

In this example, we will have a warehouse, which holds two different item types. The items are kept in separate stores. The warehouse receives orders for varying amounts of items 1 and 2 and a robot selects the required number of Item 1; then selects the required number of Item 2; before packing the items into a single box, ready for shipping. In this example, we will assume that the number of each part ordered is random, sampled from 2 distributions; however, this could also be driven by a spreadsheet representing client orders.

First, we model our system:

Next, we set up two distributions. For this example, the distributions used are rounded distributions, between 1 and 10 (we need to use discrete distributions, as we cannot select, for example, 2.5 items from a queue). The distributions will be called “distItem1” and “distItem2”.

Set the Routing In discipline of the Activity “Pick” to be Priority and the Routing In discipline of “Packing” to Collect; ensuring that the check-boxes for “Assemble” and “Do not collect until all available” are ticked. This means that the items in the Awaiting Packing queue will only be collected when the order has been completed.

We now need to use Visual Logic to control the simulation. In the “On Reset” section of Visual Logic, we set the initial values of the items to be collected from each queue, storing them in the gblNumberRequired variables:

SET gblNumberRequired1  =  distItem1
SET gblNumberRequired2  =  distItem2

We also want to ensure that the robot picks Item 1s first, so we move the “Item 1 Store” to the top of the list of it’s Route In priorities. To do this, we use the below command:

Set Route In Priority    “Pick” ,  “Item 1 Store” ,  1

The last thing we need to do, in the On Reset logic, is set the number of items to be collected by the “Packing” activity. The below command sets this for us:
Set Collect Number    “Awaiting Packing” ,  gblNumberRequired1+gblNumberRequired2 ,  “Packing”

This command tells SIMUL8 that we will be pulling items from the “Awaiting Packing” queue, into the “Packing” queue. The number to be collected will be the sum of gblNumberRequired1 and gblNumberRequired2.

This is all created on the “On Reset” section of Visual Logic, as we need it to be set up prior to the simulation being run.

Next, we want to control the Robot, so that it collects the correct number from each queue. Essentially, we want the robot to keep collecting from “Item 1 Store”, until the required number of work items have been collected; before switching to “Item 2 Store”. In the “On Exit” section of “Item 1 Store”, we enter the below code:

SET gblNumberRequired1  =  gblNumberRequired1-1
IF gblNumberRequired1  =  0
Set Route In Priority    “Pick” ,  “Item 2 Store” ,  1

This means that SIMUL8 will deduct 1 from the gblNumberRequired1 variable, each time a work item leaves the “Item 1 Store” queue. Once the number of work items required is zero, we move “Item Store 2” to the top of the list of priorities for the “Pick” activity, so that the next work item is selected from this queue.

Similarly, we set up Visual Logic in the “On Exit” section of “Item 2 Store”; however, this time we deduct from gblNumberRequired2 and once we are finished, we set the priority back to “Item 1 Store”:

SET gblNumberRequired2  =  gblNumberRequired2-1
IF gblNumberRequired2 =  0

Set Route In Priority    “Pick” ,  “Item 1 Store” ,  1

The final section of code we need to add is in the “After Loading” section of Visual Logic, on the “Packing” activity. In this section, we need to re-sample from each of the distributions (to represent the next order being different from the last) and then set the number of items to be collected from the “Awaiting Packing” queue to the sum of these two new values. The code we need is:

SET gblNumberRequired1  =  distItem1
SET gblNumberRequired2  =  distItem2

Set Collect Number    “Awaiting Packing” ,  gblNumberRequired1+gblNumberRequired2 ,  “Packing”