[英]Compare two data Structure and Suggest the best match
大家好,我有兩個結構,分別是Map<String,Map<String,String>>
。第一個Map結構是醫院偏好示例<Hospital name,<Student,Preferences>>
。 第二張地圖是學生偏好示例<Student,<Hospital,Preferences>>
。 如何比較兩者並根據給定的首選項查找最佳匹配。
在第一張地圖下面找到數據
{St. Luke's={ Martin Fowler= 2, Alan Turing= 1}, Olathe Medical Center={ Martin Fowler= 2, Alan Turing= 1}}
第二張地圖
{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}}
用於創建此結構的代碼是
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;
}
謝謝
此問題是穩定婚姻問題/穩定匹配問題的變體,即,允許不平等的規模和一夫多妻制:)
該算法經過多次回合 。 醫院會根據其偏好匹配學生。 然后,學生檢查提案,暫時保留最佳提案,然后拒絕其余提案。 在下一輪中,被拒絕的醫院提出他們的下一個最佳選擇,而學生再次保留最佳選擇,其余的則拒絕。 這個過程一直持續到沒有其他學生可以提出建議為止。
使用的原則是推遲驗收
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.