Reminders:
Class Next Monday (05/08)
In a small world…
Question. How should we assign students to internships?
Agents have preferences in the form of a strict ranking of alternatives
How do we decide whether a matching “respects” agents’ preferences?
Given:
We say $(s, t)$ is a blocking pair if
Gale-Shapley 1962
Input:
Output:
Theorem (Gale-Shapley 1962). Yes! Stable matchings always exist, and there is an efficient algorithm to find one.
lec23-stable-matchings.zip
Claim 1. Gale-Shapley terminates after at most $n (n - 1) + 1$ applications.
Claim 2. When Gale-Shapley terminates, the resulting matching is stable.
Theorem (Gale-Shapley, 1962). Every instance of the stable marriage problem admits a stable matching. If there are $n$ students and internships, a stable matching can be found in $O(n^2)$ time.
matching med students with residencies
Stable matchings in a decentralized setting
Is it reasonable to assume all agents explicitly know their own preferences?
Do not assume preferences are explicitly known:
Note. Gale-Shapley can be implemented with $O(n^2 \log n)$ queries.
Theorem (Gonczarowski, Nisan, Ostrovsky, R–). Any mechanism that finds or verifies a stable matching uses $\Omega(n^2)$ queries in the worst case.
Finding “almost stable” matchings also requires $\Omega(n^2)$ queries.
“early binding commitments” either lead to
Agent
class for a student/internship
AgentVisualizer
stores DOM elements to represent an Agent
SMInstance
MatchingViewer
keeps track of linesGaleShapley
steps through proposal/rejection roundsWhat is wrong with this method?
this.receiveProposal = function (agentID) {
if (!this.prefList.includes(agentID)) return agentID;
if (this.curMatch == null) {
this.curMatch = agentID;
return null;
}
if (this.prefers(agentID, this.curMatch)) {
let rejected = this.curMatch;
curMatch = agentID;
return rejected;
}
return agentID;}
let a = 4
a = 4
var a = 4
SomeClass = function () {
this.a = 4;
this.foo = function () {
a = 5;
...
a = 6;
}
}
The Setup. AgentVisualizer
stores this.prefElts
, an array of DOM elements
Draw the elements in preference rank order
flexbox
to handle the actual drawingYou can associate data with DOM elements
In JS, this can be done by setting the dataset
attribute:
const pref = document.createElement("div");
pref.classList.add("pref-item");
pref.innerText = '' + id;
pref.dataset.rank = this.agent.prefList.indexOf(id);
pref.dataset.id = id;
this.prefs.appendChild(pref);
this.prefElts.push(pref);
this.sortPreferenceElements = function () {
for (let pe of this.prefElts) {
pe.dataset.rank = this.agent.prefList
.indexOf(Number(pe.dataset.id));
}
this.prefElts.sort((a, b) => a.dataset.rank - b.dataset.rank);
for (let elt of this.prefElts) {
this.prefs.appendChild(elt);
}}