Created
July 14, 2019 05:53
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %%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