Created
January 6, 2020 17:09
-
-
Save stephlocke/66ec504b6f5e9f3529278464898672ae to your computer and use it in GitHub Desktop.
Quickly allocate some groups into partitions with other groups of similar size
This file contains 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
# Generate sample distributions | |
n = 1e2 | |
t = 3e6 | |
min_r = t/1000 | |
max_r = t/50 | |
c = 0 | |
r = vector(mode="numeric") | |
for(x in 1:n){ | |
k = floor(runif(1, min = pmin(min_r, t-c), max = pmin(max_r, t-c))) | |
k = ifelse(is.nan(k), min_r, k) | |
r[x] = k | |
c = c + k | |
} | |
sum(r) | |
# identify partitions | |
p = 10 | |
b = floor((max(r) - min(r)) / (p-1)) | |
partition_alloc = (r - min(r)) %/% b | |
partition_alloc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment