Need help identifying a league scheduling algorithm

algorithmsscheduling

I am trying to create a sports league scheduler. I am having trouble identifying an algorithm to help me efficiently fill in each slot.

Sample data to build the schedule would be:

  1. 10 teams
  2. Each team plays each other 1 time (45 total games
    required)
  3. Each team plays no more than 1 time per day
  4. In my testing I am using 9 days with 5 slots per day.

Combo Table (contains 45 combos)

ID
Team1ID
Team2ID
bitAssigned

Schedule Table (contains 45 time slots)

scheduleID
homeTeamID
awayTeamID
GameDate
GameTime

Right now my existing procedures fill about 90% of the slots leaving 10% of my slots empty to a scheduling conflict based off the rules above.

I loop over my schedule table in ascending date/time order.
My first slot could be Saturday at 8am.
I query a list of teams that haven't been scheduled yet. I then make an array of possible combinations of those teams. I then use that array to pull 1 random record from my combinations table from of combinations that haven't been scheduled yet and I place those teams on the schedule. I then set that combination as used.

I repeat the loop over and over again and each time my list of available teams gets smaller and my array as a result is smaller too.

I'm finding that some days go fine, and on other days my final last 2 remaining teams have already played in a previous week so they are not added to the schedule again.

The only thing I havent tried yet is to "reset" the conflict days and try them over again to see if I get better placements.

Does anyone have any suggestions?

Best Answer

Here's an algorithm I invented myself. I don't know if it already exists or is actually the round robin implementation:

1 4    1 5   1 6   1 3   1 2
2 5    4 6   5 3   6 2   3 4
3 6    2 3   4 2   5 4   6 5

basically you start with

rotation pic

and always keep the 1 in the same position and rotate the rest.

That way you will always get a schedule of unique matches. This is extremely easy to implement and scales with any number of opponents, even or uneven. If you have an uneven number of opponents, just don't place a team in the 1 position and they have a free round.

Related Topic