Stable marriage problem: Difference between revisions

Content added Content deleted
m (J: added whitespace to allow some syntax highlighting)
Line 373: Line 373:
propose=:4 :0
propose=:4 :0
'engaged etc'=.x
'engaged etc'=.x
'male feml'=.y
'guy gal'=.y
if. feml e. engaged do.
if. gal e. engaged do.
pref=.feml{fpref
pref=.gal{fpref
fiance=. engaged i.feml
fiance=. engaged i.gal
if. male <&(pref&i.) fiance do.
if. guy <&(pref&i.) fiance do.
engaged=. feml male} _ fiance} engaged
engaged=. gal guy} _ fiance} engaged
end.
end.
else.
else.
engaged=. feml male} engaged
engaged=. gal guy} engaged
end.
end.
engaged,:etc
engaged,:etc
Line 413: Line 413:
)
)
</lang>
</lang>

For most of this, males and females are both represented by indices. Rows of mpref are indexed by a male index and list female indices in priority order. Rows of pref are indexed by a female index and list male indices in priority order.

The key data structure here (the right argument for <code>GaleShap</code> and the left argument for <code>propose</code> lists the current engaged partner for each male (an index into feml or infinity if not engaged), and the next female on their list to propose to (an index into the columns of mpref).


Example use:
Example use: