Проблемы при чтении настроек из входного файла в Java для проблемы стабильного сопоставления ⇐ JAVA
Проблемы при чтении настроек из входного файла в Java для проблемы стабильного сопоставления
I'm working on a stable matching problem implementation in Java, where the input is provided via a text file. The problem involves matching a set of men to a set of women based on their preferences.
Here's an example of the desired input format:
2
1 2
2 1
2 1
1 2
And the desired output:
Output when men propose: {(1,1), (2,2)} Output when women propose: {(1,2), (2,1)} I've implemented the Gale-Shapley algorithm for both men proposing and women proposing, but I'm encountering some issues with the output.
For the input above, my output is as follows:
Output when men propose: {(1,), (2,)} Output when women propose: {(1,2), (2,1)} It seems that the output for men proposing is not correct. Similarly, when I use another testcase (input2.txt) with the following input:
3 1 2 3 2 1 3 1 2 3 2 1 3 1 2 3 1 2 3 The expected output is:
Output when men propose: {(1,1), (2,2) , (3,3)} Output when women propose: {(1,2),(2,1), (3,3)} But I'm getting the same output as if I never changed from the input files.
Here's the relevant part of my code:
try (BufferedReader br = new BufferedReader(new FileReader(fileName))) { String line; int lineCount = 0; while ((line = br.readLine()) != null) { line = line.trim(); if (line.isEmpty()) { continue; } if (lineCount == 0) { numPpl = Integer.parseInt(line); } else { String[] parts = line.split(" "); String person; Integer[] preferences; if (lineCount
Источник: https://stackoverflow.com/questions/780 ... ching-prob
I'm working on a stable matching problem implementation in Java, where the input is provided via a text file. The problem involves matching a set of men to a set of women based on their preferences.
Here's an example of the desired input format:
2
1 2
2 1
2 1
1 2
And the desired output:
Output when men propose: {(1,1), (2,2)} Output when women propose: {(1,2), (2,1)} I've implemented the Gale-Shapley algorithm for both men proposing and women proposing, but I'm encountering some issues with the output.
For the input above, my output is as follows:
Output when men propose: {(1,), (2,)} Output when women propose: {(1,2), (2,1)} It seems that the output for men proposing is not correct. Similarly, when I use another testcase (input2.txt) with the following input:
3 1 2 3 2 1 3 1 2 3 2 1 3 1 2 3 1 2 3 The expected output is:
Output when men propose: {(1,1), (2,2) , (3,3)} Output when women propose: {(1,2),(2,1), (3,3)} But I'm getting the same output as if I never changed from the input files.
Here's the relevant part of my code:
try (BufferedReader br = new BufferedReader(new FileReader(fileName))) { String line; int lineCount = 0; while ((line = br.readLine()) != null) { line = line.trim(); if (line.isEmpty()) { continue; } if (lineCount == 0) { numPpl = Integer.parseInt(line); } else { String[] parts = line.split(" "); String person; Integer[] preferences; if (lineCount
Источник: https://stackoverflow.com/questions/780 ... ching-prob
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Постоянный FDR: идентификатор сохраняется при сбросе настроек до заводских настроек.
Anonymous » » в форуме Android - 0 Ответы
- 82 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Проблема с синхронизацией Gradle Kotlin после стабильного обновления Android 3.1
Anonymous » » в форуме Android - 0 Ответы
- 13 Просмотры
-
Последнее сообщение Anonymous
-