The Stable Matching Algorithm - Examples and Implementation

Поділитися
Вставка
  • Опубліковано 14 січ 2017
  • Please support me on Patreon: / thesimpleengineer
    / thesimpengineer / schachte
    ryan-schachte.com
    Don't forget to subscribe! ➨ Website -
    ➨ New Video! - • Docker Client, Images ...
    ➨ / the-simple-engineer-80...
    ➨ Github - github.com/schachte
    ---------------------------------------------------------------
    Click Expand to View All Code and Related Links..
    Code:
    github.com/Schachte/stable-ma...
    NRMP Example:
    www.nrmp.org/wp-content/upload...
    NRMP Website:
    www.nrmp.org/
    Wikipedia:
    en.wikipedia.org/wiki/Stable_...
    Sorority Rush Research:
    www.uibk.ac.at/economics/bbl/...
    NYC High School Stable Matching:
    dash.harvard.edu/bitstream/ha...
    This is a video talking about the background involving gayle and shapley's marriage proposal algorithm. Also known as the propose and reject algorithm. I walk through coding the implementation in python, the background, step-by-step example and some applications of the GS algorithm.
  • Навчання та стиль

КОМЕНТАРІ • 45

  • @elemeno0pee
    @elemeno0pee 4 роки тому +5

    Amazing explanation. My mind was blown by the fact that you get the same outcome regardless of starting from the top or bottom.

  • @vanon2634
    @vanon2634 5 років тому +2

    Great video!! Excellent explanations and meaningful code!!

  • @SamarAshrafii
    @SamarAshrafii 8 місяців тому

    Perfect. IT could not be better than this. Thank you for sharing this video with us.

  • @SarabjotSingh294
    @SarabjotSingh294 3 роки тому

    Thanks for the explanation! I really find it useful.

  • @ryanlevy6692
    @ryanlevy6692 3 роки тому +1

    As a Ryan, the example was a nice boost to morale

  • @ketankulkarni427
    @ketankulkarni427 3 роки тому +5

    Ama-f*cking-zing !! Loved it !! Thank you so much buddy ! GBU.

  • @II_xD_II
    @II_xD_II 4 роки тому +1

    thats the cleanest and best best structure of dictionary damn

  • @humblenut1303
    @humblenut1303 2 роки тому

    I love it! appreciate so much!!!

  • @Pepegasus4
    @Pepegasus4 4 роки тому

    YOU ARE THE BEST! MORE THAN JUST A THANK YOU!!!

  • @jonny9044
    @jonny9044 2 роки тому +1

    Hey, great video but i have a question for the example. Could you elaborate on what does it actually mean that the proposee gets the worst possible match, since lizzy gets the best pick for him. Thanks

  • @CubosAssistant
    @CubosAssistant 4 роки тому +3

    Great video! Is there an algorithm to determine ranking of preference for each individual based on say, interests, age, etc?

  • @retford74
    @retford74 3 роки тому

    Very informative and explained. How can I DM you pls? I have a question on something that I'm currently thinking of setting up a start up with matching algorithm.

  • @AliRazaBhai
    @AliRazaBhai 5 років тому

    Thanks, Its really helps me. Love it

  • @spencersmith6555
    @spencersmith6555 7 років тому +8

    I'm you're biggest fan! Your vids are so cool you must be so smart and have so many cool friends. Also, your voice is so smooth and deep it's so attractive...

    • @NattapongPUN
      @NattapongPUN 7 років тому

      Me too. very clear

    • @arashfarvardin
      @arashfarvardin 5 років тому +1

      This is still stable because simple engineer doesn't prefer spencer over his woman 2.

  • @chisomchukwuma3545
    @chisomchukwuma3545 2 роки тому

    Hi.
    Can Irving's algorithm be used to build a roommate recommendation system?
    P.s: any response is good.

  • @calvinweyers712
    @calvinweyers712 7 днів тому

    What happens in the 3 couples case?

  • @cristinacasconmartin4090
    @cristinacasconmartin4090 7 років тому +1

    thanks for the video, but for the possibility existing singles?

    • @categorille8330
      @categorille8330 5 років тому

      there cant be singles, the algorithm wouldn't work.

    • @II_xD_II
      @II_xD_II 4 роки тому

      that's a silly question

  • @II_xD_II
    @II_xD_II 4 роки тому

    can there be multiple stable matches ???

  • @connormorris5589
    @connormorris5589 4 роки тому

    I'm trying to incorporate this code into a website that I'm working on. Anybody have any idea how to do that?

  • @ashagaire9377
    @ashagaire9377 6 років тому

    can u help me with which algorithm should i use for a match making according to the matching requirements that male gives which matches with women's requirement which women gives herself and vice versa. hoping for quick response

  • @MiguelHernandez-pt1kl
    @MiguelHernandez-pt1kl 6 років тому

    Can you please make a video on the hospitals/residents problem (aka college/students problem aka admissions problem). This is where you can accept more than one match, for example, a college can accept 10 students and each student has a ranking of their preferred college, etc.

    • @bizzey2714
      @bizzey2714 3 роки тому +1

      All you need to be is keep the same code -- just have another data structure storing the values of the maximum vacancy (quota) for each hospital, and iterate the matching until the quota is 0 (we reduce the quota by 1 when a matching occurs and increase it by one when an already matched student trades up/changes to a higher priority hospital/valid match)

    • @abbadmed2667
      @abbadmed2667 2 роки тому

      @@bizzey2714 hey , can please write the code for it it will really help a lot . thank you

    • @bizzey2714
      @bizzey2714 2 роки тому

      @@abbadmed2667 I can’t share the code bc it falls under disclosure/publication rules (for me), but I don’t mind helping you out with your code or something

    • @abbadmed2667
      @abbadmed2667 2 роки тому

      @@bizzey2714 ok thank you ,
      So, this is my code and I want to write a program that oriented student to their specialty in university , and each specialty can take multiple student (in this case cnm =1 , dsi=2 , rss=2),and the number of student can be more than the number of places (in this case one student not gonna have a place because there is only 5 places ).
      The program run with out a problem but the output is not correct .(and I couldn’t know why )
      .
      The output for this example should be ((a,cnm),(c,rss),(b,dsi),(e,dsi),(f,rss))
      If you could help me out I would really appreciate it.
      Thank you in advance
      this is mycode
      students = {
      'A': ['CNM', 'DSI', 'RSS'],
      'B': ['CNM', 'DSI', 'RSS'],
      'C': ['DSI', 'CNM', 'RSS'],
      'D': ['DSI', 'RSS', 'CNM'],
      'E': ['RSS', 'DSI', 'CNM'],
      'F': ['RSS', 'CNM', 'DSI']
      }
      choices = {
      'DSI': ['C', 'E','D', 'B','F','A'],
      'RSS': ['B','F','A', 'E', 'D','C'],
      'CNM': ['A', 'B','C', 'D','E','F']
      }
      rss=2
      cnm = 1
      dsi=2
      results = []
      students_with_out_choice =[]
      for student in students:
      students_with_out_choice.append(student)
      while (len(students_with_out_choice) > 0 ):
      for i in range (3):
      for student in students_with_out_choice:
      for choice in students[student]:
      if ((choice == "DSI" and dsi != 0) or (choice == "RSS" and rss != 0) or (choice == "CNM" and cnm != 0)):
      results.append([student, choice])
      students_with_out_choice.remove(student)
      if (choice == "DSI"):
      dsi -= 1
      if (choice == "RSS"):
      rss -= 1
      if (choice == "CNM"):
      cnm -= 1
      break
      else:
      for key, value in results:
      if choice == value:
      a= key
      etudiant_actuel = choices[choice].index(a)
      etudiant_proposer = choices[choice].index(student)
      if (etudiant_actuel >etudiant_proposer):
      students_with_out_choice.remove(student)
      students_with_out_choice.append(a)
      a = student
      break
      elif(i==2):
      students_with_out_choice.remove(student)
      break
      print(results)

  • @chloekimball536
    @chloekimball536 5 років тому

    Can someone please help me understand how to extend gate shapely algo when e.g 1 man doesnt wanna marry woman x under any circumstances

    • @Involent
      @Involent 4 роки тому +1

      Then he simply wouldn't enter the marriage pool at all. It would be analogous to a medical student who elects not to rank any residency programs at which he interviewed and sit out the Match instead.

  • @vitorpmh
    @vitorpmh Рік тому

    shouldnt the code keep track of the men's already proposed woman?

  • @mutiulmuhaimin9156
    @mutiulmuhaimin9156 3 роки тому

    File "E:\ClassWork\3.1\CSE 4591 DM\Assignment5_TMA_plussix\stable.py", line 44, in begin_matching
    for woman in preferred_rankings_men[man]:
    TypeError: unhashable type: 'list'
    Can't find the reason for this problem, nor how to solve it.

  • @a1988ditya
    @a1988ditya 3 роки тому +2

    C++ code if anyone interested - not the most optimised (Too lazy to make changes)
    std::set getMatching(std::map men,
    std::map women) {
    std::set match;

    std::unordered_map menCurrMatch;
    std::unordered_map womenCurrMatch;
    std::unordered_map womenMatchReverseLookup;
    std::set matchedMen;
    while (1) {
    bool change = false;
    for (auto& curr : men) {
    if (matchedMen.find(curr.first) != matchedMen.end()) {
    // Dont bother matched men
    continue;
    }
    std::string currMan = curr.first;
    std::string currWomen("");
    std::string nextWomen("");
    int startWomenIndex = 0;
    if (menCurrMatch.find(currMan) != menCurrMatch.end()) {
    startWomenIndex = menCurrMatch[currMan].second + 1;
    }
    for (int i = startWomenIndex; i < men[currMan].size(); i++) {
    currWomen = men[currMan][i];
    std::cout

  • @albertleo4329
    @albertleo4329 3 роки тому

    It was good but you should of scrolled up man, the youtube bar gets on the way when I pause for examination

    • @albertleo4329
      @albertleo4329 3 роки тому

      ok, you did scrolled down a little

  • @ThePositiev3x
    @ThePositiev3x 6 років тому

    19:10 But, in this example, women got better results then men.
    Men got 1-3-1-3
    Women got 1-2-1-2
    When we are saying best and worst, do we mean best/worst in all possible stable matchings? If so, I wouldn't say it's best to be in the left set.

    • @joestewart7150
      @joestewart7150 5 років тому +1

      He gave an odd example since in his example the outcome is always the same regardless of whether the males or the females do the proposing. When he says the men get their best options, he means that in no other stable matching would the men get better results.

    • @bizzey2714
      @bizzey2714 3 роки тому +2

      @@joestewart7150 That is not true. Stable Matching problem is beneficial for man/man optimal because the man always proposes (in the order of women in their pref list) while women can only trade-up/reject a proposal.

    • @jvmeerman
      @jvmeerman 3 роки тому +2

      Bizzey Joe Dangelewicz is right! If you calculate the final engagements when you let the women propose, the exact same 4 couples will be created. This is only because of the sets of preferences chosen in this example. With other preferences, there will be 2 different stable outcomes: depending on which gender is assigned to propose. If you compare the outcomes, the men will have a better result in the algorithm where they proposed, and the women have a better result in the algorithm where they proposed.

  • @II_xD_II
    @II_xD_II 4 роки тому +1

    only algorithm I don't enjoy learning ; :

  • @nwikeosiagwu9872
    @nwikeosiagwu9872 2 роки тому

    saying guaranteed after already stating that it is 100% is redundant