stable marriage - My method isn't putting names into my array and removing them properly -
stable marriage - My method isn't putting names into my array and removing them properly -
i've been working on "stable marriage problem" class i'm in , cannot implement gale-shapely algorithm correctly. out set when prompted:
for (int q = 0; q < nummen; q++ ) system.out.println(couples[q].tostring());
is "brian patricia george nancy john susan robert nancy stephen joyce" on different lines. how ever proper combination "brian patricia george joyce john susan robert nancy stephen anne. issue won't remove "nancy" george's pair. background men[][] matrix of men's preferences in format men[i][0] name of each man 0 < < 4 , men[i][k] k preferences in positions 1 < k < 5. same thing women matrix. couples[] array of object "couple" , array holds each matched pair of man , woman. here's place problem is:
public static void solvemenmarriages() { int i, k; string m, w, fiance; = 0; fiance = null; while (i < nummen) { k = 1; m = men[i][0]; w = men[i][k]; if (isproposedto(w)) fiance = findfiance(w); if (!isproposedto(w)) { couples[i] = new couple(m, w); i++; } else if (checkpreferencewoman(fiance, m, w).equals(m)){ couples[i] = new couple(m, w); removefiance(fiance); = fianceindex(fiance); } else { k++; } if (i == (nummen - 1)) { for(int v = 0; v < nummen; v++) { if (couples[v].woman == null) = 0; else break; } } } } public static string checkpreferencewoman(string m1, string m2, string w) { int c; c = 0; while (c < numwomen) { if (women[c][0].equals(w)) { (int d = 1; d < (nummen + 1); d++) { if (women[c][d].equals(m2)) { homecoming m2; } } } c++; } homecoming m1; } }
arrays stable-marriage
Comments
Post a Comment