Agent.java
Representation of an agent
ArrayList<Agent> prefList
Agent
, etcAgent curMatch
curMatch = null
indicates agent is not matchedcurIndex
is index of curMatch
in prefList
curIndex = -1
Agent
Instance Methodsboolean prefers(Agent a, Agent b)
returns true
if this agent prefers a
to b
prefList
agent to not being matched (i.e., curMatch == null
) to being matching with agent not in prefList
null
parameter indicates not being matchedvoid proposal(Agent a)
this agent receives proposal from Agent a
void refusal()
this agent was refused by curMatch
curMatch
is last in prefList
, unmatch and returncurMatch
to next in prefList
, and proposeSMInstance
ArrayList<Agent> hospitals
ArrayList<Agent> residents
hospitals
/residents
(r, h)
where:
h = r.curMatch
r = h.curMatch
Matching
a class for dealing with matchings
ArrayList
of Pair<Agent>
sSMInstance
Methodsvoid computeStableMatching()
use the McVitie & Wilson algorithm to compute a stable matching
curMatch
r
sets curMatch
before making first proposal
Matching getMatching()
return a Matching
consisting of pairs (r, h)
where r = h.curMatch
and h = r.curMatch
void setMatching(Matching m)
Pair<Agent> getBlockingPair()
boolean isStable()
Agent
classAgentTester
to test each method