简体   繁体   中英

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>> . 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


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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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