I need to determine which sorting algorithm would be the best for my situation. I am running a tournament for 16 people, and each tournament, every person earns a certain number of points.
These 16 people are grouped into four teams of four, and their averages should ideally be as close together as possible (to make the fairest teams).
I am not sure which sorting algorithm would be best for this. I have tried this with a greedy bin packing algorithm, which did not produce optimal teams. I have also read that this might be a knapsack or cutting stock problem. From what I have read, I believe the new algorithm would ideally use offline sorting. If anybody knows what algorithm would be best for my situation, please let me know. My code is below:
from typing import List
import binpacking
import numpy as np
import math
levels = np.genfromtxt('points.txt', dtype = 'float')
players = np.genfromtxt('players.txt', dtype = 'str')
playerLevels = zip(players, levels)
playerLevelsList = list(playerLevels)
averageLevels = sum(levels)/len(levels)
print('Average points are', averageLevels)
bins = binpacking.to_constant_bin_number(playerLevelsList, 4, 1)
a, b, c, d = [ [individualArray] for individualArray in bins]
a = a[0]
b = b[0]
c = c[0]
d = d[0]
a1 = a[1]
b1 = b[1]
c1 = c[1]
d1 = d[1]
team1 = list(zip(*a))
team2 = list(zip(*b))
team3 = list(zip(*c))
team4 = list(zip(*d))
points1 = round(sum(team1[1])/4, 2)
points2 = round(sum(team2[1])/4, 2)
points3 = round(sum(team3[1])/4, 2)
points4 = round(sum(team4[1])/4, 2)
stdev1 = math.trunc(np.std(team1[1]))
stdev2 = math.trunc(np.std(team2[1]))
stdev3 = math.trunc(np.std(team3[1]))
stdev4 = math.trunc(np.std(team4[1]))
print('Team 1 is', team1[0])
print('Team 2 is', team2[0])
print('Team 3 is', team3[0])
print('Team 4 is', team4[0])
print('\n-----Stats-----')
print('Team 1 Average is', points1, 'with a standard deviation of', stdev1)
print('Team 2 Average is', points2, 'with a standard deviation of', stdev2)
print('Team 3 Average is', points3, 'with a standard deviation of', stdev3)
print('Team 4 Average is', points4, 'with a standard deviation of', stdev4)```