Excel Coding to Pair Two Items Together While Maximizing Time Covered

SanFelippo

Board Regular
Joined
Apr 4, 2017
Messages
124
Hello Friends,

This is a bit of a tricky one to do in excel, as it involves some Operations Research (if anyone has ever taken that class in college).

I have a list of People or "Items" if you will. In the next column I have their strengths, let's say they are either Offensive or Defensive. Then in the next two columns, I have the times that they are available (it runs from 0 - 24, so someone could be available from say 7 - 19, or someone could be available from 20 - 6, or 6 - 13, etc).

I have included a table below to show what I mean.

Anyway, the idea is this. Each Person on this list has their own "account." Ideally I want each account to have the full scale of time ranges covered (0 - 24). This involves having people merge accounts, but I would want to make sure that the two (or three people if needed) who merge their accounts have at least 1 person who's strength is "Offensive" and one who's strength is "Defensive."


Example:

So if I were to have an "Offensive" Player who was available from 7 - 19, I would want to pair them with one or two other people of whom at least one would be "Defensive" who would be available for the missing time of 20 - 6. Say I have a "Defensive" player who is available from 20 - 6. They would then merge their accounts, and both play on the same account, one covering the time range from 7 - 19, and the other would cover the time range from 20 - 6.

It is going to be impossible probably to get every account to be covered for the full 24 hours, but I would like to get as close as possible. I would say the limit of players on one account is 3 total. Overlap of times is okay as well, so if you had two players, one who played 4 - 16 and one who played 13 - 5 who were Offensive and Defensive respectively, it would be okay to pair them together.

Below would be an example of what my data would look like:


PlayerStrengthTime StartTime Finished
AOffensive018
BOffensive520
CDefensive417
DDefensive239
EDefensive1910
FOffensive164
GDefensive1224
HOffensive2312
etc.etc.etc.etc.

<tbody>
</tbody>



I don't know if it is exactly possible to write code to do this (either in regular excel using formulas or with VBA). If this doesn't seem like something that can be done, or it is something one of you knows can't be done, just go ahead and say that haha.

I don't need this to actually go ahead and merge the accounts, I would just like it to maybe show in the next column or two the potential matches each person would have.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Would a chart help?
qdAGwXY.png



Book1
BCDEFGHIJK
2PlayerStrengthStartEnd012345
3AOffensive018OOOOOO
4BOffensive520O
5CDefensive417DD
6DDefensive239DDDDDD
7EDefensive1910DDDDDD
8FOffensive164OOOOO
9GDefensive1224
10HOffensive2312OOOOOO
11
12Offensive Count333333
13Defensive Count222233
Sheet1
Cell Formulas
RangeFormula
F3=REPT(LEFT($C3), IF($E3<$D3, OR(F$2<=$E3, F$2>=$D3), AND(F$2>=$D3, F$2<=$E3)))
F12=COUNTIF(F$3:F$10, "O")
F13=COUNTIF(F$3:F$10, "D")
 
Last edited:
Upvote 0
That's actually a very good way to set it up to start with. So now the idea is to have excel figure out which players can be paired together to try and make sure the entire 0-24 if covered as much as possible. Like in the example, you see that Player A is missing 19-24 and he is an Offensive Player. A good match for him would be Player G or E, as they are Defensive, and their times would ensure that the entire 0-24 is covered. However, once it is decided which player to pair Player A with, that player can no longer be paired with anyone else unless you want to try and merge 3 accounts.

This is where we get into trying to get excel to make sure all 24 hours are covered by pairing people up, but also doing it optimally, AKA as many pairings cover as much of the 24 hours as possible.

Does that make sense what I am trying to get excel to do? I am not sure if it can be done honestly. I don't know if Excel can be programmed to try and optimize pairing things.
 
Last edited:
Upvote 0
First, I want to correct the mistake I made: the chart shows 25 hours. The last hour it should show is 23. So delete the last column.

The first hour is from 0 to 1, the last hour should be 23. If Person A is available from 0 to 18, he or she cannot cover the hour between 18 and 19: hour 18 should be blank. The formula in F2 should be changed to:

=REPT(LEFT($C3), IF($E3 < $D3, OR(F$2<=$E3-1, F$2>=$D3), AND(F$2>=$D3, F$2<=$E3-1)))

Solving the pairs problem formulaically, either in a worksheet or with VBA is beyond me. I included the counts of Offensive and Defensive at the bottom and highlighted the hours where only one of the two categories is available.

You could use this chart and call it your Availability chart. Then use a second copy for a Schedule chart. Enter trial scheduled start and end times. If you have a zero in either of the two Count rows, your schedule needs to be adjusted.
 
Upvote 0
Thinking about this.

dILCXl3.png


Compare the pairing of {A, E} with the pair {A, G}. More hours are covered with {A, G}—the sum of the counts of ones and twos is closer to 24 than with {A, E}.

For a first cut, pair each Offensive with every Defensive player. Rank all the combinations by the combined counts of ones and twos, greater is better. I am unsure how to proceed from there, but you now know the strongest couples. The addition of a possible third player to a team...
 
Upvote 0
This a great start. Thanks a ton man. I am going to play around with this to see if I can figure something out. I will repost in a new topic this question with your ideas implemented to see if someone else has any ideas.

Again, thanks!!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,793
Messages
6,121,614
Members
449,039
Latest member
Mbone Mathonsi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top