Random Group Generator Based on Preferences

I'm looking to generate random groups based on certain preferences.

I've got a table that lists the names down the left hand column and several roles going across the right.

A

B

C

D

Priority

Start

Name 1

1

3

2

Name 2

N

1

Y

Name 3

N

1

Name 4

3

N

2

1

Name 5

1

2

Y

*There could be up to 30 names and 11 roles, but I've only used five names and four roles for illustration purposes.

The number denotes the preference for certain roles (1 = primary, 2 = secondary, 3 = tertiary, N = not in this role).

The priority column is for if two people have the same preference e.g. Name 2 and 5 prefer role B, but Name 5 has priority.

The start column is for if there are more people than the number of roles available. A 'Y' in this column indicates that they must start.

Underneath, there are grids to list different group sizes and how the members of the group rotate between being involved and not e.g. 10 names and 7 roles or 11 names and 9 roles etc

In the below example, there are five names and four roles. Where there's a Y, it should be populated with a role. Where it's blank, they don't have a role in the rotation.

Rotation 1

Rotation 2

Rotation 3

Rotation 4

Rotation 5

Name 1

Y

Y

Y

Y

Name 2

Y

Y

Y

Y

Name 3

Y

Y

Y

Y

Name 4

Y

Y

Y

Y

Name 5

Y

Y

Y

Y

I'd like to populate the available names in one column and then for excel to put the names in any order that can make a viable solution. In the above example, the order of the names do not make a difference. However, if two or more people have to miss a rotation, certain combinations can become problematic e.g. it might be helpful to have Name 2 on when Name 5 is off and vice versa due to both preferring the same role to help share the time between them. For example, I'd like to list the names in column A next to the grid, and Excel can reorder the names in column B to help make a viable solution.

A person should be put in a preferred position but can be put in any role unless it has a 'N' in the first grid.

They should also stay in one role as long as possible and should not be in more than three roles throughout. It's easier for continuity if Name 1 can be in role A for rotation 3-5 and either role D or B in rotation 1.

Many thanks!

It is far too complicated to recreate such a scenario. And if it does not match yours, then our solution will not work for you.

For this kind of requests, please create a sample file with the layout of your original file, filled with sample data and colored cells with the expected result.

At best make a copy of your original file and anonymize the necessary data. For this please download this file
https://www.dropbox.com/s/rkfxuh85j5wyj9y/modAnonymize.bas?dl=1
Open your Excel file
Right-click on the sheet tab
Choose "View Code"
Press CTRL-M
Select the downloaded file and import
Close the VBA editor
Select the cells with the confidential data
Press Alt-F8
Choose the macro Anonymize
Click Run

Upload it on OneDrive (or an other Online File Hoster of your choice) and post the download link here.
https://support.office.com/en-us/article/Share-OneDrive-files-and-folders-9fcc2f7d-de0c-4cec-93b0-a82024800c07

Then we can look at the file and try to find a solution. Thank you for your understanding.

Andreas.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Okay, thank you very much, but I have to admit I have no idea where the logic is.

From the grid in B2:J18 I can understand that "Name 16" prefers role H with preference 1 (cell J18, I ignore K:L for the moment).

I can see "Name 16" also in A21 and from your instructions I can choose any of the names, okay.
So I guess in A21:A30 we can put some random names from B3:B18?

But why "Name 12" in B21??? And what means "D" in C21?? "Name 12" does not prefer role D in any way, only B,E,F!

And I have absolutely no idea why there is a gap in D21 at column ".12-24" whatever that means.

Sorry, I'm lost.

Andreas.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Thanks for looking at this, Andreas!

Yeah, you can put random names from B3:B18 in A21:A30 for groups of 10. Groups of 11, the names are entered in A33:A43, and the other group sizes follow below etc.

B21:B30 are the names from A21:A30, but they can be rearranged into an order that gives a valid solution. E.g. if you have Name 2, 11 and 12 not involved at the same time (who all prefer role B), it might make it difficult to share the time they each spend in role B. The logic might find a better order for the names than the order they have been entered in.

I entered the names randomly, so there's no real reason for Name 12 to be in B21. I've not used the best combination of names or roles in my example, but Name 12 can perform role D if there's no viable solution with preferences because it's not marked as 'N' in B2:J18.

The gaps in the grid is when that person isn't involved in a role during that rotation. During that time, they'll be observing or helping in some other capacity. ".12-24" is just referring to the time of that rotation.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Hi Dimitir,

as this is a nice puzzle, I like to give you a start:

https://www.dropbox.com/s/py5lup3pzg7h6lm/b6c15bf0-2c0b-4b70-9e6a-0e9a5f33b01c.xlsm?dl=1

You need to set Excel \ Options \ Formulas \ Iterative calculation for this file.

Your approach is too complicated, we have to go one step down and choose 10 names and then let us check if there is better distribution for the roles.

So if you clear B22 and press F9 you get 10 random names in B24:B33, then write "Y" in B22 to fix the names.

To be able to make an assessment we have to weight each role individual for each name, that's the sense of the formulas in S3:Z18

The formulas in column AB:AD are just to get random roles in D24:H33

The interesting part is P24:T33 in there I pull the weigth for the name from S3:Z18 and calculate a Total in T34:

Image

But the problem is that due to your restrictions it might be possible that even a random distribution is no solution at all.
In this case there is a 0 in the Weight section. Press F9 by yourself a few times and you'll see it's not easy to get one.

That's the reason for the button, the code behind force a calculation of the sheet till there is a solution. And as higher the Total as better fits this distribution to your contrains.

Now it's your turn to decide whether you like the solution or not ... and maybe click the button again.

Andreas.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Thanks, Andreas! This is great!

I've perhaps not quite explained the first part of it, but it looks like the second bit works well!

A24:A33 isn't exactly random names. They are just the 10 people who turn up that day. I realised the order that the names are listed would affect the solution, so I wanted the logic to be able to rearrange them in B24:B33 to help find a viable solution.

I know that depending on the 10 names, there may not be a 'perfect' solution, so it's great that it can find a solution that fits most people and alerts me to where the issues might be (the 0 in the weight section)!

There are only 8 roles, but there can be between 8 and 15 people turn up, which is why there are tables for various group sizes. I'm trying to share the time evenly between them. At the moment, I try to plan this manually ahead of time, but if a different number to expected arrives it's very difficult to try to find a solution at that time. This worksheet will help a lot in these situations!

I'm open to any suggestions to make it workable or more efficient.

1 person found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated October 18, 2023 Views 3,524 Applies to: