【问题标题】:Compare two data Structure and Suggest the best match比较两个数据结构并建议最佳匹配
【发布时间】:2018-11-20 04:55:42
【问题描述】:

大家好,我有两个结构Map<String,Map<String,String>>。第一个地图结构是医院偏好示例<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;
}

谢谢

【问题讨论】:

  • 请发布您迄今为止尝试过的(代码)。至少把创建这些地图的代码和你尝试迭代它们的代码放在一起。
  • 找到“最佳匹配”的逻辑应该是什么?在您的示例输入中,输出应该是什么?为什么?
  • • 如果医院和学生最喜欢对方,他们应该匹配,除非不可能有其他匹配。 • 如果医院和学生最鄙视对方,除非没有其他匹配,否则不应匹配。 • 如果不可能完美匹配,医院应匹配最合适的学生。 • 最终目标是,对于每场比赛,不可能为所有相关方形成更好的比赛@Kartik

标签: java algorithm data-structures compare maps


【解决方案1】:

这个问题是stable marriage problem / stable matching problem 的变体,即,大小不等且允许一夫多妻制:)

该算法通过多个轮运行。医院根据学生的喜好匹配学生。然后学生审查提案,暂时保留最好的提案并拒绝其余的提案。在下一轮,被拒绝的医院提出下一个最佳选择,学生再次保留最佳建议,其余的拒绝。这个过程一直持续到没有更多的学生可以求婚为止。

使用的原则是延迟接受

http://www.nrmp.org/matching-algorithm/

【讨论】:

    猜你喜欢
    • 2018-11-16
    • 1970-01-01
    • 2019-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-19
    • 2017-06-21
    • 1970-01-01
    相关资源
    最近更新 更多