Compare two data Structure and Suggest the best match
up vote
0
down vote
favorite
Hi all I have two structure that is Map<String,Map<String,String>>
.The first Map structure is a hospitals preferences example <Hospital name,<Student,Preferences>>
.
The second map is a student preferences example <Student,<Hospital,Preferences>>
.
How can I compare both and find the Best matches according to given Preference.
Find the data below
First map
{St. Luke's={ Martin Fowler= 2, Alan Turing= 1}, Olathe Medical Center={ Martin Fowler= 2, Alan Turing= 1}}
Second Map
{Martin Fowler={ Olathe Medical Center= 1, St. Luke's= 2}, Alan Turing={ Olathe Medical Center= 1, St. Luke's= 2}, Martin Fowler={ Olathe Medical Center= 1, St. Luke's= 2}}
Code for creating this structure is
public Map<String,Map<String,String>> readingFile(String filename) {
Map<String,String> preference = new HashMap<String,String>();
Map<String,Map<String,String>> DataPreference = new HashMap<String,Map<String,String>>();
CSVReader reader = null;
try {
reader = new CSVReader(new FileReader(filename));
String line;
while ((line = reader.readNext()) != null) {
preference.put(line[1], line[2]);
DataPreference.put(line[0], preference);
}
System.out.println(DataPreference);
}
catch (IOException |ArrayIndexOutOfBoundsException e) {
System.out.println("File empty or File not fond in the given Path ");
}
return DataPreference;
}
Thanks
java algorithm data-structures compare maps
add a comment |
up vote
0
down vote
favorite
Hi all I have two structure that is Map<String,Map<String,String>>
.The first Map structure is a hospitals preferences example <Hospital name,<Student,Preferences>>
.
The second map is a student preferences example <Student,<Hospital,Preferences>>
.
How can I compare both and find the Best matches according to given Preference.
Find the data below
First map
{St. Luke's={ Martin Fowler= 2, Alan Turing= 1}, Olathe Medical Center={ Martin Fowler= 2, Alan Turing= 1}}
Second Map
{Martin Fowler={ Olathe Medical Center= 1, St. Luke's= 2}, Alan Turing={ Olathe Medical Center= 1, St. Luke's= 2}, Martin Fowler={ Olathe Medical Center= 1, St. Luke's= 2}}
Code for creating this structure is
public Map<String,Map<String,String>> readingFile(String filename) {
Map<String,String> preference = new HashMap<String,String>();
Map<String,Map<String,String>> DataPreference = new HashMap<String,Map<String,String>>();
CSVReader reader = null;
try {
reader = new CSVReader(new FileReader(filename));
String line;
while ((line = reader.readNext()) != null) {
preference.put(line[1], line[2]);
DataPreference.put(line[0], preference);
}
System.out.println(DataPreference);
}
catch (IOException |ArrayIndexOutOfBoundsException e) {
System.out.println("File empty or File not fond in the given Path ");
}
return DataPreference;
}
Thanks
java algorithm data-structures compare maps
2
Please post what (code) you've tried so far. At least put the code for creation of these Maps and your attempt to iterate over them.
– Kartik
Nov 20 at 4:58
1
what should be the logic to find the "best match"? in your example input, what should be the output and why?
– Kartik
Nov 20 at 5:49
• If a hospital and student favor each other the most, they should be matched unless no other match is possible. • If a hospital and student despise each other the most, they should not be matched unless no other match is possible. • If perfect matches are not possible, hospitals should be matched to the student that is the best fit. • The end goal is that for every match, it wasn’t possible to form a better match for all parties involved @Kartik
– rahul uday
Nov 20 at 6:06
1
See en.wikipedia.org/wiki/Stable_marriage_problem
– Jim Mischel
Nov 20 at 13:52
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Hi all I have two structure that is Map<String,Map<String,String>>
.The first Map structure is a hospitals preferences example <Hospital name,<Student,Preferences>>
.
The second map is a student preferences example <Student,<Hospital,Preferences>>
.
How can I compare both and find the Best matches according to given Preference.
Find the data below
First map
{St. Luke's={ Martin Fowler= 2, Alan Turing= 1}, Olathe Medical Center={ Martin Fowler= 2, Alan Turing= 1}}
Second Map
{Martin Fowler={ Olathe Medical Center= 1, St. Luke's= 2}, Alan Turing={ Olathe Medical Center= 1, St. Luke's= 2}, Martin Fowler={ Olathe Medical Center= 1, St. Luke's= 2}}
Code for creating this structure is
public Map<String,Map<String,String>> readingFile(String filename) {
Map<String,String> preference = new HashMap<String,String>();
Map<String,Map<String,String>> DataPreference = new HashMap<String,Map<String,String>>();
CSVReader reader = null;
try {
reader = new CSVReader(new FileReader(filename));
String line;
while ((line = reader.readNext()) != null) {
preference.put(line[1], line[2]);
DataPreference.put(line[0], preference);
}
System.out.println(DataPreference);
}
catch (IOException |ArrayIndexOutOfBoundsException e) {
System.out.println("File empty or File not fond in the given Path ");
}
return DataPreference;
}
Thanks
java algorithm data-structures compare maps
Hi all I have two structure that is Map<String,Map<String,String>>
.The first Map structure is a hospitals preferences example <Hospital name,<Student,Preferences>>
.
The second map is a student preferences example <Student,<Hospital,Preferences>>
.
How can I compare both and find the Best matches according to given Preference.
Find the data below
First map
{St. Luke's={ Martin Fowler= 2, Alan Turing= 1}, Olathe Medical Center={ Martin Fowler= 2, Alan Turing= 1}}
Second Map
{Martin Fowler={ Olathe Medical Center= 1, St. Luke's= 2}, Alan Turing={ Olathe Medical Center= 1, St. Luke's= 2}, Martin Fowler={ Olathe Medical Center= 1, St. Luke's= 2}}
Code for creating this structure is
public Map<String,Map<String,String>> readingFile(String filename) {
Map<String,String> preference = new HashMap<String,String>();
Map<String,Map<String,String>> DataPreference = new HashMap<String,Map<String,String>>();
CSVReader reader = null;
try {
reader = new CSVReader(new FileReader(filename));
String line;
while ((line = reader.readNext()) != null) {
preference.put(line[1], line[2]);
DataPreference.put(line[0], preference);
}
System.out.println(DataPreference);
}
catch (IOException |ArrayIndexOutOfBoundsException e) {
System.out.println("File empty or File not fond in the given Path ");
}
return DataPreference;
}
Thanks
java algorithm data-structures compare maps
java algorithm data-structures compare maps
edited Nov 20 at 5:33
asked Nov 20 at 4:55
rahul uday
717
717
2
Please post what (code) you've tried so far. At least put the code for creation of these Maps and your attempt to iterate over them.
– Kartik
Nov 20 at 4:58
1
what should be the logic to find the "best match"? in your example input, what should be the output and why?
– Kartik
Nov 20 at 5:49
• If a hospital and student favor each other the most, they should be matched unless no other match is possible. • If a hospital and student despise each other the most, they should not be matched unless no other match is possible. • If perfect matches are not possible, hospitals should be matched to the student that is the best fit. • The end goal is that for every match, it wasn’t possible to form a better match for all parties involved @Kartik
– rahul uday
Nov 20 at 6:06
1
See en.wikipedia.org/wiki/Stable_marriage_problem
– Jim Mischel
Nov 20 at 13:52
add a comment |
2
Please post what (code) you've tried so far. At least put the code for creation of these Maps and your attempt to iterate over them.
– Kartik
Nov 20 at 4:58
1
what should be the logic to find the "best match"? in your example input, what should be the output and why?
– Kartik
Nov 20 at 5:49
• If a hospital and student favor each other the most, they should be matched unless no other match is possible. • If a hospital and student despise each other the most, they should not be matched unless no other match is possible. • If perfect matches are not possible, hospitals should be matched to the student that is the best fit. • The end goal is that for every match, it wasn’t possible to form a better match for all parties involved @Kartik
– rahul uday
Nov 20 at 6:06
1
See en.wikipedia.org/wiki/Stable_marriage_problem
– Jim Mischel
Nov 20 at 13:52
2
2
Please post what (code) you've tried so far. At least put the code for creation of these Maps and your attempt to iterate over them.
– Kartik
Nov 20 at 4:58
Please post what (code) you've tried so far. At least put the code for creation of these Maps and your attempt to iterate over them.
– Kartik
Nov 20 at 4:58
1
1
what should be the logic to find the "best match"? in your example input, what should be the output and why?
– Kartik
Nov 20 at 5:49
what should be the logic to find the "best match"? in your example input, what should be the output and why?
– Kartik
Nov 20 at 5:49
• If a hospital and student favor each other the most, they should be matched unless no other match is possible. • If a hospital and student despise each other the most, they should not be matched unless no other match is possible. • If perfect matches are not possible, hospitals should be matched to the student that is the best fit. • The end goal is that for every match, it wasn’t possible to form a better match for all parties involved @Kartik
– rahul uday
Nov 20 at 6:06
• If a hospital and student favor each other the most, they should be matched unless no other match is possible. • If a hospital and student despise each other the most, they should not be matched unless no other match is possible. • If perfect matches are not possible, hospitals should be matched to the student that is the best fit. • The end goal is that for every match, it wasn’t possible to form a better match for all parties involved @Kartik
– rahul uday
Nov 20 at 6:06
1
1
See en.wikipedia.org/wiki/Stable_marriage_problem
– Jim Mischel
Nov 20 at 13:52
See en.wikipedia.org/wiki/Stable_marriage_problem
– Jim Mischel
Nov 20 at 13:52
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
This problem is a variant of stable marriage problem / stable matching problem , i.e, with unequal size and polygamy allowed :)
The algorithm works by a number of rounds. The hospital matches the student according to its preference. The student then reviews the proposals, tentatively holds on to the best proposal and rejects the rest. In the next round, the rejected hospitals propose to their next best choice, and the students again retain the best proposal and reject the rest. This process continues until there are no more students left to propose.
The principle used is deferred acceptance
http://www.nrmp.org/matching-algorithm/
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386466%2fcompare-two-data-structure-and-suggest-the-best-match%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
This problem is a variant of stable marriage problem / stable matching problem , i.e, with unequal size and polygamy allowed :)
The algorithm works by a number of rounds. The hospital matches the student according to its preference. The student then reviews the proposals, tentatively holds on to the best proposal and rejects the rest. In the next round, the rejected hospitals propose to their next best choice, and the students again retain the best proposal and reject the rest. This process continues until there are no more students left to propose.
The principle used is deferred acceptance
http://www.nrmp.org/matching-algorithm/
add a comment |
up vote
1
down vote
accepted
This problem is a variant of stable marriage problem / stable matching problem , i.e, with unequal size and polygamy allowed :)
The algorithm works by a number of rounds. The hospital matches the student according to its preference. The student then reviews the proposals, tentatively holds on to the best proposal and rejects the rest. In the next round, the rejected hospitals propose to their next best choice, and the students again retain the best proposal and reject the rest. This process continues until there are no more students left to propose.
The principle used is deferred acceptance
http://www.nrmp.org/matching-algorithm/
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
This problem is a variant of stable marriage problem / stable matching problem , i.e, with unequal size and polygamy allowed :)
The algorithm works by a number of rounds. The hospital matches the student according to its preference. The student then reviews the proposals, tentatively holds on to the best proposal and rejects the rest. In the next round, the rejected hospitals propose to their next best choice, and the students again retain the best proposal and reject the rest. This process continues until there are no more students left to propose.
The principle used is deferred acceptance
http://www.nrmp.org/matching-algorithm/
This problem is a variant of stable marriage problem / stable matching problem , i.e, with unequal size and polygamy allowed :)
The algorithm works by a number of rounds. The hospital matches the student according to its preference. The student then reviews the proposals, tentatively holds on to the best proposal and rejects the rest. In the next round, the rejected hospitals propose to their next best choice, and the students again retain the best proposal and reject the rest. This process continues until there are no more students left to propose.
The principle used is deferred acceptance
http://www.nrmp.org/matching-algorithm/
answered Nov 21 at 9:15
Sharin Nair
412
412
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386466%2fcompare-two-data-structure-and-suggest-the-best-match%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Please post what (code) you've tried so far. At least put the code for creation of these Maps and your attempt to iterate over them.
– Kartik
Nov 20 at 4:58
1
what should be the logic to find the "best match"? in your example input, what should be the output and why?
– Kartik
Nov 20 at 5:49
• If a hospital and student favor each other the most, they should be matched unless no other match is possible. • If a hospital and student despise each other the most, they should not be matched unless no other match is possible. • If perfect matches are not possible, hospitals should be matched to the student that is the best fit. • The end goal is that for every match, it wasn’t possible to form a better match for all parties involved @Kartik
– rahul uday
Nov 20 at 6:06
1
See en.wikipedia.org/wiki/Stable_marriage_problem
– Jim Mischel
Nov 20 at 13:52