# question

1 Like"

## Randomized Round Robin

Hello

Background: New conveyors with one input and multiple outputs (as you can see in the picture). At the beggining (on the right) you have decision point which is connected with 20 different decision points (in 'output' conveyors)

What I need is sending items quite randomly, but 'not too much' so they will not stop the system. I am looking for something like round robin, but with each round it would change the order of 'outputs'. For example let say that we have 5 outputs:

1st round - sending item to port 1, 2, 3, 4, 5 2nd round - sending item to port 2, 3, 5, 1, 4 3rd round - sending item to port 5, 3, 1, 2, 4

Ports can be chosen randomly, as long as I will not have situation when I am waiting at one port very long for item, while it has sent 5 items in a row to a different one.

I've tried some statistical distributions (e.g. normal, uniform, multiple bernoulli) and none of them has worked. Also, in decision points there is no option 'Round Robin' in Send Item in trigers.

FlexSim 7.5.4

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

·
3 Likes"

In the attached model I have two different solutions to this.

Code in On Arrival Trigger

I added a portOrder label to the decision point and generated a randomized list of port numbers. The list is randomized using the algorithm mentioned in this question. Whenever an item arrives it pulls off the last number, unless there are no more, then it generates a new list.

```/**Send Item*/
treenode portOrder = label(current, "portOrder");

//Generate the random list of ports if the list is empty
if(!content(portOrder)) {
int counts = nrop(current);
int dummy = 0;
intarray numset = makearray(counts);

//Create a {1,2,3...10} array.
for (int i = 1; i <= counts; i++)
numset[i] = i;

//Randomize array
//For each number i swap numset[i] and numset[j] and
//j is a random index between 1 and i.
for (int i = 1; i <= counts; i++){
int j = duniform(1, i);
dummy = numset[i];
numset[i] = numset[j];
numset[j] = dummy;
}

//Add randomized numbers as subnodes of my portOrder label
for (int i = 1; i <= counts; i++){
treenode subnode = nodeinsertinto(portOrder);
set(subnode, numset[i]);
}
}

//Pull off the last subnode
int nextPort = get(last(portOrder));
destroyobject(last(portOrder));

//Send the item to the port number I just pulled off
treenode newDest = outobject(current, nextPort);
conveyorsenditem(item, newDest);

```

Process Flow

This time I used Process Flow so there's very little code. Similar to the other solution I have an Event Triggered Source that is listening to the On Arrival event of the decision point. The token tries to pull something off the list, but if it can't (because it's empty) it regenerates the list. A Create Tokens activity creates a new token for each output port and assigns it two labels: 1 - it's port number and 2 - a random number. These tokens then push themselves on the Order List. When a token representing an item pulls from the list it uses an SQL query to order the entries on the list by their second label (some random number). This way you pull off a random number.

randomlistpf.png (22.4 KiB)
randomroundrobin.gif (682.0 KiB)
· 1

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

·

Thank you very much for help, it works perfectly now

1 Like 1 ·