简体   繁体   English

比较两个数据结构并提出最佳匹配

[英]Compare two data Structure and Suggest the best match

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>> . 大家好,我有两个结构,分别是Map<String,Map<String,String>> 。第一个Map结构是医院偏好示例<Hospital name,<Student,Preferences>> The second map is a student preferences example <Student,<Hospital,Preferences>> . 第二张地图是学生偏好示例<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 谢谢


This problem is a variant of stable marriage problem / stable matching problem , ie, 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/ http://www.nrmp.org/matching-algorithm/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM