prolog - /* - - - - - - - - - - - - - - - - - - - - - - - -...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Gale-Shapley Algorithm for a Stable Matching, implemented in Prolog Written Jan. 17th 2007 by Markus Triska ([email protected]) Public domain code. Tested with SWI Prolog 5.6.25 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ :- use_module(library(assoc)). :- use_module(library(pairs)). man_preferences(a, [c,b,d,a]). man_preferences(b, [b,a,c,d]). man_preferences(c, [b,d,a,c]). man_preferences(d, [c,a,d,b]). woman_preferences(a, [a,b,d,c]). woman_preferences(b, [c,a,d,b]). woman_preferences(c, [c,b,d,a]). woman_preferences(d, [b,a,c,d]). %?- time(stable_marriage(M)). %@ % 654 inferences, 0.000 CPU in 0.000 seconds (0% CPU, Infinite Lips) %@ M = [a-d, b-a, c-b, d-c]. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Structures used: MPs is an association list associating men with their remaining preference lists. WPs is an association list with keys wm(Woman,Man) associated to
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/01/2010 for the course CS 884 taught by Professor Ed during the Spring '10 term at University of Exeter.

Page1 / 2

prolog - /* - - - - - - - - - - - - - - - - - - - - - - - -...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online