You are on page 1of 25

1

CSE2003- Data Structures and Algorithms


J Component Report

A project report titled

THE STABILITY OF MARRIAGE AND COLLEGE


ADMISSIONS

By
19BCE1148 MUSKAN DHINGRA
19BCE1769 POOJA SARAVANAN

BACHELOR OF TECHNOLOGY
IN
COMPUTER SCIENCE AND ENGINEERING

Submitted to

Dr R. Rajalakshmi
School of Computer Science and Engineering

November 2020
2

DECLARATION BY THE CANDIDATE

I hereby declare that the report titled “STABILITY OF MARRIAGE


AND COLLEGE ADMISSIONS” submitted by Muskan
Dhingra(19BCE1148) and Pooja Saravanan(19BCE1769) to VIT
Chennai is a record of bona-fide work undertaken by me under the
supervision
Dr. R. Rajalakshmi, Associate Professor, SCOPE, Vellore Institute
of Technology, Chennai.

Signature of the Candidates


3

ACKNOWLEDGEMENT

We wish to express our sincere thanks and deep sense of gratitude to


our project guide, Dr. R. Rajalakshmi, School of Computer Science and
Engineering for her consistent encouragement and valuable guidance
offered to us throughout the course of the project work.

We are extremely grateful to Dr. R. Jagadeesh Kannan, Dean, School of


Computer Science and Engineering (SCOPE), Vellore Institute of
Technology, Chennai, for extending the facilities of the School towards our
project and for his unstinting support.

We express our thanks to our Head of the Department for his


support throughout the course of this project.

We also take this opportunity to thank all the faculty of the School for their
support and their wisdom imparted to us throughout the courses.

We thank our parents, family, and friends for bearing with us throughout
the course of our project and for the opportunity they provided us in
undergoing this course in such a prestigious institution.
4

BONAFIDE CERTIFICATE

Certified that this project report entitled “STABILITY OF MARRIAGE AND


COLLEGE ADMISSIONS” is a bona-fide work of MUSKAN DHINGRA
(19BCE1148), POOJA SARAVANAN (19BCE1769) carried out the “J”-
Project work under my supervision and guidance for CSE2003 – Data
structures and algorithms.

Dr. R. Rajalakshmi
School of Computer Science and Engineering (SCOPE)
5

TABLE OF CONTENTS

Ch. No Chapter Page Number

1 Abstract 6

2 Introduction 7

3 Algorithm 8

4 Data Structure Used 9

5 Literature Survey 10

6 Modules 11

7 Website Snippets 12

8 Code 14

9 Motivation 22

10 Why is this unique? 22

11 Individual contributions 23

12 Conclusion 24

13 Reference 25
6

ABSTRACT

● Stable Marriage Problem:

The Stable Marriage Problem states that given N men and N women, where
each person has ranked all members of the opposite sex in order of
preference, marry the men and women together such that there are no two
people of opposite sex who would both rather have each other than their
current partners. If there are no such people, all the marriages are “stable”.

● College Student matching:

Colleges and sent the entire list of preferences to these Colleges. Colleges
that received the application could see a student’s entire list of preferences
as well as where they ranked on the list. These Colleges would then decide
to accept, reject, or waitlist these students. In this process, some students
would get multiple offers and some would get none. After offers were
extended, and applicants accepted no more than one offer, the process would
be repeated two more times with the same preference lists. The Colleges that
still had room would extend new offers.
7

INTRODUCTION

The “stable marriage” problem is often described as follows. There are n men
and n women; each of the men has an order of preference on the women, and
each of the women has an order of preference on the men. A “matching” of
the people into n man-woman pairs is said to be unstable if there exist some
man and some woman who both prefer each other to their partner in the
matching. If there is no such pair, the matching is stable. At the beginning, all
the men and all the women are unpaired. In each round of the algorithm, take
each man in turn. If he is currently unpaired, he “proposes” to the woman
highest on his preference list that he has not before proposed to. If she is
unpaired, or if she prefers him to the man she is currently paired to, she
“accepts” (provisionally) the proposal, and they are paired together (her
current partner, if any, becomes unpaired). Continue for as many rounds as
necessary until no one is unpaired, then output the resulting matching.
The “college matching problem” is described as follows. First, each
student applies to their most preferred UNIVERSITY, and each university
rejects unranked applicants and retains its highest ranked applicants. The
rejected students then apply to their next highest preference, and the
process repeats until no rejections are issued by the colleges. Because no
student gets multiple offers, it makes room for more students to get offers.
In this specific algorithm, the students are the ones to propose, so they end
up with a better outcome than if the universities proposed. This makes
stating true preferences a dominant strategy for students.
Is it so that some more powerful model may allow for faster
algorithms?
While many “natural” algorithms for stable marriage do fit into these models,
there may be others that do not. Indeed, there exist problems for which
“computationally unnatural” operations, such as various types of hashing,
arithmetic operations, or even “cognitively natural” operations such as
processing through a neural network, do give algorithmic speedups.
The real question is: Can they do better than deterministic ones?
This question is especially fitting for the stable marriage problem as the
expected running time is known to be small when the preferences are chosen
uniformly at random.3 We give a negative answer to both hopes, as well as
several other related problems, thereby showing that answering a wide
variety of basic questions related to stable marriages requires a quadratic
number of queries (that is, requires querying nearly the entire preference
structure)
8

ALGORITHM

GALE SHAPLEY ALGORITHM

Gale–Shapley algorithm is an algorithm for finding a solution to the stable


matching problem, named for David Gale and Lloyd Shapley.
It takes polynomial time, and the time is linear in the size of the input
to the algorithm. Depending on how it is used, it can find either the solution
that is optimal for the participants on one side of the matching, or for the
participants on the other side. It is a truthful mechanism from the point of
view of the participants for whom it provides the optimal solution.
The idea is to iterate through all free men while there is any free man
available. Every free man goes to all women in his preference list according
to the order. For every woman he goes to, he checks if the woman is free, if
yes, they both become engaged. If the woman is not free, then the woman
chooses either says no to him or dumps her current engagement according
to her preference list. So an engagement done once can be broken if a woman
gets a better option. Time Complexity of the Gale-Shapley Algorithm is
O(n2).

● ALGORITHM FOR STABLE MARRIAGE:

Initialize all m ∈ M and w ∈ W to free


while ∃ freeman m who still has a woman w to propose to do
w := first woman on m's list to whom m has not yet proposed
if w is free then
(m, w) become engaged
else some pair (m', w) already exists
if w prefers m to m' then
m' becomes free
(m, w) become engaged
else
(m', w) remain engaged
end if
repeat

● ALGORITHM FOR COLLEGE MATCHING:

while(there is free student)


9

{
int s
for s=0 to total student
If sFree[s]==false
break;
for i=0 to total university && sFree[s]==false
select university = Sp[s][i];
if(there are slots available for current university)
decrease slot
add element to linked list [current university]
free the student
break;
if(no slots)
if(current student is more preferred by any other previous
admitted student)
free the student

DATA STRUCTURES USED

We need lists and arrays:

❏ To maintain list of free men and women


❏ To maintain list of available students and colleges
❏ To maintain list of possible matches for free women
❏ To maintain a list of possible matches for students.
❏ For an array of sets of women, the list of preferred men is maintained
as a list.
❏ For an array of sets of students, the list of preferred colleges is
maintained as a list.
10

LITERATURE SURVEY

Books Written in this context:

● The Stable Marriage Problem: Structure and Algorithms - Book by


Dan Gusfield and Robert W. Irving

This book probes the stable marriage problem and its variants as a rich
source of problems and ideas that illustrate both the design and analysis of
efficient algorithms. It covers the most recent structural and algorithmic
work on stable matching problems, simplifies and unifies many earlier
proofs, strengthens several earlier results, and presents new results and
more efficient algorithms.

Research papers in this context:

● Deferred Acceptance Algorithms


By Alvin E. Roth1- Harvard University
● Performance based stable matching using gale-shapley algorithm
By Elviwani, Andysah Putera Utama Siahaan, Liza Fitriana
● Distributed Stable Matching Problems
By Ismael Brito and Pedro Mesegue

Challenges faced:

Optimal Cheating in the Stable Marriage Problem: Before we derive the


optimal cheating strategy we consider the question: Suppose woman w is
allowed to reject proposals. Is it possible for a woman w to identify her
women-optimal partner by observing the sequence of proposals in the men-
propose algorithm? Somewhat surprisingly, the answer is yes! Our
algorithm to compute the optimal cheating strategy is motivated by the
observation that if a woman simply rejects all the proposals made to her,
then the best among those who have proposed to her is her women-optimal
partner. Hence by rejecting all her proposals, a woman can extract
information about her best possible partner. Using a backtracking
scheme, the deceitful woman can use the matching mechanism repeatedly to
find her optimal cheating strategy.
11

MODULES

● Stable matchmaking of men and women:


❏ Visual Representation
❏ Free men
❏ Free women
❏ Preference list of women
❏ Preference list of men
❏ Using arrays and linked lists, matching men and women

● Matchmaking of university with students:


❏ Free students
❏ Available universities for admission
❏ are slots available for current university
❏ Grade-criteria
❏ adding element to linked list [current university]
❏ current student more preferred by any other previous
admitted student
❏ Making the student free
12

WEBSITE-SNIPPETS
13
14

CODES

● FOR STABLE MARRIAGE:


#include <stdio.h>
#include <stdlib.h>

int main()
{
int ta;
printf("Enter number of test cases:\n");
scanf("%d",&ta);

while(ta--)
{
int n;
printf("\nEnter number of men or women:\n");
scanf("%d",&n);
int man2[n];
int man[n][n];
int women [n][n];
int man_ma[n],wom_ma[n];

int t;
printf("\nEnter table of preferences for women:\n");
for(int i=0;i<n;i++)
{
man2[i]=0;
scanf("%d",&t);
for(int j=0;j<n;j++)
{
scanf("%d",&women[t-1][j]);
women[t-1][j]--;
}
}

printf("Enter table of preferences for men:\n");


for(int i=0;i<n;i++)
{
man_ma[i]=-1;
wom_ma[i]=-1;
scanf("%d",&t);
for(int j=0;j<n;j++)
{
scanf("%d",&man[t-1][j]);
man[t-1][j]--;
}
}

int man1 =n;


15

while(man1>0)
{
for(int i=0;i<n;i++)
{
if(man_ma[i]==-1)
{
while(1)
{

if(wom_ma[man[i][man2[i]]]==-1)
{
man_ma[i]=man[i][man2[i]];
wom_ma[man[i][man2[i]]]=i;
man1--;
man2[i]++;
break;
}
else
{
int rank1,rank2;
for(int k=0;k<n;k++)
{
if(women[man[i][man2[i]]][k]==wom_ma[man[i][man2[i]]])
rank1=k;
if(women[man[i][man2[i]]][k]==i)
rank2=k;
}
if(rank1>rank2)
{
man_ma[wom_ma[man[i][man2[i]]]]=-1;
wom_ma[man[i][man2[i]]]=i;
man_ma[i]=man[i][man2[i]];
man2[i]++;
break;

}
man2[i]++;

}
}
}

}
printf("The match is:\n");
for(int i=0;i<n;i++)
{
printf("%d %d\n",i+1,man_ma[i]+1);
}
}
return 0;
}
16

OUTPUT:
17

● FOR COLLEGE MATCHMAKING:

#include <iostream>
#include <stdio.h>

using namespace std;

const int Total_University = 2;


const int Total_Student = 3;
const int U_Slot[Total_University]={2,1}; //Seat limit of university

//Student Preferences
int Sp[Total_Student][Total_University]={
{1,0},
{1,0}
};
//University Preferences
int Up[Total_University][Total_Student]={
{1,0,2},
{0,2,1}
};
18

//Linked List implementation


struct node
{
int data;
node *next;
};

class list
{
private:
node *head, *tail;
public:
list()
{
head=NULL;
tail=NULL;
}
void addElement(int value)
{
node *temp=new node;
temp->data=value;
temp->next=NULL;
if(head==NULL)
{
head=temp;
tail=temp;
temp=NULL;
}
else
{
tail->next=temp;
tail=temp;
}
}
void display()
{
node *temp=new node;
temp=head;
while(temp!=NULL)
{
cout<<"S"<<temp->data<<"\t";
temp=temp->next;
}
}

int getValueByIndex(int index)


{
node *temp=new node;
temp=head;
int i=0;
while(temp!=NULL)
{
19

if(i==index)
return temp->data;
i++;
temp=temp->next;
}
}

void setValueByIndex(int index,int value)


{
node *temp=new node;
temp=head;
int i=0;
while(temp!=NULL)
{
if(i==index)
temp->data=value;
i++;
temp=temp->next;
}
}

int getIndexByValue(int value)


{
node *temp=new node;
temp=head;
int i=0;
while(temp!=NULL)
{
if(temp->data == value)
return i;
i++;
temp=temp->next;
}
}

int length(){
node *temp=new node;
temp=head;
int i=0;
while(temp!=NULL)
{
i++;
temp=temp->next;
}
return i;
}
};
int freeStudent;
bool sFree[Total_Student];
int u_slot[Total_University];
void initialize(){
for(int i=0;i<Total_Student;i++){
sFree[i]=false;
u_slot[i] = U_Slot[i];
20

freeStudent = Total_Student;
}

int indexOf(int student,int universityNo){


for(int i=0;i<Total_Student;i++){
if(Up[universityNo][i] == student)
return i;
}
}

int LeastFavourStudentIndex(list U_to_S,int universityNo){


int maxIndex= indexOf(U_to_S.getValueByIndex(0),universityNo);
int maxElement;

for(int i=0; i< U_to_S.length(); i++){


if( indexOf(U_to_S.getValueByIndex(i),universityNo) > maxIndex){
maxIndex= indexOf(U_to_S.getValueByIndex(i),universityNo);
maxElement= U_to_S.getValueByIndex(i);
}
}

return U_to_S.getIndexByValue(maxElement);
}

bool currentPrefersMoreThanPrevious(list U_to_S,int s,int universityNo){


int currentStudentIndex= indexOf(s,universityNo);
for(int i=0;i < U_to_S.length(); i++){
int currentElementIndex = indexOf(U_to_S.getValueByIndex(i),universityNo);
if(currentStudentIndex < currentElementIndex)
return true;
}
return false;
}

void changePreviousToCurrent(list U_to_S,int s,int universityNo){


int currentStudentIndex= indexOf(s,universityNo);

for(int i=0; i < U_to_S.length(); i++){


int currentElementIndex = indexOf(U_to_S.getValueByIndex(i),universityNo);

if(currentStudentIndex < currentElementIndex){


int maxIndex = LeastFavourStudentIndex(U_to_S,universityNo);
sFree[U_to_S.getValueByIndex(maxIndex)]=false;
U_to_S.setValueByIndex(maxIndex, s);

}
}
int main()
21

initialize();
list U_to_S[Total_University];

while(freeStudent > 0){


int s;
for(s=0; s < Total_Student; ++s)
if(sFree[s] == false)
break;
for(int i=0; i< Total_University && sFree[s] == false; i++){
int selectedUniversity = Sp[s][i];

if(u_slot[selectedUniversity] > 0){


u_slot[selectedUniversity] -=1;
U_to_S[selectedUniversity].addElement(s);
sFree[s]=true;
freeStudent--;
break;
}

if(u_slot[selectedUniversity] == 0){
if(currentPrefersMoreThanPrevious(U_to_S[selectedUniversity],s,selectedUniversity)){
changePreviousToCurrent(U_to_S[selectedUniversity],s,selectedUniversity);
sFree[s]=true;
}
}
}
}
for(int i=0;i < Total_University; i++){
cout<<"University "<<i<<"- ";
U_to_S[i].display();
cout<<"\n";
}

return 0;
}

OUTPUT:
22

MOTIVATION

The motivation behind this project is to solve the situation of men and
women and as well as, the students. Also, to understand the algorithm used
in match-making. We wanted to make use of the most relevant techniques in
this modern world to solve the issue of finding colleges and as well as
someone for marriage within a matter of seconds. We tried our best to solve
the issues of students in finding the suitable universities for them, we tried
to solve this by giving a ladder for the career of students.

WHY IS THIS UNIQUE?

Normally, Gale- Shapley algorithm is used to match men and women for
marriage. In this project, we are considering two applications: marriage and
as well as university-student matchmaking. We have developed the code all
by ourselves and we have tried to solve the issue of matchmaking through
this project in seconds. Further, we have developed a front-end for the stable
marriage problem and added an aspect of user input.
23

INDIVIDUAL CONTRIBUTIONS

Muskan Dhingra:
• Developed the code for gale-Shapley
algorithm for stable marriage problem
and university-student matchmaking.
• Wrote code for the situation: If seats are
available for current university:
Decreasing the slot and hence adding the
element in the linked list and analysing
loops.
• Managed the back-end part.

Pooja Saravanan:

• Developed list with elements that specify which


student is matched to which college and who
remains unmatched.
• Managed the front-end part.
24

CONCLUSION

Gale and Shapley (1962) initiated and advanced what has grown into not
only a substantial academic literature on matching models and mechanisms,
but also an emerging empirical literature on market failure and market
organization, and a growing “economic engineering” practice of market
design.
This algorithm successfully matches the university with the student
and men with women. The result of this test is stable so that the optimal pair
formed. The Gale-Shapley algorithm determines the pair based on the weight
value of each student or men/women. If the position of the couple changes,
this means there is a new person who is more qualified. The algorithm has a
preference table that contains interest between both parties and positions.
Any installation made between candidates and positions in a set can be said
to be the allocation of stable pairs. But not all preference lists are a potential
stable partner. A stable pair will be determined in the last round.
A condition will result in a separate pair because a certain student’s
rank is higher than the one previously occupying that position. Although
engagement occurs, students who do not have a partner will someday
occupy an existing position. The more preference lists, the more
candidates to occupy certain positions.

Hence, this system is flexible and reliable.


25

REFERENCE LINKS

[1]
https://en.wikipedia.org/wiki/Stable_marriage_problem

[2]https://www.researchgate.net/publication/22063984
2_Stable_matching_with_couples_An_empirical_study

[3]https://www.researchgate.net/publication/22073981
5_Genetic_algorithms_for_the_sailor_assignment_problem

[4]https://www.yumpu.com/en/document/read/683880
2/stable-matching-theory-evidence-and-practical-design

[5]https://web.stanford.edu/~alroth/papers/GaleandSha
pley.revised.IJGT.pdf

You might also like