Results 1 to 19 of 19

Gale Shapley matching (Stable Marriage problem)

Threaded View

  1. #8
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Gale Shapley matching (Stable Marriage problem)

    now more dictionary oriented (this is exemplary why/when you should use dictionaries)

    Sub M_snb()
       sn = Split("abe abi eve cath ivy jan dee fay bea hope gay _bob cath hope abi dee eve fay bea jan ivy gay _col hope eve abi dee bea fay ivy gay cath jan _dan ivy fay dee gay hope eve jan bea cath abi _ed jan dee bea cath fay eve abi ivy hope gay _fred bea abi dee gay eve ivy cath jan hope fay _gav gay eve ivy bea cath abi dee hope jan fay _hal abi eve hope fay ivy cath jan bea gay dee _ian hope cath dee gay bea abi fay ivy jan eve _jon abi fay jan gay eve bea dee cath ivy hope", "_")
       sp = Split("abi bob fred jon gav ian abe dan ed col hal _bea bob abe col fred gav dan ian ed jon hal _cath fred bob ed gav hal col ian abe dan jon _dee fred jon col abe ian hal gav dan bob ed _eve jon hal fred dan abe gav col ed ian bob _fay bob abe ed ian jon dan fred gav col hal _gay jon gav hal fred bob abe col ed dan ian _hope gav jon bob abe ian dan hal ed col fred _ivy ian col hal gav fred bob abe ed jon dan _jan ed hal gav abe bob jon col ian fred dan", "_")
         
       Set d_00 = CreateObject("scripting.dictionary")
       Set d_01 = CreateObject("scripting.dictionary")
       Set d_02 = CreateObject("scripting.dictionary")
       
       For j = 0 To UBound(sn)
          d_00(Split(sn(j))(0)) = ""
          d_01(Split(sp(j))(0)) = ""
          d_02(Split(sn(j))(0)) = sn(j)
          d_02(Split(sp(j))(0)) = sp(j)
       Next
        
       Do
         For Each it In d_00.keys
           If d_00.Item(it) = "" Then
             st = Split(d_02.Item(it))
             For jj = 1 To UBound(st)
               If d_01(st(jj)) = "" Then
                 d_00(st(0)) = st(0) & vbTab & st(jj)
                 d_01(st(jj)) = st(0)
                 Exit For
               ElseIf InStr(d_02.Item(st(jj)), " " & st(0) & " ") < InStr(d_02.Item(st(jj)), " " & d_01(st(jj)) & " ") Then
                 d_00(d_01(st(jj))) = ""
                 d_00(st(0)) = st(0) & vbTab & st(jj)
                 d_01(st(jj)) = st(0)
                 Exit For
               End If
             Next
           End If
         Next
       Loop Until UBound(Filter(d_00.items, vbTab)) = d_00.Count - 1
       
       MsgBox Join(d_00.items, vbLf)
    End Sub
    Last edited by snb; 08-12-2016 at 05:08 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Weirdest problem ever - excel not matching matching text
    By andre_as in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-19-2015, 03:33 AM
  2. 40 years of marriage...
    By TMS in forum The Water Cooler
    Replies: 21
    Last Post: 04-08-2014, 01:56 AM
  3. Formula to compute oceanic Shapley value for largest player.
    By alexpsyched in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-15-2013, 03:58 AM
  4. Stable formula
    By Syahira in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 07-28-2006, 03:10 PM
  5. [SOLVED] Stable chart
    By How too create a stable chart? in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 01-24-2006, 05:40 AM
  6. [SOLVED] in ms excel 2003 research tool thomson gale is not found why?
    By Arul raj in forum Excel General
    Replies: 1
    Last Post: 10-03-2005, 08:05 AM
  7. [SOLVED] Marriage of two formulas
    By emerald_dragonfly in forum Excel General
    Replies: 2
    Last Post: 07-04-2005, 10:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1