Answered step by step
Verified Expert Solution
Question
1 Approved Answer
in java Write a program that solves the classic stable marriage problem. This problem deals with a group of men and a group of women.
in java Write a program that solves the classic stable marriage problem. This problem deals with a group of men and a group of women.
The program tries to pair them up so as to generate as many stable marriages as possible. A set of marriages is unstable if
you can find a man and a woman who would rather be married to each other than to their current spouses in which case the two
would be inclined to divorce their spouses and marry each other The input file for the program will list all of the men, one
per line, followed by a blank line, followed by all of the women, one per line. The men and women are numbered according to their
positions in the input file the first man is # the second man is # and so on; the first woman is # the second woman is #
and so on Each input line except for the blank line separating men from women lists the persons name, followed by a colon,
followed by a list of integers. These integers are the marriage partner preferences of this particular person. For example, see
the following input line in the mens section: This line indicates that the person is named Joe and that his first choice for
marriage is woman # his second choice is woman # and so on Any women not listed are considered unacceptable to Joe.
Joe: The stable marriage problem is solved by the following algorithm: assign each person to be free.
while some man M with a nonempty preference list is free
W first woman on Ms list.
if some man P is engaged to W
assign P to be free.
assign M and W to be engaged to each other.
for each successor Q of M who is on Ws list
delete W from Qs preference list.
delete Q from Ws preference list.
Consider the following input:
Man :
Man :
Man :
Man :
Woman :
Woman :
Woman :
Woman :
The following is a stable marriage solution for this input:
Man and Woman
Man and Woman
Man and Woman
Man and Woman
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started