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 |
||
' |
'guy gal'=.y |
||
if. |
if. gal e. engaged do. |
||
pref=. |
pref=.gal{fpref |
||
fiance=. engaged i. |
fiance=. engaged i.gal |
||
if. |
if. guy <&(pref&i.) fiance do. |
||
engaged=. |
engaged=. gal guy} _ fiance} engaged |
||
end. |
end. |
||
else. |
else. |
||
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: |