# NOT RUN {
## -----------------------
## --- Marriage problem
## 7 men, 6 women, random preferences:
hri(nStudents=7, nColleges=6, seed=4)
## 3 men, 2 women, given preferences:
s.prefs <- matrix(c(1,2, 1,2, 1,2), 2,3)
c.prefs <- matrix(c(1,2,3, 1,2,3), 3,2)
hri(s.prefs=s.prefs, c.prefs=c.prefs)
## 3 men, 2 women, given preferences:
s.prefs <- matrix(c("x","y", "x","y", "x","y"), 2,3)
colnames(s.prefs) <- c("A","B","C")
c.prefs <- matrix(c("A","B","C", "A","B","C"), 3,2)
colnames(c.prefs) <- c("x","y")
hri(s.prefs=s.prefs, c.prefs=c.prefs)
## --------------------------------
## --- College admission problem
## 7 students, 2 colleges with 3 slots each, random preferences:
hri(nStudents=7, nSlots=c(3,3), seed=21)
## 7 students, 2 colleges with 3 slots each, given preferences:
s.prefs <- matrix(c(1,2, 1,2, 1,NA, 1,2, 1,2, 1,2, 1,2), 2,7)
c.prefs <- matrix(c(1,2,3,4,5,6,7, 1,2,3,4,5,NA,NA), 7,2)
hri(s.prefs=s.prefs, c.prefs=c.prefs, nSlots=c(3,3))
## 7 students, 2 colleges with 3 slots each, given preferences:
s.prefs <- matrix(c("x","y", "x","y", "x",NA, "x","y",
"x","y", "x","y", "x","y"), 2,7)
colnames(s.prefs) <- c("A","B","C","D","E","F","G")
c.prefs <- matrix(c("A","B","C","D","E","F","G",
"A","B","C","D","E",NA,NA), 7,2)
colnames(c.prefs) <- c("x","y")
hri(s.prefs=s.prefs, c.prefs=c.prefs, nSlots=c(3,3))
## 7 students, 3 colleges with 3 slots each, incomplete preferences:
hri(nStudents=7, nSlots=c(3,3,3), seed=21, s.range=c(1,3))
s.prefs <- matrix(c('S1', 'S2', NA,
'S3', 'S1', NA,
'S1', NA, NA,
NA, NA,NA,
'S2', 'S1', 'S5'),
nrow = 3, ncol = 5)
# Note that we explicitly allow for the existence of entries refering to colleges
# that do not exist. A warning is generated and the entry is ignored.
colnames(s.prefs) <- c('A', 'B', 'C', 'D', 'E')
c.prefs <- matrix(c('B', 'C','D', 'A',
'C', 'D', NA, NA,
'D', 'B', 'A', 'E'),
nrow = 4, ncol = 3)
colnames(c.prefs) <- c('S1', 'S2', 'S3')
hri(s.prefs=s.prefs, c.prefs=c.prefs, nSlots=c(3,3,3), check_consistency = TRUE)
## --------------------
## --- Summary plots
## 200 students, 200 colleges with 1 slot each
res <- hri(nStudents=200, nColleges=200, seed=12)
plot(res)
plot(res, energy=TRUE)
# }
Run the code above in your browser using DataLab