Skip to content

Instantly share code, notes, and snippets.

@jcheong0428
Created July 14, 2019 05:53
Show Gist options
  • Select an option

  • Save jcheong0428/e3b2b4e7ead55d023873cb015aa531d0 to your computer and use it in GitHub Desktop.

Select an option

Save jcheong0428/e3b2b4e7ead55d023873cb015aa531d0 to your computer and use it in GitHub Desktop.
Estimates the time needed for brute force optimal assignment for group size 10.
%%timeit
# Second gist for Hungarian post.
# Estimates the time needed for brute force optimal assignment for group size 10.
# Takes about 3 minutes.
maxsums, colixs = [], []
group_size = 10
np.random.seed(0)
preferences = np.random.rand(group_size,group_size)
rowix = list(range(group_size)) # rows don't need to be permuted
# Permute choice of columns.
for colix in itertools.permutations(range(group_size)):
_sum = np.sum(preferences[rowix,colix])
maxsums.append(_sum)
colixs.append(colix)
maxsum = np.max(maxsums)
maxcolix = colixs[np.argmax(maxsums)]
print("Total preference:", maxsum)
print("Row:",rowix, "Col:", maxcolix)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment