Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Gale-Shapley Algorithm
# Gale-Shapley matching
# From
doInstall <- TRUE # Change to FALSE if you don't want packages installed.
toInstall <- c("devtools", "animation")
if(doInstall){install.packages(toInstall, repos = "")}
lapply(toInstall, library, character.only = TRUE)
# Source the daa() function:
nOptions <- 15 # Although these matrices don't have to have the same dims
mPrefs <- t(replicate(nOptions, sample(1:nOptions, nOptions)))
wPrefs <- replicate(nOptions, sample(1:nOptions, nOptions))
heatmap(mPrefs, Rowv = NA, Colv = NA)
heatmap(wPrefs, Rowv = NA, Colv = NA)
galeShapleyResult <- daa(nMen = nOptions,
nWomen = nOptions,
m.prefs = mPrefs,
w.prefs = wPrefs)
matchMatrix <- 1*(matrix(rep(galeShapleyResult$matches, each=nOptions),
heatmap(1-matchMatrix, Rowv = NA, Colv = NA)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.