[英]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.