Stable marriage problem: Difference between revisions

m (J: added whitespace to allow some syntax highlighting)
Line 373:
propose=:4 :0
'engaged etc'=.x
'maleguy femlgal'=.y
if. femlgal e. engaged do.
pref=.femlgal{fpref
fiance=. engaged i.femlgal
if. maleguy <&(pref&i.) fiance do.
engaged=. femlgal maleguy} _ fiance} engaged
end.
else.
engaged=. femlgal maleguy} engaged
end.
engaged,:etc
Line 413:
)
</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:
6,962

edits