31.01.2014 Views

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

12.10 Stable Matching ( stable matching )<br />

We are given a bipartite graph G = (A∪B, E) in which the edges incident to every vertex<br />

are linearly ordered. <strong>The</strong> order expresses preferences. A matching M in G is stable if<br />

there is no pair (a, b) ∈ E \ M such that (1) a is unmatched or prefers b over its partner<br />

in M and (2) b is unmatched or prefers a over its partner in M. In such a situation a<br />

has the intention to switch to b and b has the intention to switch to a, i.e., the pairing is<br />

unstable.<br />

We provide a function to compute a correct input graph from the preference data, a<br />

function that computes the stable matching when the graph is given and a function that<br />

checks whether a given matching is stable.<br />

void StableMatching(const graph& G, const list& A,<br />

const list& B, list& M)<br />

<strong>The</strong> function takes a bipartite graph G with sides A<br />

and B and computes a maximal stable matching M<br />

which is A-optimal. <strong>The</strong> graph is assumed to be bidirected,<br />

i.e, for each (a, b) ∈ E we also have (b, a) ∈ E.<br />

It is assumed that adjacency lists record the preferences<br />

of the vertices. <strong>The</strong> running time is O(n + m).<br />

Precondition: <strong>The</strong> graph G is bidirected and a map.<br />

Sets A and B only contain nodes of graph G. In addition<br />

they are disjoint from each other.<br />

bool CheckStableMatching(const graph& G, const list& A,<br />

const list& B, const list& M)<br />

returns true if M is a stable matching in G. <strong>The</strong><br />

running time is O(n + m).<br />

Precondition: A and B only contain nodes from G.<br />

<strong>The</strong> graph G is bipartite with respect to lists A and<br />

B.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!