Проблемы при чтении настроек из входного файла в Java для проблемы стабильного сопоставленияJAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Проблемы при чтении настроек из входного файла в Java для проблемы стабильного сопоставления

Сообщение Anonymous »


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
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «JAVA»