Round Robin algorithm

Hi all! I want to make a simple thing but is so simple that i cant! :( I have a list of people that are made a subscription to a training course. The list is composed by 6 people. (but I would like to implement more in future) With a microflow, I would like to create an automatic match list where the each person can match with others. Easly talking the new list will be composed by these match : 1-6 , 1-5, 1-4 , 1-3, 1-2, 2-3 , 2-4, 2-5, 2-6, 3-4 , 3-5, 3-6, 4-5 , 4-6 , 5-6 . Anyone can help me please?   
3 answers

Create a multiple multiple reference with itself of the people object. That self reference will contain the match.
Now in a microflow retrieve the list of all the people and make an iteration over this list. In the iteration create again a list of people and copy the list containing all the people. Remove from this list the person from the iteration so it can not make an appointment with itself. Now retrieve the self reference list (at first it will offcourse be empty) and call this the appointmentlist. Then create another iteration (so you have an iteration within an iteration). The second iteration is all the people minus the person from the first iteration. In the second iteration retrieve again the self reference list. if the list is empty add the person from the second iteration and add the person to the appointmentlist. If this list is not empty check if the person from the first iteration is already part of this list (list operation contains). If the person in the second iteration already has the person of the first iteration on its list you can skip to the next person. Otherwise add the person to the list.  After completion of the second iteration commit the appointment list in the first iteration and make sure that for the next person you again create a fresh copy of the first list so that the self references of these people are updated.
I hope I gave you a point in the right direction.


You can add a new reference Match object that has a many-to-many association to the Person object.  You can also associate this object to the course, as in the end of the day Person A and Perosn B might have matches in more than one single course. So the Match object is now caring the information who are the persons and where do they match, you can also add additional information as if match meeting has taken part or anything like that. 

 The procedure of assigning the new  objects is pretty much similar, to the one with the reference described by Ronald – iterate over the course attendees, check which matches do they already have and if needed assign new Match Objects – set the reference of the match object to both persons and to the course, commit the list ob Match objects in the end of your microflow.

Be aware what should happen when new Person(s) subscribe or unsubscribe after creating the matches. 

I thing this solutions suits better for the case that you need more than just the information who are the people involved in the match. However self-reference is also a way to go.

Hope that helps




Setup a RoundRobin entity like this (deletion behavior: on Person-deletion, delete RR-object. On RR-deletion, keep Person):

Then two microflows to do this:

Then create a second microflow for creating the RoundRobin-objects:

go to to see this working (untested yet) and to to download the code

Mind that if the number of persons grows  performance issues will arise and the last retrieve of persons needs to get replaced with a loop instead.